1

I want to run a customized function based on ARIMA model. The function calls the ma3 coefficient from ARIMA (2, 0, 3) model ran on daily data of a year and subtracts ma3 coefficient from 2, for every firm. I have 5 years daily data for five firms, so each firm should have 5 year-wise values. My code:

>Stressy =function(x) 2-summary(arima(x, order=c(2,0,3)))$coefficients[1, "ma3"] 
>Funny = aggregate(cbind(QQ) ~  Year + Firm , df, FUN = Stressy)

Running my code gives the following error:

Error in summary(arima(x, order = c(2, 0, 3)))$coefficients : $ operator is invalid for atomic vectors 

I know the result can be estimated manually but my data set is large enough to be confusing when handled manually. Please suggest an edit to fix this.

4

1 回答 1

2

有两种方法可以获得 ma3 系数:

Stressy <- function(x) 2-coef(arima(x, order=c(2,0,3)))["ma3"] 

或者

Stressy <- function(x) 2-arima(x, order=c(2,0,3))$coef["ma3"] 

您原来的自定义函数不起作用,因为summary(arima_object)给了您一个表格,您不能在该表格上应用$运算符:

x <- arima(df, c(2,0,3))
class(summary(x))
[1] "summaryDefault" "table"
于 2016-03-08T10:03:59.313 回答