楼主: crain1984
10542 7

[问答] R: gam(在s(x, k=...)... ) 中的k值如何选取 [推广有奖]

  • 0关注
  • 1粉丝

已卖:8份资源

博士生

67%

还不是VIP/贵宾

-

威望
0
论坛币
1095 个
通用积分
0.0027
学术水平
2 点
热心指数
9 点
信用等级
2 点
经验
353 点
帖子
135
精华
0
在线时间
513 小时
注册时间
2008-7-29
最后登录
2025-5-28

楼主
crain1984 发表于 2011-6-7 20:49:07 |AI写论文
100论坛币
在模型 gam(y~s(x,k=...,))
不同的k
y随x的变化趋势不同。见附件。
第一个图模型中用k=10
因变量随着自变量的增加而呈现先下降后上升的趋势。
第二个图模型中用k=15
因变量随着自变量的增加而一直呈现下降的趋势。
请问如何选取k值。最好有例题说明。
对任何回复 或者提示 或者任何意见 表示衷心的感谢并予以评分!
最佳答案悬赏100论坛币。

最佳答案

epoh 查看完整内容

Package 'mgcv' mgcv.pdf page12 -page14 choose.k Basis dimension choice for smooths 里面的说明及各种范例 已经说明的非常清楚 楼主看了,自当了然. 1. fit your model and extract the deviance residuals; 2. for each smooth term in your model, fit an equivalent, single, smooth to the residuals, using a substantially increased k to see if there is pattern in the residuals that could pote ...
关键词:GAM 100论坛币 悬赏100 0论坛币 最佳答案 GAM

沙发
epoh 发表于 2011-6-7 20:49:08
Package 'mgcv'
mgcv.pdf page12 -page14
choose.k    Basis dimension choice for smooths
里面的说明及各种范例
已经说明的非常清楚
楼主看了,自当了然.
1. fit your model and extract the deviance residuals;
2. for each smooth term in your model, fit an equivalent, single,
   smooth to the residuals, using a substantially increased k to
   see if there is pattern in the residuals that could potentially
   be explained by increasing k.

###########
## Simulate some data ....
library(mgcv)
set.seed(0)
dat <- gamSim(1,n=400,scale=2)
## fit a GAM with quite low 'k'
b<-gam(y~s(x0,k=6)+s(x1,k=6)+s(x2,k=6)+s(x3,k=6),data=dat)
plot(b,pages=1)
## Economical tactic (see below for more obvious approach)....
## check for residual pattern, removeable by increasing 'k'
## typically 'k', below, chould be substantially larger than
## the original, 'k' but certainly less than n/2.
## Note use of cheap "cs" shrinkage smoothers, and gamma=1.4
## to reduce chance of overfitting...
rsd <- residuals(b)
gam(rsd~s(x0,k=40,bs="cs"),gamma=1.4,data=dat) ## fine
gam(rsd~s(x1,k=40,bs="cs"),gamma=1.4,data=dat) ## fine
gam(rsd~s(x2,k=40,bs="cs"),gamma=1.4,data=dat) ## `k' too low
gam(rsd~s(x3,k=40,bs="cs"),gamma=1.4,data=dat) ## fine
已有 2 人评分学术水平 热心指数 信用等级 收起 理由
esir + 1 + 1 + 1 我很赞同
crain1984 + 1 + 1 + 1 谢谢 解答 我要先慢慢看:)

总评分: 学术水平 + 2  热心指数 + 2  信用等级 + 2   查看全部评分

藤椅
crain1984 发表于 2011-6-7 21:09:35
欢迎大家讨论。任何回复都有评分:)

板凳
crain1984 发表于 2011-6-8 16:07:14
No answers?
No idea?

报纸
wzy1713 发表于 2011-6-10 13:52:25
等待answer,我基本上都不设定的!
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
crain1984 + 1 + 1 + 1 谢谢 参与

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

地板
crain1984 发表于 2011-6-10 15:03:00
等得我们花都谢了,希望有经验的童鞋,留下点什么。谢谢。

7
云定海 发表于 2015-12-25 15:04:41
无法下载附件 无法显示此页 楼主能否分析下这个文件 最近在做GAM 急用中 kimi11089@126.com

8
追求自我的水瓶座 发表于 2018-5-14 15:47:26
建议楼主仔细看一下,R中mgcv的内容,能解决你所有问题。

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-25 16:50