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

genZcor fails if using unstructured correlation structure with only two observations per cluster #19

Open
jwilliman opened this issue Mar 26, 2023 · 0 comments

Comments

@jwilliman
Copy link

Hello

If there are only two observations per cluster, and an unsturctured correlation structured is used, genZcor and consequently geeglm fail with a relatively unhelpful message.

gendat <- function() {
  id <- gl(5, 4, 20)
  visit <- rep(1:4, 5)
  y <- rnorm(id)
  dat <- data.frame(y, id, visit)[c(-2,-9),]
}
set.seed(88)
dat <- gendat()
dat2 <- subset(dat, visit %in% 1:2)

zcor <- geepack::genZcor(clusz = table(dat$id), waves = dat$visit, corstrv=4)
zcor <- geepack::genZcor(clusz = table(dat2$id), waves = dat2$visit, corstrv=4)
#> Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels

Created on 2023-03-27 with reprex v2.0.2

This appears to be caused by the line ans <- model.matrix(~z - 1) in genZcor, where z is a factor variable with only one level (1:2).

Can this be made to work, or a helpful error message added explaining the problem?

Thanks very much for your work on this package :)

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

1 participant