单独更改 GAM 图的选项?

Change options of GAM plots indvidually?

考虑以下代码以适合 GAM:

library(mgcv)
x1=runif(200)
x2=runif(200)
y=sin(x1)+x2^2+rnorm(200)
m = gam(y~s(x1)+s(x2))

现在使用 plot(m) 分别绘制平滑项图,因此要合并图,我找到了这段代码:

par(mfrow=c(1,2))
plot(m)

绘制的图形如下所示:

但是我无法单独更改每个图的选项,例如设置 main="plot" 更改两个图的标题,我需要为每个图设置不同的标题。如何分别更改每个地块的设置选项?

您可以使用 plot.gamselect 参数:

select: Allows the plot for a single model term to be selected for printing. e.g. if you just want the plot for the second smooth term set select=2.

例如:

library(mgcv)
df <- data.frame(x1 = runif(200), x2 = runif(200))
df <- transform(df, y = sin(x1) + x2^2 + rnorm(200))

m <- gam(y~s(x1)+s(x2), data = df)

layout(matrix(1:2, ncol = 2))
plot(m, select = 1, main = "First smooth")
plot(m, select = 2, main = "Second smooth")
layout(1)

结果图如下所示