[Rd] Weird problem / bug with augPred() from nlme

Viechtbauer, Wolfgang (SP) wo||g@ng@v|echtb@uer @end|ng |rom m@@@tr|chtun|ver@|ty@n|
Tue Mar 5 12:20:36 CET 2019


Posted this to r-sig-mixed-models (https://stat.ethz.ch/pipermail/r-sig-mixed-models/2019q1/027620.html) but this might rather need to go to r-devel anyway, so reposting here:

I came across a weird problem / bug with augPred() from nlme (nlme_3.1-137). Here is a reproducible example to illustrate the issue (tested on R 3.5.2 and R-devel 2019-03-03 r76192):

library(nlme)

dat <- data.frame(id = c(1,1,1,2,3,3,4,4,4,4),
                  xi = c(1,2,3,1,1,2,1,2,3,4),
                  yi = c(2,1,4,2,3,2,5,4,6,8),
                  zi = c(rep("a",9), NA))

res1 <- lme(yi ~ xi, random = ~ 1 | id, data=dat)
sav1 <- augPred(res1, primary = ~ xi) # WORKS

dat$zi <- "a"

res2 <- lme(yi ~ xi, random = ~ 1 | id, data=dat)
sav2 <- augPred(res2, primary = ~ xi) # WORKS

dat$zi[10] <- NA

res3 <- lme(yi ~ xi, random = ~ 1 | id, data=dat)
sav3 <- augPred(res3, primary = ~ xi) # ERROR

The error message:

Error in `[[<-.data.frame`(`*tmp*`, nm, value = c(1L, 1L, 1L, 2L, 3L,  : 
  replacement has 10 rows, data has 4

So, if 'zi' is a factor, then a missing value causes no problems (sav1). Or if 'zi' is a character variable without any missings, then augPred() also runs (sav2). But if 'zi' is a character variable and there is at least one missing value, then augPred() fails (sav3).

This aside, why does 'zi' even play a role here? It isn't used at all in the model fit.

Best,
Wolfgang



More information about the R-devel mailing list