[R-sig-ME] MCMCglmm predictions using new data error
Sven E. Templer
sven.templer at gmail.com
Thu Jan 7 21:06:16 CET 2016
Hi Alberto,
avoid the error from predict by running
pred_grid$y <- 0
before
predict(fit, newdata = pred_grid)
Best,
Sven
> On 06 Jan 2016, at 23:39, Alberto Gallano <alberto.gc8 at gmail.com> wrote:
>
> I'm trying to make predictions from an MCMCglmm model using new data. This
> is a feature that was recently added to the predict.MCMCglmm function
> (version 2.22). However, when I set things up as I would for other predict
> methods, I get the following error:
>
>> Error in eval(expr, envir, enclos) : object 'y' not found
>
> where 'y' is my response vector. I'm including a simplified replicable
> example below. Is the set up of the prediction grid different for the
> MCMCglmm predict method compared with other methods?
>
> best,
> Alberto
>
> #
> ----------------------------------------------------------------------------------
> library(MCMCglmm)
>
> set.seed(123)
>
> dat <- data.frame(x = rnorm(100), y = rnorm(100))
>
>
> fit <- MCMCglmm(
>
> fixed = y ~ x,
>
> rcov = ~ units,
>
> data = dat,
>
> family = "gaussian",
>
> pr = TRUE, pl = TRUE,
>
> saveX = TRUE, saveZ = TRUE,
>
> nitt = 1.3e+4, thin = 10, burnin = 3e+3
>
> )
>
>
> pred_grid <- data.frame(x = seq(-1, 1, length.out = 30))
>
>
> predict(fit, newdata = pred_grid)
>
> #
> ----------------------------------------------------------------------------------
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
More information about the R-sig-mixed-models
mailing list