segmented.lme() 对象的函数 predict()

Function predict() for object of segmented.lme()

我之前 运行 使用 lme4 包中的 glmer() 进行了混合模型分析。我在 MuMIn 包中应用了函数 dredge() 和 get.models() 来量化 top.models。然后,我使用 MuMIn 包中的 model.avg() 方法为函数 predict() 创建了一个拟合对象。最后,我创建了一个名为 newdat 的新数据对象,即为每个预测变量创建一个新对象。

然后我使用了 newdatfinal <- predict(avModX, newdata = newdat, se.fit=TRUE, re.form=NA),其中 avModX 提供了从 subset.top.models <- c(top.models[[1]],top.models[[1]])avModX <- model.avg(subset.top.models) 派生的拟合模型。这一切都很好。

我现在需要在 segmented.lme() 对象上使用 predict()。可以在此处找到函数 segmented.lme() 的代码:https://www.researchgate.net/publication/292986444_segmented_mixed_models_in_R_code_and_data. A reference working paper is available here: https://www.researchgate.net/publication/292629179_Segmented_mixed_models_with_random_changepoints_in_R。此函数允许检测斜率差异并提供变化点估计,即测试数据中的断点。

我第一次使用函数

global.model.lme <- lme(response ~ predictor1*predictor2*predictor3*
                              predictor4 + covariate1 + covariate2 + covariate3,
                            data = mydat,
                            random = list(block = pdDiag(~ 1 + predictor1),
                                          transect = pdDiag(~ 1 + predictor1)),
                            na.action="na.fail") 

然后是函数

global.model.seg <- segmented.lme(global.model.lme, 
                                      Z = predictor1, 
                                      random = list(block = pdDiag(~ 1 + predictor1 + U + G0),
                                                    transect = pdDiag(~ 1 + predictor1 + U + G0)),
                                      psi.link = "identity")

Z = 'segmented' 与响应具有分段关系的协变量,U = 斜率差,G0 = 变化点的随机效应公式(变化点估计)

我现在想在函数 predict() 中使用 segmented.lme() 对象,例如 newdatfinal <- predict(global.model.seg, newdata = newdat, se.fit=TRUE, re.form=NA)

我目前收到错误消息: UseMethod("predict") 错误: 没有适用于 'predict' 的方法应用于 class "segmented.lme"

的对象

这是原始数据的可重现子集:

structure(list(block = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8"), class = "factor"), transect = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("B1L", "B1M", "B1S", "B2L", "B2M", "B2S", "B3L", "B3M", "B3S", "B4L", "B4M", "B4S", "B5L", "B5M", "B5S", "B6L", "B6M", "B6S", "B7L", "B7M", "B7S", "B8L", "B8M", "B8S"), class = "factor"), predictor1 = c(28.63734661, 31.70995133, 27.40407982, 25.48842992, 21.81094637, 24.02032756), predictor2 = c(5.002945364, 6.85567854, 0, 22.470422, 0, 0), predictor3 = c(3.72, 3.55, 3.66, 3.65, 3.53, 3.66), predictor4 = c(504.8, 547.6, 499.7, 497.8, 473.8, 467.5), covariate1 = c(391L, 394L, 351L, 336L, 304L, 335L), covariate2 = c(0.96671086, 2.81939707, 0.899512367, 1.024730094, 1.641161861, 1.419433714), covariate3 = c(0.787505444, 0.641693911, 0.115804751, -0.041146951, 1.983567486, -0.451039179), response = c(0.81257636, 0.622662116, 0.490330786, 0.709929461, -0.156398286, -1.185175095)), .Names = c("block", "transect", "predictor1", "predictor2", "predictor3", "predictor4", "covariate1", "covariate2", "covariate3", "response"), row.names = c(NA, 6L), class = "data.frame")

和 newdat 数据的可重现子集:

structure(list(predictor1 = c(-0.441935, -0.433467318435754,0.424999636871508, -0.416531955307263, -0.408064273743017, -0.399596592178771), covariate1 = c(0L, 0L, 0L, 0L, 0L, 0L), covariate2 = c(0L, 0L, 0L, 0L, 0L, 0L), covariate3 = c(0L, 0L, 0L, 0L, 0L, 0L), 
predictor2 = c(0L, 0L, 0L, 0L, 0L, 0L), predictor3 = c(0L, 
0L, 0L, 0L, 0L, 0L), predictor4 = c(0L, 0L, 0L, 0L, 0L, 0L
)), .Names = c("predictor1", "covariate1", "covariate2", "covariate3", "predictor2", "predictor3", "predictor4"), row.names = c(NA, 6L), class = "data.frame")

非常感谢您的任何建议。

segmented.lme处于初步阶段,所以目前没有预测方法功能。但是,由于该算法依赖于工作线性模型,您可以使用最后一个(收敛时)进行预测,

predict(global.model.seg[[2]], ..)

应仔细检查结果。