我已经建立了一个 GAMLSS 模型来基于现有数据集调查鱼类的种群驱动因素,但是在尝试预测新数据集的响应值时出现了问题。
要创建一个虚拟数据集:
Site <- c("Angle Crossing","Angle Crossing Pool","Casuarina Sands","Kambah Pool","Kissops Flat","Lawler Rd","Point Hut Crossing","Retallacks Hole","Scottsdale","Tharwa Sandwash")
Year <- round((rnorm(n=100, mean=2013, sd=2.530846)), digits=0)
LogTurbidity <- (rnorm(n=100, mean=2.026, sd=1.417185))
Datej <- rnorm(n=100, mean=105.0, sd=41.66927)
Catch <- round((rnorm(n=100, mean=1.596, sd=1.895757)), digits=0)
Catch <- ifelse(Catch < 0, 0, Catch)
mc.dummy <- data.frame(Site=Site, Catch=Catch, Year=Year,
Turbidity=LogTurbidity, Datej=Datej)
使用 GAMLSS 模型:
ZIPGAMM.dummy <- gamlss(Catch ~ cs(Datej, k=5) + cs(Year, k=5) + cs(Turbidity, k=5) + random(Site), family= ZIP(), data=mc.dummy, n.cyc=100)
当我在predict()
现有数据集上运行该函数时,我能够毫无问题地获得所有模型参数。但是,当我尝试使用新数据集 ( MC.df.newdata <- data.frame(Datej=c(1:100), Year=2010, Turbidity=1.959954, Site="Retallacks Hole")
) 获取预测响应值时,我收到以下错误消息:
MC.predicted <- predict(ZIPGAMM.dummy, newdata = MC.df.newdata, what="mu", type="response")
new prediction
Error in pred.s %*% rep(1, n.smooths) :
requires numeric/complex matrix/vector arguments
In addition: Warning message:
contrasts dropped from factor random(Site)
我使用了上面所有相同的代码,+random(Site)
一切正常,所以我的问题是如何让predict()
函数在模型中使用随机效应?