[英]ARIMA model with nonlinear exogenous variable in R
I'm doing a non-linear regression in R and want to add one moving-average term to my model to eliminate the autocorrelations in residuals. 我正在R中进行非线性回归,并想在模型中添加一个移动平均项以消除残差的自相关。
Basically, here is the model: 基本上,这是模型:
y[n] = a + log((x1[n])^g + (x2[n])^g) + c*e[n-1] + e[n]
where [e]
is the moving average term. 其中[e]
是移动平均项。
I plan to use ARIMA(0, 0, 1)
to model residuals. 我计划使用ARIMA(0, 0, 1)
对残差建模。 However, I do not know which function I should use in R to add non-linear exogenous part to ARIMA model. 但是,我不知道我应该在R中使用哪个函数将非线性外生部分添加到ARIMA模型中。
More information: I know how to use nls
command to estimate a
and g
, but do not know how to deal with e[n]
. 更多信息:我知道如何使用nls
命令来估计a
和g
,但是不知道如何处理e[n]
。
I know that xreg
in arima
can handle ARIMA model with linear exogenous variables. 我知道xreg
中的arima
可以处理带有线性外生变量的ARIMA模型。 Is there a similar function to handle ARIMA model with nonlinear exogenous variables? 是否有类似的函数来处理带有非线性外生变量的ARIMA模型?
Thank you for the help in advance! 预先感谢您的帮助!
nlme
has such capability, as it is fitting non-linear mixed models. nlme
具有这种能力,因为它适合非线性混合模型。 You can think of it an extension to nls
(a fixed-effect only non-linear regression), by allowing random effect and correlated errors. 通过允许随机效应和相关误差,您可以认为它是nls
的扩展(仅固定效应非线性回归)。
nlme
can handle ARMA correlation, by something like correlation = corARMA(0.2, ~ 1, p = 0, q = 1, fixed = TRUE)
. nlme
可以通过诸如correlation = corARMA(0.2, ~ 1, p = 0, q = 1, fixed = TRUE)
类的东西来处理ARMA相关性。 This means, that residuals are MA(1) process, with initial guess of coefficient 0.2, but to be updated during model fitting. 这意味着,残差是MA(1)过程,初始猜测系数为0.2,但在模型拟合过程中会进行更新。 The ~ 1
suggests that MA(1)
is on intercept and there is no further grouping structure. ~ 1
表示MA(1)
处于截距,没有进一步的分组结构。
I am not an expert in nlme
, but I know nlme
is what you need. 我不是nlme
的专家,但是我知道nlme
是您所需要的。 I produce the following example, but since I am not an expert, I can't get nlme
work at the moment. 我提供了以下示例,但是由于我不是专家,因此目前无法使nlme
工作。 I post it here to give a start / flavour. 我将其发布在此处以开始/添加味道。
set.seed(0)
x1 <- runif(100)
x2 <- runif(100)
## MA(1) correlated error, with innovation standard deviation 0.1
e <- arima.sim(model = list(ma = 0.5), n = 100, sd = 0.1)
## a true model, with `a = 0.2, g = 0.5`
y0 <- 0.2 + log(x1 ^ 0.5 + x2 ^ 0.5)
## observations
y <- y0 + e
## no need to install; it comes with R; just `library()` it
library(nlme)
fit <- nlme(y ~ a + log(x1 ^ g + x2 ^ g), fixed = a + g ~ 1,
start = list(a = 0.5, g = 1),
correlation = corARMA(0.2, form = ~ 1, p = 0, q = 1, fixed = FALSE))
Similar to nls
, we have an overall model formula y ~ a + log(x1 ^ g + x2 ^ g)
, and starting values are required for iteration process. 与nls
相似,我们有一个整体模型公式y ~ a + log(x1 ^ g + x2 ^ g)
,并且迭代过程需要起始值。 I have chosen start = list(a = 0.5, g = 1)
. 我选择了start = list(a = 0.5, g = 1)
。 The correlation
bit has been explained in the beginning. 开头已经说明了correlation
位。
fixed
and random
arguments in nlme
specify what should be seen as fixed effects and random effects in the overall formula. nlme
fixed
和random
参数指定在整个公式中应视为固定效应和随机效应的参数。 Since we have no random effect, we leave it unspecified. 由于我们没有随机效应,因此我们未对其进行指定。 We want a
and g
as fixed effect, so I tried something like fixed = a + g ~ 1
. 我们希望a
和g
为固定效果,所以我尝试了诸如fixed = a + g ~ 1
。 Unfortunately it does not quite work, for some reason I don't know. 不幸的是,由于某些原因,我不知道它不能正常工作。 I read the ?nlme
, and thought this formula means that we want a common a
and g
for all observations, but later nlme
reports an error saying this is not a valid group formula. 我阅读了?nlme
,并认为该公式意味着我们希望所有观察值都具有共同的a
和g
,但是后来nlme
报告了一个错误,指出这不是有效的组公式。
I am also investing at this; 我也在对此进行投资; as I said, the above gives us a start. 正如我所说,以上内容为我们提供了一个起点。 We are already fairly close to the final answer. 我们已经很接近最终答案了。
Thanks to user20650 for point out my awkward error. 感谢user20650指出我的尴尬错误。 I should use gnls
function rather than nlme
. 我应该使用gnls
函数而不是nlme
。 By design nature of nlme
package, functions lme
and nlme
have to take a random
argument to work. 根据nlme
软件包的设计性质,函数lme
和nlme
必须采用random
参数才能起作用。 Luckily, there are several other routines in nlme
package for extending linear models and non-linear models. 幸运的是, nlme
软件包中还有其他一些例程可以扩展线性模型和非线性模型。
gls
and gnls
extend lm
and nls
by allowing non-diagonal variance functions. gls
和gnls
通过允许非对角方差函数gnls
扩展lm
和nls
。 So, I should really use gnls
instead: 因此,我应该真正使用gnls
代替:
## no `fixed` argument as `gnls` is a fixed-effect only
fit <- gnls(y ~ a + log(x1 ^ g + x2 ^ g), start = list(a = 0.5, g = 1),
correlation = corARMA(0.2, form = ~ 1, p = 0, q = 1, fixed = FALSE))
#Generalized nonlinear least squares fit
# Model: y ~ a + log(x1^g + x2^g)
# Data: NULL
# Log-likelihood: 92.44078
#
#Coefficients:
# a g
#0.1915396 0.5007640
#
#Correlation Structure: ARMA(0,1)
# Formula: ~1
# Parameter estimate(s):
# Theta1
#0.4184961
#Degrees of freedom: 100 total; 98 residual
#Residual standard error: 0.1050295
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.