NA
正在发生?我怎么能摆脱它?
simfun <- function(J,n_j,g00,g10,g01,g11,sig2_0,sig01,sig2_1){
N <- sum(rep(n_j,J))
x <- rnorm(N)
z <- rnorm(J)
mu <- c(0,0)
sig <- matrix(c(sig2_0,sig01,sig01,sig2_1),ncol=2)
u <- rmvnorm(J,mean=mu,sigma=sig)
b_0j <- g00 + g01*z + u[,1]
b_1j <- g10 + g11*z + u[,2]
y <- rep(b_0j,each=n_j)+rep(b_1j,each=n_j)*x + rnorm(N,0,sqrt(0.5))
sim_data <- data.frame(Y=y,X=x,Z=rep(z,each=n_j),group=rep(1:J,each=n_j))
}
noncoverage <- function(J,n_j,g00,g10,g01,g11,sig2_0,sig01,sig2_1){
dat <- simfun(J,n_j,g00,g10,g01,g11,sig2_0,sig01,sig2_1)
fit <- lmer(Y~X+Z+X:Z+(X||group),data=dat,control=lmerControl(optCtrl=list(maxfun=20000)))
ci=confint.merMod(fit,oldName=FALSE,c("sd_(Intercept)|group","sd_X|group","sigma"))
ci.u0 = as.numeric(ci[1,])
nc.u0 = ifelse((ci.u0[1]<sqrt(sig2_0) & ci.u0[2]>sqrt(sig2_0)),0,1)
ci.u1 = as.numeric(ci[2,])
nc.u1 = ifelse((ci.u1[1]<sqrt(sig2_1) & ci.u1[2]>sqrt(sig2_1)),0,1)
ci.e = as.numeric(ci[3,])
nc.e = ifelse((ci.e[1]<sqrt(0.5) & ci.e[2]>sqrt(0.5)),0,1)
nc = data.frame(nc.u0=nc.u0,nc.u1=nc.u1,nc.e=nc.e)
}
fit <- replicate(10,noncoverage(10,5,1,.3,.3,.3,(1/18),0,(1/18)))
fit
, , 1
nc.u0 nc.u1 nc.e
1 0 0 0
, , 2
nc.u0 nc.u1 nc.e
1 0 0 0
, , 3
nc.u0 nc.u1 nc.e
1 1 0 0
, , 4
nc.u0 nc.u1 nc.e
1 NA 0 0
, , 5
nc.u0 nc.u1 nc.e
1 0 NA 0
, , 6
nc.u0 nc.u1 nc.e
1 1 0 0
, , 7
nc.u0 nc.u1 nc.e
1 0 0 1
, , 8
nc.u0 nc.u1 nc.e
1 0 0 0
, , 9
nc.u0 nc.u1 nc.e
1 0 0 0
, , 10
nc.u0 nc.u1 nc.e
1 0 NA 0
答案 0 :(得分:1)
此处的问题(已在lme4
...的开发版本中修复)是使用样条拟合构建似然概要。如果轮廓太平,则样条曲线拟合将失败。在这种情况下,开发版本现在尝试替换线性插值。
simfun <- function(J,n_j,g00,g10,g01,g11,sig2_0,sig01,sig2_1){
N <- sum(rep(n_j,J))
x <- rnorm(N)
z <- rnorm(J)
mu <- c(0,0)
sig <- matrix(c(sig2_0,sig01,sig01,sig2_1),ncol=2)
u <- MASS::mvrnorm(J,mu=mu,Sigma=sig)
b_0j <- g00 + g01*z + u[,1]
b_1j <- g10 + g11*z + u[,2]
y <- rep(b_0j,each=n_j)+rep(b_1j,each=n_j)*x + rnorm(N,0,sqrt(0.5))
sim_data <- data.frame(Y=y,X=x,Z=rep(z,each=n_j),
group=rep(1:J,each=n_j))
}
set.seed(102)
dat <- simfun(10,5,1,.3,.3,.3,(1/18),0,(1/18))
library("lme4") ## version 1.1-9
fit <- lmer(Y~X+Z+X:Z+(X||group),data=dat)
pp <- profile(fit,"theta_",quiet=TRUE) ## warnings
cc <- confint(pp) ## warning
## 2.5 % 97.5 %
## .sig01 0.0000000 0.2880457
## .sig02 0.0000000 0.5427609
## .sigma 0.5937762 0.8802176
您还应注意这些置信区间are based on ML, not REML, fits ...