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

by = for groups with covariates that have no variance #58

Open
mkrasmus opened this issue Apr 15, 2024 · 1 comment
Open

by = for groups with covariates that have no variance #58

mkrasmus opened this issue Apr 15, 2024 · 1 comment

Comments

@mkrasmus
Copy link

Hi @ngreifer do you have any advice for using WeightIt when there are groups (variable for 'by' argument) that have predictors in the PS model that have no variation (ie redundant covariates).

So for example if using 'by = race' and predictors
predvars <- c('age', 'educ','nodegree', 'married', 're74', 're75')

but married had no variation for race at one level, say. In a loop with a separate PS model for each level of race we would do something like the following to trim out 'married' if there were no variance in values:

cdpred <- predvars[sapply(predvars,
function(v) length(unique(lalonde[[v]])) > 1)]
form <- as.formula(paste0("group ~ ",
paste0(c(cdpred), collapse = " + ")))
mod <- glm(form, data = lalonde, family = "binomial")

I'm wondering if there is something in WeightIt that handles a lack of variation in predictors if they spring up at one level, or if its a problem for 'glm' but maybe not the other methods. Any thoughts greatly appreciated, thanks.

@ngreifer
Copy link
Owner

weightit() automatically removes redundant predictors (i.e., those that have no variation or covary exactly with others) before estimating weights, so there should be no problem with any method. For example, if you include the by variable in the model formula, that should induce a redundancy that is automatically taken care of. Different methods do this in different ways, but I have a custom function (that is actually user-facing should you want to use it) that removes linearly dependent columns prior to estimating the weights.

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

No branches or pull requests

2 participants