ciTools icon indicating copy to clipboard operation
ciTools copied to clipboard

add_ci.lmer is not robust to formula types

Open andercolin opened this issue 5 years ago • 0 comments

Trying add_ci on a model with a formula involving I(...), i.e.

library(ciTools)
library(lme4)

data <- data.frame(x = c(1, 2, 3, 4), y = c(1, 3, 10, 15), gr = (1, 1, 2, 2))
mod <- lmer(y ~ I(x^2) + (1|gr), data)
add_ci(data, mod)

results in Error in x^2: non-numeric argument to binary operator. Attempting add_ci(data, mod, type = "parametric") results in Error in `[[<-.data.frame`(`*tmp*`, names[1], value = numeric(0)) : replacement has 0 rows, data has 4. The code completes in other cases, but returns spurious confidence intervals and the warning longer object length is not a multiple of shorter object length. At least in the parametric case, the problem appears to be in get_x_matrix_mermod.

Trying add_ci on a model with no fixed effects, i.e.

data <- data.frame(x = rep(seq(5), 2), y = c(rnorm(5), rnorm(5, mean = 0.5)), gr = c(rep(1, 5), rep(2, 5)))
mod <- lmer(y ~ (1 | gr), data)
data %>% add_ci(mod, type = "parametric")

results in Error in reformulate(attributes(terms(fit))$term.labels) : 'termlabels' must be a character vector of length at least one. Again, the problem appears to be in get_x_matrix_mermod.

andercolin avatar Jul 10 '19 20:07 andercolin