Skip to content

Commit

Permalink
Merge pull request #187 from DeclareDesign/ls/gp
Browse files Browse the repository at this point in the history
Ls/gp
  • Loading branch information
lukesonnet committed Mar 22, 2018
2 parents 4e21ce2 + 9be9588 commit c17c9da
Show file tree
Hide file tree
Showing 30 changed files with 964 additions and 989 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -44,6 +44,7 @@ addons:
r_github_packages:
- DeclareDesign/DDtools
- ropensci/git2r
- DeclareDesign/fabricatr@v0.4.0

r_packages:
- broom
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
@@ -1,7 +1,8 @@
Package: estimatr
Type: Package
Title: Fast Estimators for Design-Based Inference
Version: 0.5.0
Version: 0.6.0
Date: 2018-03-21
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")),
Expand Down Expand Up @@ -33,4 +34,3 @@ Suggests:
Enhances:
broom,
texreg
Additional_Repositories: http://r.declaredesign.org
17 changes: 14 additions & 3 deletions NEWS.md
@@ -1,11 +1,22 @@
# estimatr 0.5.0 (GitHub version)
# estimatr 0.6.0

* Fixed bug that caused variances, standard errors, and p-values to be wrong for weighted "CR2" variance estimation
* Added support for multivariate linear models
* Added support for instrumental variables regression
* Major change to name of object output elements to mostly match with `broom::tidy`
* old -> new
* `coefficient_names` -> `term`
* `se` -> `std.error`
* `p` -> `p.values`
* `ci_lower` -> `ci.lower`
* `ci_upper` -> `ci.upper`
* All of the above changes are also made to the column names on the output of `tidy`; furthermore for `tidy` objects one further name change from `coefficients` -> `estimate` has been made
* Fixed bug that caused variances, standard errors, and p-values to be wrong for weighted "CR2" variance estimation
* Fixed incorrect estimates when both weights and blocks were passed to `difference_in_means`
* Rewrite NSE handling to be done by `rlang`
* Rewrite `na.omit` handler in R
* Major refactor of C++ underlying regression estimators

# estimatr 0.4.0 (CRAN version)
# estimatr 0.4.0

* Changed suffix added to centered variables in `lm_lin()` from `_bar` to `_c`
* Added all vignettes to `.Rbuildignore`, only available on website now
Expand Down
4 changes: 2 additions & 2 deletions R/RcppExports.R
Expand Up @@ -29,7 +29,7 @@ lm_variance_cr2 <- function(X, Xunweighted, XtX_inv, ei, weight_mean, clusters,
.Call(`_estimatr_lm_variance_cr2`, X, Xunweighted, XtX_inv, ei, weight_mean, clusters, J, ci, which_covs)
}

naomitwhy <- function(df, is_na_generic) {
.Call(`_estimatr_naomitwhy`, df, is_na_generic)
naomitwhy <- function(df, recursive_subset) {
.Call(`_estimatr_naomitwhy`, df, recursive_subset)
}

30 changes: 14 additions & 16 deletions R/S3_confint.R
Expand Up @@ -19,26 +19,24 @@ confint.iv_robust <- confint_lm_like


#' @export
confint.difference_in_means <-
function(object,
parm = NULL,
level = NULL,
...) {
cis <- get_ci_mat(object, level)
confint.difference_in_means <- function(object,
parm = NULL,
level = NULL,
...) {
cis <- get_ci_mat(object, level)

return(cis)
}
return(cis)
}

#' @export
confint.horvitz_thompson <-
function(object,
parm = NULL,
level = NULL,
...) {
cis <- get_ci_mat(object, level, ttest = FALSE)
confint.horvitz_thompson <- function(object,
parm = NULL,
level = NULL,
...) {
cis <- get_ci_mat(object, level, ttest = FALSE)

return(cis)
}
return(cis)
}


## internal method that builds confidence intervals and labels the matrix to be returned
Expand Down
1 change: 0 additions & 1 deletion R/S3_predict.R
Expand Up @@ -119,7 +119,6 @@ predict.lm_robust <- function(object,
interval <- match.arg(interval)

if (se.fit || interval != "none") {

if (ncol(coefs) > 1) {
stop("Can't set `se.fit` == TRUE with multivariate outcome")
}
Expand Down
22 changes: 9 additions & 13 deletions R/S3_print.R
Expand Up @@ -13,7 +13,8 @@ print_summary_lm_like <- function(x,
...) {
cat(
"\nCall:\n", paste(deparse(x$call, nlines = 5), sep = "\n", collapse = "\n"),
"\n\n", sep = ""
"\n\n",
sep = ""
)
if (x$weighted) {
cat("Weighted, ")
Expand Down Expand Up @@ -67,18 +68,13 @@ print.summary.iv_robust <- function(x,
}

#' @export
print.difference_in_means <-
function(
x,
...) {
cat("Design: ", x$design, "\n")
print(summarize_tidy(x))
}
print.difference_in_means <- function(x, ...) {
cat("Design: ", x$design, "\n")
print(summarize_tidy(x))
}


#' @export
print.horvitz_thompson <-
function(x,
...) {
print(summarize_tidy(x))
}
print.horvitz_thompson <- function(x, ...) {
print(summarize_tidy(x))
}
21 changes: 6 additions & 15 deletions R/S3_summary.R
@@ -1,7 +1,5 @@
#' @export
summary.lm_robust <- function(object,
...) {

summary.lm_robust <- function(object, ...) {
if (is.matrix(coef(object))) {
ny <- ncol(coef(object))

Expand Down Expand Up @@ -29,7 +27,6 @@ summary.lm_robust <- function(object,
all_models <- object

for (i in seq(ny)) {

for (nm in names(object)) {
if (nm %in% mat_objs) {
object[[nm]] <- all_models[[nm]][, i, drop = TRUE]
Expand All @@ -52,9 +49,7 @@ summary.lm_robust <- function(object,
}

#' @export
summary.iv_robust <- function(object,
...) {

summary.iv_robust <- function(object, ...) {
summary_lm_model(object)
}

Expand Down Expand Up @@ -85,8 +80,7 @@ summary_lm_model <- function(object) {


#' @export
summary.difference_in_means <- function(object,
...) {
summary.difference_in_means <- function(object, ...) {
return(list(
coefficients = summarize_tidy(object),
design = object$design
Expand All @@ -95,12 +89,9 @@ summary.difference_in_means <- function(object,


#' @export
summary.horvitz_thompson <-
function(
object,
...) {
return(list(coefficients = summarize_tidy(object, "z")))
}
summary.horvitz_thompson <- function(object, ...) {
return(list(coefficients = summarize_tidy(object, "z")))
}

summarize_tidy <- function(object, test = "t", ...) {
remove_cols <- c("term", "outcome")
Expand Down
5 changes: 3 additions & 2 deletions R/S3_tidy.R
Expand Up @@ -83,7 +83,6 @@ tidy.horvitz_thompson <- function(object, ...) {


tidy_data_frame <- function(object, digits = NULL) {

vec_cols <-
c(
"coefficients",
Expand All @@ -94,7 +93,9 @@ tidy_data_frame <- function(object, digits = NULL) {
"df"
)

tidy_mat <- do.call("cbind", lapply(vec_cols, function(x) {as.vector(object[[x]])}))
tidy_mat <- do.call("cbind", lapply(vec_cols, function(x) {
as.vector(object[[x]])
}))
vec_cols[which(vec_cols == "coefficients")] <- "estimate"
colnames(tidy_mat) <- vec_cols
return_frame <- data.frame(
Expand Down

0 comments on commit c17c9da

Please sign in to comment.