与任何类一样,这些lme
对象被设计为包含它们可能需要的所有内容,以便在其上调用任何已编写的函数。如果您只想使用裸露的骨骼,则只需提取所需的内容并重新分配类,以便调用正确的 S3 方法。要查看您需要哪些组件,您必须查看源代码nlme:::predict.lme
。这是数据集的示例Orthodont
。
library(nlme)
data(Orthodont)
# Just fit a model
fm1 <- lme(distance ~ age, data = Orthodont)
# pull out the minimal components needed for prediction
min_fm1 <- list(modelStruct = fm1$modelStruct,
dims = fm1$dims,
contrasts = fm1$contrasts,
coefficients = fm1$coefficients,
groups = fm1$groups,
call = fm1$call,
terms = fm1$terms)
# assign class otherwise the default predict method would be called
class(min_fm1) <- "lme"
# By dropping this like fm1$data you trim it down quite a bit
object.size(fm1)
63880 bytes
object.size(min_fm1)
22992 bytes
# make sure output identical
identical(predict(min_fm1, Orthodont, level = 0, na.action = na.omit),
predict(fm1, Orthodont, level = 0, na.action = na.omit))
[1] TRUE