无法使ggpredict处理来自lme模型的结果(更新R后)

时间:2019-06-10 11:52:41

标签: r predict nlme

我最近更新了R,现在ggpredict给我的混合效果模型的预测(使用lme()函数时给了我错误。

我想分析一下(不同地点的植物之间)抗氧化剂活性如何变化。为此,我有5个站点,每个站点有3个地块,在6年内进行了测量。

我建立了一个线性混合效应模型(函数lme()),其中“ anitox”是针对固定因子site和随机因子plot建模的。

然后,我使用ggpredict()(来自软件包ggeffects)来获取模型预测并进行绘制。

它曾经可以正常工作,但是由于我更新了R(版本3.6.0),因此收到一条错误消息,我不知道该如何解决:

  

错误:必须在`[`中使用向量,而不是类矩阵的对象。

您是否知道错误的含义以及如何解决问题?我想这一定与数据的写入/组织方式有关,但我不知道是什么。

以下是数据:

structure(list(year = structure(c(1L,1L,1L,2L,2L,2L,3L, 3L,3L,4L,4L,4L,5L,5L,5L,6L,6L,6L,1L,1L,1L,2L,2L, 2L,3L,3L,3L,4L,4L,4L,5L,5L,5L,6L,6L,6L,1L,1L,2L, 2L,2L,3L,3L,3L,4L,4L,4L,5L,5L,5L,6L,6L,6L,1L,1L, 1L,2L,2L,2L,3L,3L,3L,4L,4L,4L,5L,5L,5L,6L,6L,6L, 1L,1L,1L,2L,2L,2L,3L,3L,3L,4L,4L,4L,5L,5L,5L,6L, 6L,6L),.Label = c(“ 2011”,“ 2012”,“ 2013”​​,“ 2014”,“ 2015”,“ 2016” ),类别=“因子”),位置=结构(c(1L,1L,1L,1L,1L, 1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,2L,2L,2L, 2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,3L, 3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L, 4L,4L,4L,4L,4L,4L,4L,4L,4L,4L,4L,4L,4L,4L,4L,4L, 4L,4L,5L,5L,5L,5L,5L,5L,5L,5L,5L,5L,5L,5L,5L,5L, 5L,5L,5L,5L),. Label = c(“ Rebbenes”,“ Skogsfjord”,“ Snarby”, “ Skibotn”,“ Gukhesjavri”),class =“ factor”),plot = c(11,12, 13,11,12,13,11,11,13,11,12,13,11,12,13,11,12,13, 21,22,23,21,22,23,21,22,23,21,22,23,21,22,23,21, 22、23、31、32、31、32、33、31、32、33、31、32、33、31、32、33, 31、32、33、41、42、43、41、42、43、41、42、43、41、42、43、41, 42、43、41、42、43、51、52、53、51、52、53、51、52、53、51、52, 53,51,52,53,51,52,53),antiox = c(2.46653362547122,2.47281284862989, 3.08407675482263、2.88731523045473、3.034372394251、3.21454300619676, 2.74011075995272、2.33528554925283、3.03876785046206、2.47494278726812, 2.31854154139051、2.53086546956933、2.80912124091414、2.44954337356346, 3.28600361541029、3.44682099175027、1.20463110534499、3.35829625741535, 3.05272373173726,2.99366209743898,3.16879701865554,3.22166561521105, 3.17619665222095、3.27004641403846、3.00891075995272、2.69110819491058, 2.56533904870318、2.72225865388593、2.50975004267303、2.71080830577306, 3.21333084150044,3.42928071324833,3.23869397818054,3.50487302546225, 3.45334645895437、3.32049779644063、2.99351321506448、3.09215971561413, 3.02336528541992、3.05388107875081、3.13256220736936、2.4930048603558, 2.43519907068925,2.50833355218431,2.38878206812421,2.12290006006265, 2.21622655328361、3.04982479532968、3.11766502984782、3.1409350921417, 3.70615906430432、3.35201703425668、3.07677775246848、3.09648082230486, 3.10361574352142、3.16501054015022、2.68618331400182、3.15280346790435, 3.17590731546756、2.85941599996738、2.70762794573506、2.88732056665119, 2.9199920351451、2.77984747669878、2.58608510953132、2.83503842669648, 2.73056939041945、2.74792959562282、3.445827133986313、3.50868980816654, 3.71756016360809、3.1311150472957、2.990842126812、3.04599463688895, 2.62511479073322,2.66155890945803,2.76085682078086,2.69787990616012, 3.01615649098973、3.04644450857859、2.49460544665114、2.41654608424733, 2.6073852194617,1.64795744465177,2.71924216432931,2.72552138748798, 3.09217877114499,3.14044260405082,2.87856206172762)),row.names = c(NA, -89L),class = c(“ tbl_df”,“ tbl”,“ data.frame”))

这是模型:

m.antiox <-lme(antiox〜site,random =〜1 | plot,data = antiox)

ggpredict(m.antiox)

1 个答案:

答案 0 :(得分:0)

无法重现您的错误,对我来说,一切正常:

library(nlme)
library(ggeffects)

snowmelt <- c(rep("early", 20), rep("mid",20), rep("late",20))
transect <- c(rep("T1",10), rep("T2",10), rep("T3",10), rep("T4",10), rep("T5",10), rep("T6",10))
plot <- c("T1_1","T1_1","T1_2","T1_2","T1_3","T1_3","T1_4","T1_4","T1_5","T1_5","T2_1","T2_1","T2_2","T2_2","T2_3","T2_3","T2_4","T2_4","T2_5","T2_5","T3_1","T3_1","T3_2","T3_2","T3_3","T3_3","T3_4","T3_4","T3_5","T3_5","T4_1","T4_1","T4_2","T4_2","T4_3","T4_3","T4_4","T4_4","T4_5","T4_5","T5_1","T5_1","T5_2","T5_2","T5_3","T5_3","T5_4","T5_4","T5_5","T5_5","T6_1","T6_1","T6_2","T6_2","T6_3","T6_3","T6_4","T6_4","T6_5","T6_5")
soillayer <- c(rep(c("shallow","deep"),30))
success <- runif(60)

plantsuccess <- data.frame(snowmelt, plot, soillayer, success)
m.success <- lme(success ~ snowmelt+soillayer, random=~1|transect/plot, data=plantsuccess)

ggpredict(m.success, c("snowmelt","soillayer"))
#> 
#> # Predicted values of success
#> # x = snowmelt
#> 
#> # soillayer = deep
#>  x predicted std.error conf.low conf.high
#>  1     0.479     0.088    0.307     0.651
#>  2     0.599     0.088    0.427     0.771
#>  3     0.465     0.088    0.293     0.637
#> 
#> # soillayer = shallow
#>  x predicted std.error conf.low conf.high
#>  1     0.521     0.088    0.349     0.693
#>  2     0.642     0.088    0.470     0.814
#>  3     0.508     0.088    0.336     0.680

reprex package(v0.3.0)于2019-06-10创建