Coder Social home page Coder Social logo

wildboottests.jl's Introduction

WildBootTests.jl

WildBootTests.jl performs wild bootstrap-based hypothesis tests at extreme speed. It is intended mainly for linear models: ordinary least squares (OLS) and instrumental variables/two-stage least squares (IV/2SLS). For an introduction to the wild bootstrap and the algorithms deployed here, see Roodman et al. (2019). It is a Julia program, but can be accessed from other environments as demonstrated below.

Documentation

Julia example

using WildBootTests, CSV, DataFrames, StatsModels, Plots
d = download("https://raw.github.com/vincentarelbundock/Rdatasets/master/csv/sandwich/PetersenCL.csv");
df = CSV.read(d, DataFrame);
f = @formula(y ~ 1 + x);                             # state OLS model
f = apply_schema(f, schema(f, df));                  # link model to data
resp, predexog = modelcols(f, df);                   # extract response & (exogenous) predictor variables
clustid = df.firm;                                   # extract clustering variable
R = [0 1]; r = [1];                                  # put null in Rβ = r form, where β is parameter vector

test = wildboottest(R, r; resp, predexog, clustid);  # run test
test                                                 # display results summary
plot(plotpoints(test)...)                            # plot confidence curve

R example, via fwildclusterboot

library(fwildclusterboot)
df <- read.csv("https://raw.github.com/vincentarelbundock/Rdatasets/master/csv/sandwich/PetersenCL.csv")
lm_fit <- lm(y ~ x, data = df)
boot_lm <- boottest(lm_fit, clustid = "firm", param = "x", r = 1, B = 999,  boot_algo = "WildBootTests.jl")
summary(boot_lm)
plot(boot_lm)

R example, via JuliaConnectoR

library(JuliaConnectoR)
startJuliaServer()
WildBootTests <- juliaImport("WildBootTests")
df <- read.csv(file = 'https://raw.github.com/vincentarelbundock/Rdatasets/master/csv/sandwich/PetersenCL.csv')
R <- matrix(c(0,1), nrow=1); r <- c(1)
test <- WildBootTests$wildboottest(R, r, resp=df$y, predexog=cbind(1, df$x), clustid=df$firm)
test
WildBootTests$teststat(test)
WildBootTests$p(test)
WildBootTests$ci(test)
plotpoints <- WildBootTests$plotpoints(test)
plot(plotpoints$X[[1]], plotpoints$p, type="l")

Python example, via PyJulia

from julia import WildBootTests as wbt
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

df = pd.read_csv(r'https://raw.github.com/vincentarelbundock/Rdatasets/master/csv/sandwich/PetersenCL.csv')
R = np.array([[0, 1]]); r = np.array([1])
resp = df.y.values
predexog = np.c_[np.ones(df.firm.size), df.x]
clustid = df.firm.values
test = wbt.wildboottest(R, r, resp=resp, predexog=predexog, clustid=clustid)
wbt.teststat(test)
wbt.p(test)
wbt.ci(test)
plotpoints = wbt.plotpoints(test)
plt.plot(plotpoints.X[0], plotpoints.p)

Stata example, via boottest

import delimited https://raw.github.com/vincentarelbundock/Rdatasets/master/csv/sandwich/PetersenCL.csv
regress y x, cluster(firm)
boottest x, reps(999) julia

Stata example, via Python and PyJulia

import delimited https://raw.github.com/vincentarelbundock/Rdatasets/master/csv/sandwich/PetersenCL.csv
python
from julia import WildBootTests as wbt
import numpy as np
from sfi import Data

R = np.array([[0, 1]]); r = np.array([1])
resp = np.asarray(Data.get('y'))
predexog = np.c_[np.ones(resp.size), np.asarray(Data.get('x'))]
clustid = np.asarray(Data.get('firm'))
test = wbt.wildboottest(R, r, resp=resp, predexog=predexog, clustid=clustid)
wbt.p(test)
wbt.teststat(test)
wbt.ci(test)
end

wildboottests.jl's People

Contributors

droodman avatar s3alfisc avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.