- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在为我的数据集使用 GAM
(广义加性模型)。该数据集有 32 个观测值,具有 6 个预测变量和一个响应变量(即功率)。
我正在使用 gam()
包的 mgcv
函数来拟合模型。每当我尝试拟合模型时,都会收到如下错误消息:
Error in gam(formula.hh, data = data, na.action = na.exclude, :
Model has more coefficients than data
library(mgcv)
formula.hh <- as.formula(power ~ s(temperature)
+ s(prevday1) + s(prevday2)
+ s(prev_2_hour) + s(prev_instant1))
model <- gam(formula.hh, data = data, na.action = na.exclude)
dput()
函数附加数据
> dput(data)
data <- structure(list(power = c(250.615931666667, 252.675878333333,
1578.209605, 186.636575166667, 1062.07912666667, 1031.481235,
1584.38902166667, 276.973836666667, 401.620463333333, 1622.50827666667,
273.825153333333, 1511.37474333333, 291.460865, 215.138178333333,
247.509348333333, 1140.21383833333, 1680.63441666667, 1742.44168333333,
592.162706166667, 1610.7307, 615.857495, 1664.13551, 464.973065,
1956.2482, 1767.94469333333, 1869.02678333333, 1806.731, 1746.3731,
549.216605, 1425.42390166667, 1900.32575, 1766.18103333333),
temperature = c(31, 30, 28, 28, 27, 31, 32, 32, 30.5, 33,
33, 30, 32, 24, 30, 26, 28, 32, 34, 25, 32, 33, 35, 36, 36,
37, 35, 33, 35, 33, 35, 32), prevday1 = c(NA, 250.615931666667,
252.675878333333, 1578.209605, 186.636575166667, 1062.07912666667,
1031.481235, 1584.38902166667, 276.973836666667, 401.620463333333,
1622.50827666667, 273.825153333333, 1511.37474333333, 291.460865,
215.138178333333, 247.509348333333, 1140.21383833333, 1680.63441666667,
1742.44168333333, 592.162706166667, 1610.7307, 615.857495,
1664.13551, 464.973065, 1956.2482, 1767.94469333333, 1869.02678333333,
1806.731, 1746.3731, 549.216605, 1425.42390166667, 1900.32575
), prevday2 = c(NA, NA, 250.615931666667, 252.675878333333,
1578.209605, 186.636575166667, 1062.07912666667, 1031.481235,
1584.38902166667, 276.973836666667, 401.620463333333, 1622.50827666667,
273.825153333333, 1511.37474333333, 291.460865, 215.138178333333,
247.509348333333, 1140.21383833333, 1680.63441666667, 1742.44168333333,
592.162706166667, 1610.7307, 615.857495, 1664.13551, 464.973065,
1956.2482, 1767.94469333333, 1869.02678333333, 1806.731,
1746.3731, 549.216605, 1425.42390166667), prev_instant1 = c(NA,
237.211388333333, 455.932271666667, 367.837349666667, 1230.40137333333,
1080.74080166667, 1898.06056666667, 326.103031666667, 302.770571666667,
1859.65283333333, 281.700161666667, 1684.32288333333, 291.448878333333,
214.838578333333, 254.042623333333, 1380.14074333333, 824.437228333333,
1660.46284666667, 268.004111666667, 1715.02763333333, 1853.08503333333,
1821.31845, 1173.91945333333, 1859.87353333333, 1887.67635,
1760.29563333333, 1876.05421666667, 1743.10665, 366.382048333333,
1185.16379, 1713.98534666667, 1746.36006666667), prev_instant2 = c(NA,
275.55167, 242.638122833333, 220.635857, 1784.77271666667,
1195.45020333333, 590.114391666667, 310.141536666667, 1397.3184605,
1747.44398333333, 260.10318, 1521.77355833333, 283.317726666667,
206.678135, 231.428693833333, 235.600631666667, 232.455201666667,
281.422625, 256.470893333333, 1613.82088333333, 1564.34841666667,
1795.03498333333, 1551.64725666667, 1517.69289833333, 1596.66556166667,
2767.82433333333, 2949.38005, 328.691775, 389.83789, 1805.71815333333,
1153.97645666667, 1752.75968333333), prev_2_hour = c(NA,
219.024983, 313.393630708333, 263.748829166667, 931.193606666667,
699.399163791667, 754.018962083334, 272.22309625, 595.954508875,
1597.21487208333, 512.64361, 1236.42579666667, 281.200373333334,
196.983981666666, 230.327737625, 525.483920416666, 391.120302791667,
610.101280416667, 247.710625543785, 978.741044166665, 979.658926666667,
1189.25306041667, 814.840889166667, 989.059700416665, 1352.2367025,
1770.20417833333, 1847.11590666667, 843.191556416666, 363.50806625,
904.924465041666, 841.746712500002, 1747.73452958333)), .Names = c("power",
"temperature", "prevday1", "prevday2", "prev_instant1", "prev_instant2",
"prev_2_hour"), class = "data.frame", row.names = c(NA, 32L))
最佳答案
This dataset has 32 observations.
NA
。
From this error message, I infer that I have more predictor variables as compared to the number of observations.
s()
选择基础维度(或等级)为 10 以实现 1D 平滑,给出 10 个原始参数。在居中约束(参见
?identifiability
)之后,您得到的参数少了一个,但每个平滑仍然有 9 个参数。请注意,您有 5 个平滑!所以你有 45 个平滑项的参数,加上一个截距。这大于您的 30 个数据。
I guess this error is generated during cross-validation procedures.
n
(数据数量)和什么是
p
(参数数量)。
Is there any way to handle this error?
k
而不是使用默认值。但是对于三次样条,最小
k
是 3。例如,使用
s(temperature, bs = 'cr', k = 3)
。注意我还将
bs = 'cr'
设置为使用自然三次样条,而不是薄板回归样条的默认
bs = 'tp'
。你当然可以使用它,但对于一维平滑
"cr"
是一个自然的选择。
关于r - mgcv gam() 错误 : model has more coefficients than data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36719799/
我想澄清并在行中使用 :: 表示法来拟合 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
我是一名优秀的程序员,十分优秀!