我想使用选项分别评估来自 GAM 模型的预测器的每个组件type="terms"
。作为健全性检查,我将结果与使用选项的总预测评估进行了比较type="response"
。
事实证明,结果不同。这是一个例子:
library(mgcv)
n<-200
sig <- 2
dat <- gamSim(1,n=n,scale=sig)
b<-gam(y~x0+s(I(x1^2))+s(x2)+offset(x3),da=dat)
nd <- data.frame(x0=c(.25,.5),x1=c(.25,.5),x2=c(.25,.5),x3=c(.25,.5))
a1 <- predict.gam(b,newdata=nd,type="response")
a2 <- rowSums(predict.gam(b,newdata=nd,type="terms")) + b$coefficients[1]
a1 - a2 # Should be zero!
# 1 2
# 0.25 0.50
谁能帮我解决这个问题?非常感谢您的帮助!