diff --git a/DESCRIPTION b/DESCRIPTION index 69743e84..209278b8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: estimatr Type: Package Title: Fast Estimators for Design-Based Inference -Version: 0.20.0 +Version: 0.22.0 Authors@R: c(person("Graeme", "Blair", email = "graeme.blair@ucla.edu", role = c("aut", "cre")), person("Jasper", "Cooper", email = "jjc2247@columbia.edu", role = c("aut")), person("Alexander", "Coppock", email = "alex.coppock@yale.edu", role = c("aut")), @@ -23,7 +23,7 @@ Imports: rlang (>= 0.2.0) LinkingTo: Rcpp, RcppEigen Encoding: UTF-8 -RoxygenNote: 6.1.1 +RoxygenNote: 7.1.0 LazyData: true Suggests: fabricatr (>= 0.10.0), diff --git a/NEWS.md b/NEWS.md index 098cfe2d..256bfc07 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,8 @@ -# estimatr 0.20.0 (CRAN) +# estimatr 0.22.0 + +* Bug fixes + +# estimatr 0.20.0 * Added support for `emmeans` (thanks @rvlenth)! * Fixed bug when estimating `diagnostics` in `iv_robust()` without explicitly specifying `se_type` (issue #310) diff --git a/R/estimatr.R b/R/estimatr.R index 78714d40..8312b55e 100644 --- a/R/estimatr.R +++ b/R/estimatr.R @@ -1,5 +1,7 @@ #' estimatr #' +#' @description Fast procedures for small set of commonly-used, design-appropriate estimators with robust standard errors and confidence intervals. Includes estimators for linear regression, instrumental variables regression, difference-in-means, Horvitz-Thompson estimation, and regression improving precision of experimental estimates by interacting treatment with centered pre-treatment covariates introduced by Lin (2013) . +#' #' @docType package #' @useDynLib estimatr, .registration = TRUE #' @importFrom Rcpp evalCpp diff --git a/R/helper_na_omit_detailed.R b/R/helper_na_omit_detailed.R index b85dcb8a..8eda29bd 100644 --- a/R/helper_na_omit_detailed.R +++ b/R/helper_na_omit_detailed.R @@ -1,7 +1,6 @@ #' Extra logging on na.omit handler #' #' @param object a data.frame -#' @param ... unused #' #' @return a normal \code{omit} object, with the extra attribute \code{why_omit}, #' which contains the leftmost column containing an NA for each row that was dropped, by diff --git a/cran-comments.md b/cran-comments.md index 315502ea..ff36ee74 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,8 +1,6 @@ ## Submission -We are resubmitting a small update, `estimatr 0.20.0`, with bug fixes and the addition of a small new feature. - -We have now fixed issues related to Solaris builds, MKL, and OpenBLAS. Apologies for the back and forth. +This small patch addresses errors on CRAN related to changes in stringsAsFactor and we think resolves all issues. Thank you for your time reviewing the submission. @@ -11,6 +9,7 @@ Thank you for your time reviewing the submission. * ubuntu on travis-ci (devel, release, oldrel) * OS X on travis-ci (release, oldrel) * win-builder (devel, release, oldrel) +* rhub (including Solaris) ## R CMD check results diff --git a/man/alo_star_men.Rd b/man/alo_star_men.Rd index 1417ab1c..57773dca 100644 --- a/man/alo_star_men.Rd +++ b/man/alo_star_men.Rd @@ -4,14 +4,16 @@ \name{alo_star_men} \alias{alo_star_men} \title{Replication data for Lin 2013} -\format{A data frame with educational treatments and outcomes: +\format{ +A data frame with educational treatments and outcomes: \describe{ \item{gpa0}{high school GPA} \item{sfsp}{financial incentives and support treatment} \item{ssp}{support only treatment} \item{GPA_year1}{college GPA year 1} \item{GPA_year2}{college GPA year 2} -}} +} +} \source{ \url{https://www.aeaweb.org/articles?id=10.1257/app.1.1.136} } diff --git a/man/commarobust.Rd b/man/commarobust.Rd index 713c3050..f4831f3b 100644 --- a/man/commarobust.Rd +++ b/man/commarobust.Rd @@ -4,8 +4,7 @@ \alias{commarobust} \title{Build lm_robust object from lm fit} \usage{ -commarobust(model, se_type = NULL, clusters = NULL, ci = TRUE, - alpha = 0.05) +commarobust(model, se_type = NULL, clusters = NULL, ci = TRUE, alpha = 0.05) } \arguments{ \item{model}{an lm model object} diff --git a/man/declaration_to_condition_pr_mat.Rd b/man/declaration_to_condition_pr_mat.Rd index c2171411..eb234ce5 100644 --- a/man/declaration_to_condition_pr_mat.Rd +++ b/man/declaration_to_condition_pr_mat.Rd @@ -5,8 +5,12 @@ \title{Builds condition probability matrices for Horvitz-Thompson estimation from \pkg{randomizr} declaration} \usage{ -declaration_to_condition_pr_mat(ra_declaration, condition1 = NULL, - condition2 = NULL, prob_matrix = NULL) +declaration_to_condition_pr_mat( + ra_declaration, + condition1 = NULL, + condition2 = NULL, + prob_matrix = NULL +) } \arguments{ \item{ra_declaration}{An object of class \code{"ra_declaration"}, generated diff --git a/man/difference_in_means.Rd b/man/difference_in_means.Rd index ee00e279..a45f1eb5 100644 --- a/man/difference_in_means.Rd +++ b/man/difference_in_means.Rd @@ -4,9 +4,19 @@ \alias{difference_in_means} \title{Design-based difference-in-means estimator} \usage{ -difference_in_means(formula, data, blocks, clusters, weights, subset, - se_type = c("default", "none"), condition1 = NULL, - condition2 = NULL, ci = TRUE, alpha = 0.05) +difference_in_means( + formula, + data, + blocks, + clusters, + weights, + subset, + se_type = c("default", "none"), + condition1 = NULL, + condition2 = NULL, + ci = TRUE, + alpha = 0.05 +) } \arguments{ \item{formula}{an object of class formula, as in \code{\link{lm}}, such as diff --git a/man/estimatr.Rd b/man/estimatr.Rd index 9a80eab0..23516402 100644 --- a/man/estimatr.Rd +++ b/man/estimatr.Rd @@ -3,8 +3,7 @@ \docType{package} \name{estimatr} \alias{estimatr} -\alias{estimatr-package} \title{estimatr} \description{ -estimatr +Fast procedures for small set of commonly-used, design-appropriate estimators with robust standard errors and confidence intervals. Includes estimators for linear regression, instrumental variables regression, difference-in-means, Horvitz-Thompson estimation, and regression improving precision of experimental estimates by interacting treatment with centered pre-treatment covariates introduced by Lin (2013) . } diff --git a/man/extract.lm_robust.Rd b/man/extract.lm_robust.Rd index 7ae788a5..6c2775eb 100644 --- a/man/extract.lm_robust.Rd +++ b/man/extract.lm_robust.Rd @@ -6,17 +6,41 @@ \alias{extract.iv_robust} \title{Extract model data for \pkg{texreg} package} \usage{ -extract.robust_default(model, include.ci = TRUE, - include.rsquared = TRUE, include.adjrs = TRUE, include.nobs = TRUE, - include.fstatistic = FALSE, include.rmse = TRUE, ...) +extract.robust_default( + model, + include.ci = TRUE, + include.rsquared = TRUE, + include.adjrs = TRUE, + include.nobs = TRUE, + include.fstatistic = FALSE, + include.rmse = TRUE, + include.nclusts = TRUE, + ... +) -extract.lm_robust(model, include.ci = TRUE, include.rsquared = TRUE, - include.adjrs = TRUE, include.nobs = TRUE, - include.fstatistic = FALSE, include.rmse = TRUE, ...) +extract.lm_robust( + model, + include.ci = TRUE, + include.rsquared = TRUE, + include.adjrs = TRUE, + include.nobs = TRUE, + include.fstatistic = FALSE, + include.rmse = TRUE, + include.nclusts = TRUE, + ... +) -extract.iv_robust(model, include.ci = TRUE, include.rsquared = TRUE, - include.adjrs = TRUE, include.nobs = TRUE, - include.fstatistic = FALSE, include.rmse = TRUE, ...) +extract.iv_robust( + model, + include.ci = TRUE, + include.rsquared = TRUE, + include.adjrs = TRUE, + include.nobs = TRUE, + include.fstatistic = FALSE, + include.rmse = TRUE, + include.nclusts = TRUE, + ... +) } \arguments{ \item{model}{an object of class \code{\link{lm_robust}} or \code{"iv_robust"}} @@ -33,6 +57,8 @@ extract.iv_robust(model, include.ci = TRUE, include.rsquared = TRUE, \item{include.rmse}{logical. Defaults to TRUE} +\item{include.nclusts}{logical. Defaults to TRUE if clusters in \code{model}} + \item{...}{unused} } \description{ diff --git a/man/horvitz_thompson.Rd b/man/horvitz_thompson.Rd index b7324fba..84746e4c 100644 --- a/man/horvitz_thompson.Rd +++ b/man/horvitz_thompson.Rd @@ -4,11 +4,23 @@ \alias{horvitz_thompson} \title{Horvitz-Thompson estimator for two-armed trials} \usage{ -horvitz_thompson(formula, data, blocks, clusters, simple = NULL, - condition_prs, condition_pr_mat = NULL, ra_declaration = NULL, - subset, condition1 = NULL, condition2 = NULL, se_type = c("youngs", - "constant", "none"), ci = TRUE, alpha = 0.05, - return_condition_pr_mat = FALSE) +horvitz_thompson( + formula, + data, + blocks, + clusters, + simple = NULL, + condition_prs, + condition_pr_mat = NULL, + ra_declaration = NULL, + subset, + condition1 = NULL, + condition2 = NULL, + se_type = c("youngs", "constant", "none"), + ci = TRUE, + alpha = 0.05, + return_condition_pr_mat = FALSE +) } \arguments{ \item{formula}{an object of class formula, as in \code{\link{lm}}, such as diff --git a/man/iv_robust.Rd b/man/iv_robust.Rd index be559de6..22802c95 100644 --- a/man/iv_robust.Rd +++ b/man/iv_robust.Rd @@ -4,9 +4,20 @@ \alias{iv_robust} \title{Two-Stage Least Squares Instrumental Variables Regression} \usage{ -iv_robust(formula, data, weights, subset, clusters, fixed_effects, - se_type = NULL, ci = TRUE, alpha = 0.05, diagnostics = FALSE, - return_vcov = TRUE, try_cholesky = FALSE) +iv_robust( + formula, + data, + weights, + subset, + clusters, + fixed_effects, + se_type = NULL, + ci = TRUE, + alpha = 0.05, + diagnostics = FALSE, + return_vcov = TRUE, + try_cholesky = FALSE +) } \arguments{ \item{formula}{an object of class formula of the regression and the instruments. diff --git a/man/lh_robust.Rd b/man/lh_robust.Rd index 76006120..baa561a6 100644 --- a/man/lh_robust.Rd +++ b/man/lh_robust.Rd @@ -49,11 +49,10 @@ lhro <- lh_robust(y ~ x + z, data = dat, linear_hypothesis = "z + 2x = 0") # The linear hypothesis argument can be specified equivalently as: lh_robust(y ~ x + z, data = dat, linear_hypothesis = "z = 2x") -lh_robust(y ~ x + z, data = dat, linear_hypothesis = c("z = 1", "x = 2")) lh_robust(y ~ x + z, data = dat, linear_hypothesis = "2*x +1*z") lh_robust(y ~ x + z, data = dat, linear_hypothesis = "z + 2x = 0") -# Also recovers other sorts of standard erorrs just as specified in \\code{\\link{lm_robust}} +# Also recovers other sorts of standard erorrs just as specified in \code{\link{lm_robust}} lh_robust(y ~ x + z, data = dat, linear_hypothesis = "z + 2x = 0", se_type = "classical") lh_robust(y ~ x + z, data = dat, linear_hypothesis = "z + 2x = 0", se_type = "HC1") diff --git a/man/lm_lin.Rd b/man/lm_lin.Rd index 575e931a..fdc46b8e 100644 --- a/man/lm_lin.Rd +++ b/man/lm_lin.Rd @@ -4,9 +4,19 @@ \alias{lm_lin} \title{Linear regression with the Lin (2013) covariate adjustment} \usage{ -lm_lin(formula, covariates, data, weights, subset, clusters, - se_type = NULL, ci = TRUE, alpha = 0.05, return_vcov = TRUE, - try_cholesky = FALSE) +lm_lin( + formula, + covariates, + data, + weights, + subset, + clusters, + se_type = NULL, + ci = TRUE, + alpha = 0.05, + return_vcov = TRUE, + try_cholesky = FALSE +) } \arguments{ \item{formula}{an object of class formula, as in \code{\link{lm}}, such as diff --git a/man/lm_robust.Rd b/man/lm_robust.Rd index c23b8988..b7555fc7 100644 --- a/man/lm_robust.Rd +++ b/man/lm_robust.Rd @@ -4,9 +4,19 @@ \alias{lm_robust} \title{Ordinary Least Squares with Robust Standard Errors} \usage{ -lm_robust(formula, data, weights, subset, clusters, fixed_effects, - se_type = NULL, ci = TRUE, alpha = 0.05, return_vcov = TRUE, - try_cholesky = FALSE) +lm_robust( + formula, + data, + weights, + subset, + clusters, + fixed_effects, + se_type = NULL, + ci = TRUE, + alpha = 0.05, + return_vcov = TRUE, + try_cholesky = FALSE +) } \arguments{ \item{formula}{an object of class formula, as in \code{\link{lm}}} diff --git a/man/lm_robust_fit.Rd b/man/lm_robust_fit.Rd index 2a018e20..2c88fd6f 100644 --- a/man/lm_robust_fit.Rd +++ b/man/lm_robust_fit.Rd @@ -4,10 +4,23 @@ \alias{lm_robust_fit} \title{Internal method that creates linear fits} \usage{ -lm_robust_fit(y, X, yoriginal = NULL, Xoriginal = NULL, weights, - cluster, fixed_effects = NULL, ci = TRUE, se_type, has_int, - alpha = 0.05, return_vcov = TRUE, return_fit = TRUE, - try_cholesky = FALSE, iv_stage = list(0)) +lm_robust_fit( + y, + X, + yoriginal = NULL, + Xoriginal = NULL, + weights, + cluster, + fixed_effects = NULL, + ci = TRUE, + se_type, + has_int, + alpha = 0.05, + return_vcov = TRUE, + return_fit = TRUE, + try_cholesky = FALSE, + iv_stage = list(0) +) } \arguments{ \item{y}{numeric outcome vector} diff --git a/man/na.omit_detailed.data.frame.Rd b/man/na.omit_detailed.data.frame.Rd index 4883389c..b2bf48ec 100644 --- a/man/na.omit_detailed.data.frame.Rd +++ b/man/na.omit_detailed.data.frame.Rd @@ -8,8 +8,6 @@ na.omit_detailed.data.frame(object) } \arguments{ \item{object}{a data.frame} - -\item{...}{unused} } \value{ a normal \code{omit} object, with the extra attribute \code{why_omit}, diff --git a/man/predict.lm_robust.Rd b/man/predict.lm_robust.Rd index 61a5fb4c..27792d4e 100644 --- a/man/predict.lm_robust.Rd +++ b/man/predict.lm_robust.Rd @@ -4,9 +4,17 @@ \alias{predict.lm_robust} \title{Predict method for \code{lm_robust} object} \usage{ -\method{predict}{lm_robust}(object, newdata, se.fit = FALSE, - interval = c("none", "confidence", "prediction"), alpha = 0.05, - na.action = na.pass, pred.var = NULL, weights, ...) +\method{predict}{lm_robust}( + object, + newdata, + se.fit = FALSE, + interval = c("none", "confidence", "prediction"), + alpha = 0.05, + na.action = na.pass, + pred.var = NULL, + weights, + ... +) } \arguments{ \item{object}{an object of class 'lm_robust'} diff --git a/man/starprep.Rd b/man/starprep.Rd index 56d32143..d442657d 100644 --- a/man/starprep.Rd +++ b/man/starprep.Rd @@ -4,8 +4,13 @@ \alias{starprep} \title{Prepare model fits for stargazer} \usage{ -starprep(..., stat = c("std.error", "statistic", "p.value", "ci", "df"), - se_type = NULL, clusters = NULL, alpha = 0.05) +starprep( + ..., + stat = c("std.error", "statistic", "p.value", "ci", "df"), + se_type = NULL, + clusters = NULL, + alpha = 0.05 +) } \arguments{ \item{...}{a list of lm_robust or lm objects} diff --git a/tests/testthat/test-lm-robust-fes.R b/tests/testthat/test-lm-robust-fes.R index 05036cd6..6b3eb7fc 100644 --- a/tests/testthat/test-lm-robust-fes.R +++ b/tests/testthat/test-lm-robust-fes.R @@ -518,6 +518,7 @@ test_that("FEs give correct projected F-stats", { }) test_that("FE matches lm_robust with one block", { + # In outcome datmiss <- dat datmiss$Y[5] <- NA @@ -675,6 +676,9 @@ test_that("FEs handle collinear covariates", { }) test_that("Handle perfect fits appropriately", { + + skip_on_os("solaris") + dat$Bsingle <- c(1, 2, rep(3:4, each = 9)) rfo <- lm_robust(Y ~ X, fixed_effects = ~ Bsingle, data = dat) ro <- lm_robust(Y ~ X + factor(Bsingle), data = dat) diff --git a/vignettes/simulations-debiasing-dim.Rmd b/vignettes/simulations-debiasing-dim.Rmd index 97a5f836..cf300fdb 100644 --- a/vignettes/simulations-debiasing-dim.Rmd +++ b/vignettes/simulations-debiasing-dim.Rmd @@ -76,11 +76,11 @@ simp_bl_des <- simp_blocks + # Our diagnosands of interest my_diagnosands <- declare_diagnosands( - `Bias` = mean(est - estimand), - `Coverage` = mean(estimand <= ci_upper & estimand >= ci_lower), - `Mean of Estimated ATE` = mean(est), + `Bias` = mean(estimate - estimand), + `Coverage` = mean(estimand <= conf.high & estimand >= conf.low), + `Mean of Estimated ATE` = mean(estimate), `Mean of True ATE (Estimand)` = mean(estimand), - `Mean Standard Error` = mean(se) + `Mean Standard Error` = mean(std.error) ) ```