0
我試圖在lme4
中使用glmer
模型中的simulate
。我試圖通過newdata
,但獲得各種格式的不同錯誤。可能只是不理解函數需要什麼格式,但包示例也會產生錯誤。從包數據使用模擬混合模型中的新數據產生的錯誤
實施例:
# Mixed model
gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
data = cbpp, family = binomial)
# Generate new data as per example
newdata <- with(cbpp, expand.grid(period=unique(period), herd=unique(herd)))
# Predict works as expected
predict(gm1, newdata=newdata) # works
predict(gm1, newdata=newdata[1,]) # works
# Simulate generates different errors
simulate(gm1, newdata=newdata) # works with error, but probably fine.
# Warning message:
# In wts - Y :
# longer object length is not a multiple of shorter object length
simulate(gm1, newdata=newdata[1,]) # doesn't work
# Error in data.frame(sim_1 = c(" 4", "10"), check.names = FALSE, row.names = "1") :
# 'row.names' should specify one of the variables
# In addition: Warning message:
# In format.data.frame(x, digits = digits, na.encode = FALSE) :
# corrupt data frame: columns will be truncated or padded with NAs
newdata2 = data.frame(
herd=c("1"),
period=c("1")
)
simulate(gm1, newdata=newdata2) # same error
simulate(gm1, newdata=newdata[1:2,]) # works but with error
# Warning message:
# In format.data.frame(x, digits = digits, na.encode = FALSE) :
# corrupt data frame: columns will be truncated or padded with NAs
R version 3.2.1 (2015-06-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.1 LTS
other attached packages:
[1] ggplot2_1.0.0 Zelig_3.5.4 boot_1.3-9 MASS_7.3-29 Hmisc_3.14-5
[6] Formula_1.1-2 survival_2.37-7 lattice_0.20-29 plyr_1.8.1 RCurl_1.95-4.3
[11] bitops_1.0-6 lme4_1.1-10 Matrix_1.1-2
loaded via a namespace (and not attached):
[1] Rcpp_0.12.1 cluster_1.14.4 munsell_0.4.2 colorspace_1.2-4
[5] minqa_1.2.4 stringr_0.6.2 tools_3.2.1 nnet_7.3-7
[9] MatchIt_2.4-21 gtable_0.1.2 nlme_3.1-113 latticeExtra_0.6-26
[13] digest_0.6.4 reshape2_1.4 RColorBrewer_1.0-5 nloptr_1.0.4
[17] acepack_1.3-3.3 rpart_4.1-5 labeling_0.3 scales_0.2.4
[21] foreign_0.8-59 proto_0.3-10