-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes weighting for lm_lin and blocked difference_in_means #169
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sfsg
R/estimatr_lm_lin.R
Outdated
if (is.numeric(weights)) { | ||
center <- apply(demeaned_covars, 2, weighted.mean, weights) | ||
} else { | ||
center <- TRUE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
center <- colMeans(...)
or simliar - generally don't set a variable to different types in different branches.
R/estimatr_lm_lin.R
Outdated
], | ||
center = TRUE, | ||
demeaned_covars, | ||
center = center, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given above, change scale to sweep.
tests/testthat/test-lm-lin.R
Outdated
lmo$coefficients["am"] | ||
) | ||
|
||
# Weighted matches (one covar) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
split these into different test_that blocks with appropriate lables.
R/estimatr_difference_in_means.R
Outdated
# rescale weights for convenience | ||
if (is.numeric(model_data$weights)) { | ||
weight_mean <- mean(model_data$weights) | ||
data$weights <- model_data$weights / weight_mean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If weight_mean is never used again, ok to put all onto one line.
Previously,
lm_lin
was not demeaning covariates by the weighted mean, and was just using the simple mean (Issue #148). This has been solved.After solving it, a test failed checking
difference_in_means
againstlm_lin
in the blocked, weighted case. This test previously passed because both were wrong in the same say!The above problem is solved now. In
difference_in_means()
we compute the post-stratification estimator as:The problem was that we used
N
andN_overall
rather than the sum of the weights in a block and the sum of all of the weights if you had a blocked, weighted specification. NowN
andN_overall
appropriately capture the weights.