问题标签 [mgcv]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
237 浏览

r - How to solve compatibility problems mgcv ang gam packages?

I'm compiling using RMarkdown and knitr a short protocol for me (in one html file), about modelling. The basis is Zuur, A. F. "leno, E. N, Walker, NJ, Saveliev, AA & Smith, G M. 2009: Mixed effects models and extensions in ecology with R."

I downloaded the code and the datasets shared in their website1 and I'm mixing it with other sources and comments to produce something useful for me. In this website you can freely download the two dataset I'm using.

The main problem is that I'm trying to mix something made with mgcv package and something with gam package.

I clearly understood from this two topics that this is the problem:

R Package conflict between gam and mgcv?
Are there known compatibility issues with R package mgcv? Are there general rules for compatibility?

But I would like to find a solution. Obviously as answered in theese two topics specify the package or detach the unused one does not work. I just tried in my code.

Those are the parts that are causing me problems:



Does anyone knows a way to "detach" completely mgcv or gam? Or a code that can "reaload" the entire environment when I have to compile the gam part?

My sessionInfo if it is useful.

0 投票
1 回答
1053 浏览

r - 来自 gamm 模型错误的随机效应预测:无法在“newdata”上评估组的期望水平

我正在尝试使用参数从gamm模型(来自mgcv包)生成预测。newdata我想对lme模型的一部分进行预测,以便预测包括随机效应。但是,我认为,由于模型系数的命名方式,我遇到了问题。

我的问题是,应该如何newdata构造/命名论点以允许预测。谢谢。

阿米韦

产生错误

predict.lme(mod$lme, newdata = d) 中的错误:无法评估“newdata”上所需级别的组


如果我在nlme没有样条项的情况下运行模型,则newdata执行没有问题


信息:我没有将随机效果指定为样条曲线 (s(. , bs="re")),因为我的 RE 比上面的示例更复杂。

0 投票
1 回答
6248 浏览

r - mgcv gam() 错误:模型的系数多于数据

我正在GAM为我的数据集使用(广义相加模型)。该数据集有 32 个观测值,有 6 个预测变量和一个响应变量(即功率)。我正在使用包的gam()功能mgcv来适应模型。每当我尝试拟合模型时,我都会收到一条错误消息:

从这个错误消息中,我推断与观察数相比,我有更多的预测变量。我猜这个错误是在交叉验证过程中产生的。有没有办法处理这个错误?

我为此使用以下代码,

在这里,我用dput()函数附加数据

0 投票
1 回答
2767 浏览

r - mgcv:如何使用 Tweedie 响应模型进行逐步回归?

有谁知道如何在 R 中使用 Tweedie 进行逐步回归?

我找到了这个mgcv包,它显然将 Tweedie 的功率参数视为另一个要估计的参数。这似乎比必须使用tweedie.profile估计 之外的功率有所改进glm,因此使用自动逐步函数进行回归似乎令人鼓舞。但我无法弄清楚该软件包是否还提供逐步功能。包装手册有这样的说法。

我在谈论平滑时迷失了方向:

包 mgcv 中没有 step.gam。
为了促进全自动模型选择,该包实现了两种平滑修改技术,可用于将平滑缩小到零作为平滑选择的一部分。

我会很感激你的帮助。谢谢。

0 投票
1 回答
8322 浏览

r - Extract knots, basis, coefficients and predictions for P-splines in adaptive smooth

I'm using the mgcv package to fit some polynomial splines to some data via:

I'm trying to extract the functional form of the fit. x.gam is a gamObject, and I've been reading the documentation but haven't found enough information in order to manually reconstruct the fitted function.

  • x.gam$smooth contains information about whether the knots have been placed;
  • x.gam$coefficients gives the spline coefficients, but I don't know what order polynomial splines are used and looking in the code has not revealed anything.

Is there a neat way to extract the knots, coefficients and basis used so that one can manually reconstruct the fit?

0 投票
1 回答
1839 浏览

r - mgcv:从 GAM 模型中提取“tp”平滑的结位置

我试图从 GAM 模型中提取结的位置,以便将我的预测变量描述为另一个模型的类别。我的数据包含一个二元响应变量(使用)和一个连续预测变量(打开)。

我适合这样的GAM:

我可以在函数中获得预测值和模型矩阵等,type=c("response", "lpmatrix")predict.gam我正在努力提取系数变化的节点位置。任何建议都非常感谢!

如果可能的话,我也会有兴趣做类似的事情:

http://www.fromthebottomoftheheap.net/2014/05/15/identifying-periods-of-change-with-gams/

在其中识别了样条的统计增加/减少,但是,我此时没有使用 GAMM,因此在识别从他的 GAMM 模型中提取的 GAM 中的相似模型特征时遇到问题。第二个项目更多的是出于好奇。

0 投票
1 回答
1677 浏览

r - 如何更改 MGCV GAM 因子图上的 y 轴?

我想调整 GAM 平滑函数和因子图的 y 限制,以便更轻松地比较两种不同 GAM 模型对不同季节的影响。在函数中使用ylim选项时plot.gam,我只能更改平滑函数的 y 轴,但不能更改因子。

例如:

在第二个图中,只有平滑变化的 y 限制,而不是因子。这是怎么回事,我该如何解决?

0 投票
0 回答
985 浏览

r - predict.gam 模型中的 r mgcv 错误

我的测试数据和我的微调数据具有不同的因素水平。我尝试合并级别,但它不起作用。

然后 R 给了我这个错误: predict.gam(model, newdata = testData) 中的错误:1001, 1213,1231 not in original fit Calls: predict -> predict.gam

0 投票
1 回答
1750 浏览

r - 广义加法模型 data.frame.default 错误:尝试应用非功能

我正在尝试使用 mgcv 包运行一般附加模型,但我不断收到 model.frame.default 错误:

这是我正在使用的代码(由于数据集的大小,我使用“bam()”):

这是数据的样子:

我似乎找不到我的公式有任何明显的错误。我已检查以确保没有列长度不匹配的错误,并且我没有看到任何缺少的括号、逗号或 + 号。我将我的代码与一些使用 mgcv 包的同事进行了比较,但我无法找出问题所在。有什么建议么?

感谢您的任何帮助。

0 投票
1 回答
1698 浏览

r - GAM R 方差由变量解释

我目前的问题是用 R 计算由通用加法模型(GAM)的不同变量解释的方差。

我在这里按照伍德给出的解释: https ://stat.ethz.ch/pipermail/r-help/2007-October/142743.html

但我想用三个变量来做。我试过这个:

但我不明白结果。例如,只有 x1 和 x2 的模型的偏差小于具有三个解释变量的偏差。

我用来提取由三个变量解释的变量的方差的方法是否正确?

这是否意味着全局模型中存在混杂效应?还是有其他解释?

非常感谢。