-
Notifications
You must be signed in to change notification settings - Fork 19
/
index.html
234 lines (213 loc) · 13.7 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fast Estimators for Design-Based Inference • estimatr</title>
<!-- jquery --><script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha384-nrOSfDHtoPMzJHjVTdCopGqIqeYETSXhZDFyniQ8ZHcVy08QesyHcnOUpMpqnmWq" crossorigin="anonymous"></script><!-- Bootstrap --><link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script><!-- Font Awesome icons --><link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-T8Gy5hrqNKT+hzMclPo118YTQO6cYprQmhrYwIiQ/3axmI1hQomh7Ud2hPOy8SP1" crossorigin="anonymous">
<!-- pkgdown --><link href="pkgdown.css" rel="stylesheet">
<script src="jquery.sticky-kit.min.js"></script><script src="pkgdown.js"></script><!-- mathjax --><script src="https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container template-vignette">
<header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="">estimatr</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="articles/getting-started.html">Getting Started</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Technical Notes
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="articles/mathematical-notes.html">Mathematical Notes</a>
</li>
<li>
<a href="articles/benchmarking-estimatr.html">Simulations - Speed Comparisons</a>
</li>
<li>
<a href="articles/simulations-ols-variance.html">Simulations - OLS and Variance</a>
</li>
<li>
<a href="articles/simulations-debiasing-dim.html">Simulations - Debiasing Difference-in-Means</a>
</li>
<li>
<a href="articles/stata-wls-hat.html">How Stata's hat matrix differs with weights</a>
</li>
</ul>
</li>
<li>
<a href="reference/index.html">Reference</a>
</li>
<li>
<a href="http://discuss.declaredesign.org">Ask for Help</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
Packages
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="http://declaredesign.org">DeclareDesign</a>
</li>
<li>
<a href="http://randomizr.declaredesign.org">randomizr</a>
</li>
<li>
<a href="http://fabricatr.declaredesign.org">fabricatr</a>
</li>
<li>
<a href="http://estimatr.declaredesign.org">estimatr</a>
</li>
</ul>
</li>
<li>
<a href="http://declaredesign.org">DeclareDesign home</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a></a>
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
<!--/.container -->
</div>
<!--/.navbar -->
</header><div class="row">
<div class="col-md-9">
<div class="contents">
<!-- README.md is generated from README.Rmd. Please edit that file -->
<div id="estimatr-fast-estimators-for-design-based-inference" class="section level1">
<div class="page-header"><h1 class="hasAnchor">
<a href="#estimatr-fast-estimators-for-design-based-inference" class="anchor"></a>estimatr: Fast Estimators for Design-Based Inference</h1></div>
<p>Technical papers and textbooks demand complex estimation strategies that are often difficult to implement, even for scientists who are expert coders. The result is slow code copied and pasted from the internet, where the result is taken on faith.</p>
<p><strong>estimatr</strong> provides a small set of commonly-used estimators (methods for estimating quantities of interest like treatment effects or regression parameters), using <code>C++</code> for speed, and implemented in <code>R</code> with simple, accessible syntax. We include two functions that implement means estimators, <code><a href="reference/difference_in_means.html">difference_in_means()</a></code> and <code><a href="reference/horvitz_thompson.html">horvitz_thompson()</a></code>. In addition, we include three functions for linear regression estimators, <code><a href="reference/lm_robust.html">lm_robust()</a></code>, <code><a href="reference/lm_lin.html">lm_lin()</a></code>, and <code><a href="reference/iv_robust.html">iv_robust()</a></code>. In each case, scientists can choose an estimator to reflect cluster-randomized, block-randomized, and block-and-cluster-randomized designs. The <a href="articles/getting-started.html">Getting Started Guide</a> describes each estimator provided by <strong>estimatr</strong> and how it can be used in your analysis.</p>
<p>Fast estimators also enable fast simulation of research designs to learn about their properties (see <a href="declaredesign.org">DeclareDesign</a>).</p>
<div id="installing-estimatr" class="section level2">
<h2 class="hasAnchor">
<a href="#installing-estimatr" class="anchor"></a>Installing estimatr</h2>
<p>To install the latest stable release of <strong>estimatr</strong>, please ensure that you are running version 3.3 or later of R and run the following code:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">install.packages</span>(<span class="st">"estimatr"</span>)</code></pre></div>
<p>If you would like to use the latest development release of <strong>estimatr</strong>, please ensure that you are running version 3.3 or later of R and run the following code:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">install.packages</span>(<span class="st">"estimatr"</span>, <span class="dt">dependencies =</span> <span class="ot">TRUE</span>,
<span class="dt">repos =</span> <span class="kw">c</span>(<span class="st">"http://r.declaredesign.org"</span>, <span class="st">"https://cloud.r-project.org"</span>))</code></pre></div>
</div>
<div id="easy-to-use" class="section level2">
<h2 class="hasAnchor">
<a href="#easy-to-use" class="anchor"></a>Easy to use</h2>
<p>Once the package is installed, getting appropriate estimates and standard errors is now both fast and easy.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(estimatr)
<span class="co"># sample data from cluster-randomized experiment</span>
<span class="kw">library</span>(fabricatr)
<span class="co">#> Warning: package 'fabricatr' was built under R version 3.4.4</span>
<span class="kw">library</span>(randomizr)
<span class="co">#> Warning: package 'randomizr' was built under R version 3.4.4</span>
dat <-<span class="st"> </span><span class="kw"><a href="http://www.rdocumentation.org/packages/fabricatr/topics/fabricate">fabricate</a></span>(
<span class="dt">N =</span> <span class="dv">100</span>,
<span class="dt">y =</span> <span class="kw">rnorm</span>(N),
<span class="dt">clusterID =</span> <span class="kw">sample</span>(letters[<span class="dv">1</span><span class="op">:</span><span class="dv">10</span>], <span class="dt">size =</span> N, <span class="dt">replace =</span> <span class="ot">TRUE</span>),
<span class="dt">z =</span> <span class="kw"><a href="http://www.rdocumentation.org/packages/randomizr/topics/cluster_ra">cluster_ra</a></span>(clusterID)
)
<span class="co"># robust standard errors</span>
res_rob <-<span class="st"> </span><span class="kw"><a href="reference/lm_robust.html">lm_robust</a></span>(y <span class="op">~</span><span class="st"> </span>z, <span class="dt">data =</span> dat)
<span class="co"># cluster robust standard errors</span>
res_cl <-<span class="st"> </span><span class="kw"><a href="reference/lm_robust.html">lm_robust</a></span>(y <span class="op">~</span><span class="st"> </span>z, <span class="dt">data =</span> dat, <span class="dt">clusters =</span> clusterID)
<span class="kw">summary</span>(res_cl)
<span class="co">#> </span>
<span class="co">#> Call:</span>
<span class="co">#> lm_robust(formula = y ~ z, data = dat, clusters = clusterID)</span>
<span class="co">#> </span>
<span class="co">#> Standard error type: CR2 </span>
<span class="co">#> </span>
<span class="co">#> Coefficients:</span>
<span class="co">#> Estimate Std. Error Pr(>|t|) CI Lower CI Upper DF</span>
<span class="co">#> (Intercept) 0.269 0.164 0.20 -0.255 0.793 2.99</span>
<span class="co">#> z -0.422 0.250 0.14 -1.027 0.182 6.30</span>
<span class="co">#> </span>
<span class="co">#> Multiple R-squared: 0.041 , Adjusted R-squared: 0.0312 </span>
<span class="co">#> F-statistic: 4.18 on 1 and 98 DF, p-value: 0.0435</span>
<span class="co"># matched-pair design learned from blocks argument</span>
<span class="kw">data</span>(sleep)
res_dim <-<span class="st"> </span><span class="kw"><a href="reference/difference_in_means.html">difference_in_means</a></span>(extra <span class="op">~</span><span class="st"> </span>group, <span class="dt">data =</span> sleep, <span class="dt">blocks =</span> ID)</code></pre></div>
<p>The <a href="articles/getting-started.html">Getting Started Guide</a> has more examples and uses, as do the reference pages. The <a href="articles/mathematical-notes.html">Mathematical Notes</a> provide more information about what each estimator is doing under the hood.</p>
</div>
<div id="fast-to-use" class="section level2">
<h2 class="hasAnchor">
<a href="#fast-to-use" class="anchor"></a>Fast to use</h2>
<p>Getting estimates and robust standard errors is also faster than it used to be. Compare our package to using <code>lm()</code> and the <code>sandwich</code> package to get HC2 standard errors. More speed comparisons are available <a href="articles/benchmarking-estimatr.html">here</a>.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># example code</span>
<span class="co"># estimatr</span>
<span class="kw"><a href="reference/lm_robust.html">lm_robust</a></span>(y <span class="op">~</span><span class="st"> </span>x1 <span class="op">+</span><span class="st"> </span>x2 <span class="op">+</span><span class="st"> </span>x3 <span class="op">+</span><span class="st"> </span>x4, <span class="dt">data =</span> dat)
<span class="co"># usual specification (lm + sandwich)</span>
<span class="kw">library</span>(lmtest)
<span class="kw">library</span>(sandwich)
lm_out <-<span class="st"> </span><span class="kw">lm</span>(y <span class="op">~</span><span class="st"> </span>x1 <span class="op">+</span><span class="st"> </span>x2 <span class="op">+</span><span class="st"> </span>x3 <span class="op">+</span><span class="st"> </span>x4, <span class="dt">data =</span> dat)
<span class="kw"><a href="http://www.rdocumentation.org/packages/lmtest/topics/coeftest">coeftest</a></span>(lm_out, <span class="dt">vcov =</span> <span class="kw"><a href="http://www.rdocumentation.org/packages/sandwich/topics/vcovHC">vcovHC</a></span>(lm_out, <span class="dt">type =</span> <span class="st">'HC2'</span>))</code></pre></div>
<div class="figure">
<img src="articles/lm_speed.png">
</div>
<div class="figure">
<img src="articles/lm_speed_covars.png">
</div>
<hr>
<p>This project is generously supported by a grant from the <a href="arnoldfoundation.org">Laura and John Arnold Foundation</a> and seed funding from <a href="egap.org">Evidence in Governance and Politics (EGAP)</a>.</p>
</div>
</div>
</div>
</div>
<div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
<div id="sidebar_links">
<h2 class="hasAnchor">
<a href="#sidebar_links" class="anchor"></a>Links</h2>
<ul class="list-unstyled">
<li><a href="https://github.com/DeclareDesign/estimatr">Help develop estimatr</a></li>
<li><a href="https://github.com/DeclareDesign/estimatr/issues">Report a bug</a></li>
</ul>
</div>
<div id="sidebar_authors">
<h2 class="hasAnchor">
<a href="#sidebar_authors" class="anchor"></a>Developers</h2>
<ul class="list-unstyled">
<li>Graeme Blair <br><small class="roles"> Author, maintainer </small> </li>
<li>Jasper Cooper <br><small class="roles"> Author </small> </li>
<li>Alexander Coppock <br><small class="roles"> Author </small> </li>
<li>Macartan Humphreys <br><small class="roles"> Author </small> </li>
<li>Luke Sonnet <br><small class="roles"> Author </small> </li>
<li>Neal Fultz <br><small class="roles"> Contributor </small> </li>
</ul>
</div>
</div>
</div>
<footer><div class="copyright" style="flex:3;">
<p>Developed by Graeme Blair, Jasper Cooper, Alexander Coppock, Macartan Humphreys, Luke Sonnet, Neal Fultz.</p>
<p>Code is licensed under <a href="https://opensource.org/licenses/mit-license.php">MIT</a> license.</p>
</div>
<div class="pkgdown">
<p>Site built with <a href="http://hadley.github.io/pkgdown/">pkgdown</a>.</p>
</div>
</footer>
</div>
</body>
</html>