从 R gamlss 对象预测新拟合值时出错

Bon*_*ieM 5 r predict gam

我有一个 gamlss 模型,我想用它来进行新的 y 预测(和置信区间),以便可视化模型与真实数据的拟合程度。我想从随机预测值的新数据集(而不是原始数据)中进行预测,但我遇到了错误消息。下面是一些示例代码:

library(gamlss)    

# example data
irr <- c(0,0,0,0,0,0.93,1.4,1.4,2.3,1.5)
lite <- c(0,1,2,2.5)
blck <- 1:8
raw <- data.frame(
   css =abs(rnorm(500, mean=0.5, sd=0.1)),
   nit =abs(rnorm(500, mean=0.72, sd=0.5)),
   irr =sample(irr, 500, replace=TRUE),
   lit =sample(lite, 500, replace=TRUE),
   block =factor(sample(blck, 500, replace=TRUE))
)

# the model
mod <- gamlss(css~nit + irr + lit + random(block), 
       sigma.fo=~irr*nit + random(block), data=raw, family=BE)

# new data (predictors) for making css predictions
pred <- data.frame(
nit =abs(rnorm(500, mean=0.72, sd=0.5)),
irr =sample(irr, 500, replace=TRUE),
lit =sample(lite, 500, replace=TRUE),
block =factor(sample(blck, 500, replace=TRUE))
)

# make predictions
predmu <- predict(mod, newdata=pred, what="mu", type="response")
Run Code Online (Sandbox Code Playgroud)

这给出了以下错误:

Error in data[match(names(newdata), names(data))] : 
  object of type 'closure' is not subsettable
Run Code Online (Sandbox Code Playgroud)

当我在我的真实数据上运行这个时,它给出了这个稍微不同的错误:

Error in `[.data.frame`(data, match(names(newdata), names(data))) : 
  undefined columns selected
Run Code Online (Sandbox Code Playgroud)

当我使用predictwithout 时newdata,它可以很好地对原始数据进行预测,如下所示:

predmu <- predict(mod, what="mu", type="response")
Run Code Online (Sandbox Code Playgroud)

我使用预测错误吗?任何建议都非常感谢!谢谢你。

Hed*_*hog 6

不,你没有错。我也经历过同样的问题。

文档表明预测的实现不完整。这似乎是一个不完整的特性/功能的示例。