gam.check
在mgcv
包中应用时,R
会产生一些残差图和基础维度输出。有没有办法只生成图而不是打印输出?
library(mgcv)
set.seed(0)
dat <- gamSim(1,n=200)
b <- gam(y~s(x0)+s(x1)+s(x2)+s(x3), data=dat)
plot(b, pages=1)
gam.check(b, pch=19, cex=.3)
有四个地块,从左上角向下移动,我们有:
在下面的代码中,我假设b
根据您的示例包含您的拟合模型。首先我们需要一些东西
type <- "deviance" ## "pearson" & "response" are other valid choices
resid <- residuals(b, type = type)
linpred <- napredict(b$na.action, b$linear.predictors)
observed.y <- napredict(b$na.action, b$y)
请注意,最后两行将模型拟合到和NA
上的信息时使用的处理方法,即响应数据的存储副本。linear.predictors
y
上面的代码和下面显示的代码都在gam.check()
源代码的前 10 行左右给出。要查看此内容,只需输入
gam.check
在 R 提示符下。
每个地块按如下方式生成:
这是通过以下方式产生的qq.gam()
:
qq.gam(b, rep = 0, level = 0.9, type = type, rl.col = 2,
rep.col = "gray80")
这是使用
hist(resid, xlab = "Residuals", main = "Histogram of residuals")
这是使用
plot(linpred, resid, main = "Resids vs. linear pred.",
xlab = "linear predictor", ylab = "residuals")
这是使用
plot(fitted(b), observed.y, xlab = "Fitted Values",
ylab = "Response", main = "Response vs. Fitted Values")