I recently updated R, and now ggpredict
gives me error when calculating the predictions for my mixed effects model (using lme()
function).
I want to analyse how anitoxidant activity varies between (plants at) different sites. In order to do that, I have 5 sites with 3 plots each, measured during 6 years.
I have established a linear mixed effects model (function lme()
) where "anitox" is modeled against the fixed factor site
, and the random factor plot
.
Then I use ggpredict()
(from package ggeffects
) to obtain the model predictions and plot them.
It used to work fine, but since I updated R (version 3.6.0) I get an error message, which i do not know how to solve:
Error: Must use a vector in `[`, not an object of class matrix.
Do you have any idea about what the error means and how to solve the problem? I imagine it must be something with how the data are written/organized, but I do not know what.
Here is the data:
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" ), class = "factor"), site = structure(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, 12, 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.87831523045473, 3.034372394251, 3.21454300619676, 2.74011075995272, 2.33528554925283, 3.03876785046206, 2.44794278726812, 2.31854154139051, 2.53086546956933, 2.80912124091414, 2.44954337356346, 3.28600361541029, 3.44682099175027, 1.20643110534499, 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.93581321506448, 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.76602794573506, 2.8732056665119, 2.9199920351451, 2.79834747669878, 2.58608510953132, 2.83503842669648, 2.73056939041945, 2.74792959562282, 3.45827133986313, 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"))
And this is the model:
m.antiox <- lme(antiox~site, random=~1|plot, data=antiox)
ggpredict(m.antiox)