【问题标题】:Extract values used to make plot for parametric component of GAM in R提取用于绘制 R 中 GAM 参数分量图的值
【发布时间】:2021-12-17 10:15:47
【问题描述】:

我执行了一个包含连续平滑项和分类变量的 GAM。我使用plot(mod,residuals=T,all.terms=T,pages=1) 绘制了模型(mod)。这会生成两个平滑参数以及参数参数的图。我想提取用于制作这些图的值,以便我可以重新制作它们并使它们看起来更好。如果我将绘图保存在一个对象中,这将为我提供平滑项所需的一切,但不包含有关参数组件的任何信息:plot.mod=plot(mod,residuals=T,all.terms=T,select=0)。但是我看不到参数组件的默认绘图的数字来自哪里。有没有办法提取这些?

这是我迄今为止所做的一个可重复的示例

library(mgcv)

# create some data
data=data.frame(response=c(10,12,8,9,3,4,5,5,4,5,4,5,4,1),pred1=c(9,8,8,9,6,7,6,4,3,4,2,3,3,1),pred2=as.factor(c("A","C","B","B","A","A","C","B","C","A","C","B","A","B")),pred3=c(1,6,3,4,8,6,4,5,7,10,11,3,12,1))

# run the GAM
mod <- gam(response ~ s(pred1,k=8) + pred2 + s(pred3,k=5), data=data, family=gaussian(), method="REML")

# the default plot
plot(mod,residuals=T,all.terms=T,pages=1)

# save values in an object. But this only saves the smooth terms.
plot.mod=plot(mod,residuals=T,all.terms=T,select=0)

# How can I extract the values used to plot the parametric term?

我试图提取数据来制作的情节:

【问题讨论】:

    标签: r plot gam mgcv


    【解决方案1】:

    plot.gam 文档中,termplot 用于参数项,所以

    plot.para <- termplot(mod, se = TRUE, plot = FALSE)
    

    将该图保存到列表中。
    格式与其他格式不同,但数据在那里。

    【讨论】:

    • 非常好,这正是我想要的。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-10
    • 2020-02-20
    • 1970-01-01
    • 2015-07-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多