When using the newdata argument, predict.phylolm() fails for models built with phylostep(). Here's a reprex based on the ?phylostep example (using the same data for modelling and predicting here, but normally I want to predict beyond that, so I do need to use newdata):
# example data:
set.seed(123456)
tre = rcoal(100)
taxa = sort(tre$tip.label)
b0=0; b1=1;
x1 = rTrait(phy=tre,model="BM",
parameters=list(ancestral.state=0,sigma2=10))
x2 = rTrait(phy=tre,model="BM",
parameters=list(ancestral.state=0,sigma2=10))
x3 = rTrait(phy=tre,model="BM",
parameters=list(ancestral.state=0,sigma2=10))
y <- b0 + b1*x1 + rTrait(n=1,phy=tre,model="BM",
parameters=list(ancestral.state=0,sigma2=1))
dat <- data.frame(trait=y[taxa],pred1=x1[taxa],pred2=x2[taxa],pred3=x3[taxa])
# model and predict:
fit_step <- phylostep(trait~pred1+pred2+pred3,
data=dat,phy=tre)
predict(fit_step, dat)
# Error: $ operator is invalid for atomic vectors
The error doesn't occur if the model is computed with phylolm() and the formula is specified manually:
When using the
newdata
argument,predict.phylolm()
fails for models built withphylostep()
. Here's a reprex based on the?phylostep
example (using the same data for modelling and predicting here, but normally I want to predict beyond that, so I do need to usenewdata
):The error doesn't occur if the model is computed with
phylolm()
and the formula is specified manually:However, if I try to automate extraction of the selected variables from the
phylostep
model object, error again:Regards,