- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在寻找一种方法来添加模型中每个变量的预测值(真实的,非标准化的)
> model<-gam(LN_Brutto~s(agecont,by=Sex)+factor(Sex)+te(Month,Age)+s(Month,by=Sex),
data=bears)
这是我的模型的总结:
> summary(m13)
Family: gaussian
Link function: identity
Formula:
LN_Brutto ~ s(agecont, by = Sex) + factor(Sex) + te(Month, Age) +
s(Month, by = Sex)
Parametric coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 4.32057 0.01071 403.34 <2e-16 ***
factor(Sex)m 0.27708 0.01376 20.14 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Approximate significance of smooth terms:
edf Ref.df F p-value
s(agecont):Sexf 8.1611 8.7526 20.170 < 2e-16 ***
s(agecont):Sexm 6.6695 7.5523 32.689 < 2e-16 ***
te(Month,Age) 10.3651 12.7201 6.784 2.19e-12 ***
s(Month):Sexf 0.9701 0.9701 0.641 0.430
s(Month):Sexm 1.3750 1.6855 0.193 0.787
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Rank: 60/62
R-sq.(adj) = 0.781 Deviance explained = 78.7%
GCV = 0.048221 Scale est. = 0.046918 n = 1093
预测值由这段代码提供:
> predict<-predict(m13, type = "terms")
结果是这样的:
factor(Sex) s(agecont):Sexf s(agecont):Sexm te(Month,Age) s(Month):Sexf s(Month):Sexm
1 0.2770806 0.000000000 0.111763696 -0.077845764 0.000000000 0.0007840912
2 0.2770806 0.000000000 0.240016156 -0.049143798 0.000000000 0.0007840912
3 0.2770806 0.000000000 0.034328752 0.046524454 0.000000000 -0.0058871897
4 0.0000000 -0.786533918 0.000000000 -0.067942427 0.021990192 0.0000000000
5 0.0000000 0.074434715 0.000000000 0.046524454 0.021990192 0.0000000000
6 0.0000000 0.161121563 0.000000000 0.089599601 0.021990192 0.0000000000
7 0.0000000 0.074434715 0.000000000 0.046524454 0.021990192 0.0000000000
8 0.2770806 0.000000000 -0.298597370 -0.007877328 0.000000000 -0.0058871897
...
但我猜这些只是标准化的预测值而不是真实值(真实值应该没有负值!?)。
那么有人知道我必须在代码中修改什么才能获得真正的值(value)吗?任何想法?谢谢!
最佳答案
不太确定我是否理解正确,但 predict(model, type = "terms")
可能是您正在寻找的解决方案。
更新
我不认为这些是标准化的。可能有些系数只是负数。
考虑帮助文件 ?mgcv:::predict.gam
中的示例:
library(mgcv)
n<-200
sig <- 2
dat <- gamSim(1,n=n,scale=sig)
b<-gam(y~s(x0)+s(I(x1^2))+s(x2)+offset(x3),data=dat)
下面的结果表明,这些实际上是用于每个预测变量计算拟合值的贡献(通过计算每个贡献的总和,然后添加截距和偏移量)。
> head(predict(b))
1 2 3 4 5 6
9.263322 2.822200 7.137201 4.902631 14.558401 11.889092
> head(rowSums(predict(b, type = "terms")) + attr(predict(b, type = "terms"), "constant") + dat$x3)
1 2 3 4 5 6
9.263322 2.822200 7.137201 4.902631 14.558401 11.889092
关于r - 如何为 R 中的每个变量提取 GAM {mgcv} 的拟合值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27017133/
我想澄清并在行中使用 :: 表示法来拟合 mgcv::gam。在使用 mgcv::s 模型调用中的符号时,我偶然发现了一件事。具有可重现示例/错误的代码如下所示。 原因可能是因为我在模型公式中使用了这
好吧,当我实际上犯了一个错误时,我就发现了这一点。我想获得mgcv.FAQ的手册页,但是我 忘记做library(mgcv); 错误地放入了?mgcv-faq。 但是,R奇怪地将我定向到doc页面,就
基于样条的 GAM 回归由以下成本函数定义: cost = ||y - S\beta ||^2 + scale * integral(|S''\beta|^2) 其中 S 是由样条定义的设计矩阵。 在
我正在尝试运行一个 GAM 模型,其中使用高斯过程对 X 和 Y 之间的交互进行建模。在 mgcv 中使用默认平滑 (s()) 时,下面的代码工作正常,但我想用张量积 (te( )) 据我了解,te
考虑如下简单的 GAM 拟合: library(mgcv) my.gam 0 && is.null(sm$no.rescale)) { maXX <- norm(sm$X, type = "
考虑如下简单的 GAM 拟合: library(mgcv) my.gam 0 && is.null(sm$no.rescale)) { maXX <- norm(sm$X, type = "
在 R 中,我想用分类变量拟合 gam 模型。我想我可以这样做(cat 是分类变量)。 lm(data = df, formula = y ~ x1*cat + x2 + x3); 但我不能做这样的事
我正在研究一个模型,其中包含多个 RE 和一个变量的样条,因此我尝试使用 gam() .但是,我遇到了内存耗尽限制错误(即使我在具有 128GB 的集群上运行它时也是如此)。即使我只用一个 RE
This thread从几年前开始描述了如何提取用于绘制拟合 Gam 模型平滑分量的数据。它有效,但仅当存在一个平滑变量时。我有不止一个平滑变量,不幸的是我只能从系列的最后一个中提取平滑。下面是一个例
使用 mgcv 的惩罚样条,我希望在示例数据中获得 10/年的有效自由度 (EDF)(整个周期为 60)。 library(mgcv) library(dlnm) df = '1995-01-01')
我想在 mgcv 包中使用函数 gam: x 结的位置 对于惩罚回归样条线,确切的位置并不重要,只要: k 足够大; 结的分布具有良好、合理的覆盖范围。 默认情况下: 自然三次回归样条bs = '
为什么 mgcv::gam.vcomp 显示与 mgcv::ti 进行的交互的两个方差分量? 我似乎无法在任何地方找到解释或字里行间的解释。方差是否可能归因于交互中的每个组件? require(mgc
我正在制作一个函数,它将对回归函数的未评估调用作为输入,创建一些数据,然后评估调用。这是一个例子: library(lme4) compute_fit Loading required packag
我使用 gam 对时间序列数据的季节性建模取得了巨大成功。除了季节性变化之外,我的最新模型清楚地显示了每周模式。虽然每周模式本身在一年中非常稳定,但其幅度也随季节变化。所以理想情况下,我想将我的数据建
有谁知道如何在 R 中使用 Tweedie 进行逐步回归? 我找到了 mgcv 包,它显然将 Tweedie 的功率参数视为另一个要估计的参数。这似乎改进了必须使用 tweedie.profile 来
在 R 中分离包并不是一个好的做法(请参阅?detach),但由于某些原因,我必须在包 gam 和mgcv。一旦 mgcv 被附加和分离(并且卸载命名空间中的所有依赖项!),gam 的函数会产生一些奇
我正在使用 GAM 对逻辑回归中的时间趋势进行建模。然而,我想从中提取拟合样条线以将其添加到另一个无法在 GAM 或 GAMM 中拟合的模型中。 因此我有两个问题: 我怎样才能随着时间的推移拟合更平滑
我使用 R 版本 2.15.1 (2012-06-22) 和 mgcv 版本 1.7-22 我在 R 中加载以下一组包: library(sqldf) library(timeDate) librar
如果答案很明显,我深表歉意,但我花了很多时间尝试在 mgcv.gam 中使用自定义链接功能 简而言之, 我想使用包 psyphy 中经过修改的 probit 链接(我想用psyphy.probit_2
我想使用 R.NET 链接到 IronPython 中的 R 统计包图书馆。它一直工作正常,但现在我需要使用 R 的 mgcv图书馆。 进口mgcv失败(导入使用命令 rdn.r.EagerEvalu
我是一名优秀的程序员,十分优秀!