Skip to content
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

Merged
merged 3 commits into from
Mar 17, 2018

Conversation

lukesonnet
Copy link
Contributor

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 against lm_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:

diff <- with(block_estimates, sum(coefficients * N / N_overall))

The problem was that we used N and N_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. Now N and N_overall appropriately capture the weights.

@lukesonnet lukesonnet requested a review from nfultz March 13, 2018 22:41
@coveralls
Copy link

coveralls commented Mar 13, 2018

Coverage Status

Coverage increased (+0.003%) to 99.173% when pulling 33e3cd7 on ls/weight_lin into 18b6c9a on master.

Copy link
Contributor

@nfultz nfultz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sfsg

if (is.numeric(weights)) {
center <- apply(demeaned_covars, 2, weighted.mean, weights)
} else {
center <- TRUE
Copy link
Contributor

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.

],
center = TRUE,
demeaned_covars,
center = center,
Copy link
Contributor

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.

lmo$coefficients["am"]
)

# Weighted matches (one covar)
Copy link
Contributor

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.

# rescale weights for convenience
if (is.numeric(model_data$weights)) {
weight_mean <- mean(model_data$weights)
data$weights <- model_data$weights / weight_mean
Copy link
Contributor

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.

@lukesonnet lukesonnet merged commit f73db70 into master Mar 17, 2018
@lukesonnet lukesonnet deleted the ls/weight_lin branch March 17, 2018 16:38
This was referenced Mar 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants