R 基于bam{mgcv}的种群水平预测
使用R 基于bam{mgcv}的种群水平预测,r,prediction,mixed-models,mgcv,R,Prediction,Mixed Models,Mgcv,使用bam,我用以下形式制作了一个逻辑混合模型: PresAbs ~ s(Var 1) + s(Var 2) + ... + s(Var n) + s(RandomVar, bs = "re") RandomVar是一个因素,我对它的每个级别的预测都不感兴趣。如何获得与之相当的总体水平预测?一种方法是从预测中排除随机效应样条线 使用《游戏模型》中的示例 library("mgcv") dat <- gamSim(1,n=400,scale=2) ## simulate 4 term ad
bam
,我用以下形式制作了一个逻辑混合模型:
PresAbs ~ s(Var 1) + s(Var 2) + ... + s(Var n) + s(RandomVar, bs = "re")
RandomVar
是一个因素,我对它的每个级别的预测都不感兴趣。如何获得与之相当的总体水平预测?一种方法是从预测中排除随机效应样条线
使用《游戏模型》中的示例
library("mgcv")
dat <- gamSim(1,n=400,scale=2) ## simulate 4 term additive truth
## Now add some random effects to the simulation. Response is
## grouped into one of 20 groups by `fac' and each groups has a
## random effect added....
fac <- as.factor(sample(1:20,400,replace=TRUE))
dat$X <- model.matrix(~fac-1)
b <- rnorm(20)*.5
dat$y <- dat$y + dat$X%*%b
m1 <- gam(y ~ s(fac,bs="re")+s(x0)+s(x1)+s(x2)+s(x3),data=dat,method="ML")
对于观测数据,人口效应为
predict(m1, exclude = 's(fac)')
但您可以提供
newdata
来生成其他协变量组合的预测。预测仅基于与lme模型可用的固定效应“估计值”。例如
predict(m1, exclude = 's(fac)')