Closed cbaumbach closed 6 years ago
Thank you for trying my package and for reaching out. I will try to fix it as soon as I can.
Thank you very much for letting me know about this problem! Sorry for the very long response time. I believe I fixed it in the new version (1.1.2) that I just pushed to Github. Please let me know if you encounter any further problems.
If one of my covariates is categorical with 3 or more levels, I get the following error message:
Error in
contrasts<-
(*tmp*
, value = contr.funs[1 + isOF[nn]]) : contrasts can be applied only to factors with 2 or more levels In addition: Warning message: In[<-.factor
(*tmp*
, ri, value = c(0, 0, 0, 0, 0, 0, 0, 0, 0, : invalid factor level, NA generatedHere is an example that reproduces the error:
`n <- 100 d <- data.frame( id = rep(1:(n/2), 2), y = sample(0:1, n, TRUE), e = runif(n), m = factor(sample(0:1, n, TRUE)), v = factor(sample(1:3, n, TRUE)))
library(GEEmediate) GEEmediate(y ~ e + m + v, exposure = "e", mediator = "m", df = d, family = binomial, corstr = "exchangeable", id = d$id)`
I tracked down the problem to DupliData. When it duplicates the 3-level categorical v variable, sets the duplicate v to all 0s, and does an rbind with the original v (which does not have level 0!) the factor complains.
Would it be possible to adjust DupliData to work around this problem or is there a theoretical limitation that I am not aware of?
Thanks in advance for your efforts!