anniejw6/modmarg

Unhelpful Error

akgold opened this issue · 5 comments

Accidentally tried to do something stupid in vignette, but error message is unhelpful. Trying to specify that you want margins of continuous variable without at list.

Error message: Error in poly(age, 2) : 'degree' must be less than number of unique points

Code:

data(margex)

g <- glm(y ~ poly(age, 2)*sex , data = margex)
summary(g)
modmarg::mod_marg2(g, var_interest = "age")

It looks like this is a more general error. Running at with polynomial term seems to break.

data(margex)

g <- glm(y ~ poly(age, 2)*sex , data = margex)
modmarg::mod_marg2(g, var_interest = "treatment", type = "effects", 
                   at = list(age = seq(20, 60, 5)))

Error: Error in poly(age, 2) : 'degree' must be less than number of unique points

So fascinating...

data(margex)

# Fails to run
g <- glm(y ~ poly(age, 2) * sex , data = margex)
modmarg::mod_marg2(g, var_interest = "sex", "effects", 
                   at = list(age = seq(20, 60, 5)))

# Runs
g <- glm(y ~ poly(age, 2, raw = T) * sex , data = margex)
modmarg::mod_marg2(g, var_interest = "sex", type = "effects", 
                   at = list(age = seq(20, 60, 5)))

This makes sense to me intuitively insofar as poly (with raw set to F, which is the default) creates orthogonal vectors, and you can't really do that for a constant. Not sure how to deal with the error...

Add something to error that says You may be seeing this error because you used the poly() function and did not specify the option raw = T`? Just so that people have some idea how to fix...

Addressed in PR #80