在线性建模中,很容易写:
linear1 <- lm(mpg ~ ., data = mtcars)
无需写出所有列名称。然而,我无法找到(也无法弄清楚)时间序列中的任何类似内容。例如,这会失败:
library(fpp3)
head(us_change)
linear1 <- us_change %>%
fabletools::model(TSLM(Consumption ~ .,)) %>%
report()
Error in TSLM(Consumption ~ ., ) : unused argument (alist())
但这工作正常(写出所有列名称):
us_change %>%
fabletools::model(TSLM(Consumption ~ Income + Production + Savings + Unemployment)) %>%
report()
数据如下:
编写时间序列模型时是否有列名称的简写,类似于编写线性模型?
我忘记了我之前问过基本相同的问题。在这里得到了回答:多变量时间序列 - 是否有符号来选择所有变量,或者它们都必须写出来?
作为当前数据集的一个很好的例子:
resp <- "Consumption"
form <- reformulate(response = resp,
c(setdiff(names(us_change), resp),
"season()", "trend()"))
us_change %>%
fabletools::model(TSLM(form)) %>%
report()
返回此结果(这是所需的结果):
Series: Consumption
Model: TSLM
Residuals:
Min 1Q Median 3Q Max
-0.90648 -0.14780 -0.01299 0.13156 1.04526
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -2.756442 7.231263 -0.381 0.7035
Quarter -0.034715 0.079097 -0.439 0.6612
Income 0.730331 0.040179 18.177 <2e-16 ***
Production 0.037230 0.023936 1.555 0.1215
Savings -0.052284 0.002947 -17.743 <2e-16 ***
Unemployment -0.226441 0.100480 -2.254 0.0254 *
season()year2 -0.119831 0.104683 -1.145 0.2538
season()year3 -0.095053 0.125207 -0.759 0.4487
season()year4 -0.122601 0.082581 -1.485 0.1393
trend() 3.168947 7.222511 0.439 0.6613
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.3068 on 188 degrees of freedom
Multiple R-squared: 0.7793, Adjusted R-squared: 0.7687
F-statistic: 73.75 on 9 and 188 DF, p-value: < 2.22e-16
>