anniejw6/modmarg

write test: Drop covariates due to covariate perfectly predicting

Closed this issue · 3 comments

write test: Drop covariates due to covariate perfectly predicting

This doesn't work -- it breaks.

data(mtcars)
  mtcars$am <- factor(mtcars$am)
  mtcars$cyl <- factor(mtcars$cyl)
  mtcars$gear <- factor(mtcars$gear)
  mtcars$disp_colin <- mtcars$disp * 2 + 5

  ols1 <- glm(mpg ~ am * poly(disp, degree = 2, raw = TRUE) +
                cyl + hp + gear + disp_colin, data = mtcars)

  eff1 <- mod_marg2(
    mod = ols1, var_interest = 'am', type = 'effects',
    at = list('disp' = seq(70, 475, 5)))

Covar returned by predict_modelmat doesn't exclude collinear variables so jacobian is non-conformable. Need to figure out how to fix. Don't have time right now.

@nathanielolin -- I feel like you've messed with this a lot. Any ideas?

I think the code is in the wrong order (h/t to @anniejw6 who flagged this at me).

These lines should happen before jacobs is assigned in the previous chunk https://github.com/anniejw6/modmarg/blob/master/R/discrete_wrap.R#L51-L54

Don't know how that snuck past - it's correct in the continuous wrapper. Does that fix it?

This was fixed in the pred_se_wrap refactor.