[R] extracting coefficients from ar() output

peter dalgaard pdalgd at gmail.com
Thu Jun 16 19:49:21 CEST 2016


> On 16 Jun 2016, at 17:07 , William Dunlap via R-help <r-help at r-project.org> wrote:
> 
> help(ar) should tell you how to get the coefficients.  If, like me, you
> don't
> read help files, you can use str() to look at the structure of ar's output.

Also notice that the output of rollapply is not an ar object. More likely a list of them, so  try rollingarma[[i]]$ar or maybe lapply(rollingarma, function(x)x$ar) or sapply(rollingarma, "[[", "ar") or...

> 
>> str(a <- ar(sin(1:30), aic=TRUE))
> List of 14
> $ order       : int 2
> $ ar          : num [1:2] 1.011 -0.918
> $ var.pred    : num 0.0654
> $ x.mean      : num 0.00934
> $ aic         : Named num [1:15] 61.215 53.442 0 0.985 2.917 ...
>  ..- attr(*, "names")= chr [1:15] "0" "1" "2" "3" ...
> $ n.used      : int 30
> $ order.max   : num 14
> $ partialacf  : num [1:14, 1, 1] 0.5273 -0.9179 -0.1824 -0.0477 -0.0393 ...
> $ resid       : num [1:30] NA NA -0.0145 -0.0734 -0.0725 ...
> $ method      : chr "Yule-Walker"
> $ series      : chr "sin(1:30)"
> $ frequency   : num 1
> $ call        : language ar(x = sin(1:30), aic = TRUE)
> $ asy.var.coef: num [1:2, 1:2] 0.00583 -0.00308 -0.00308 0.00583
> - attr(*, "class")= chr "ar"
>> a$ar
> [1]  1.0112512 -0.9178554
> 
> 
> 
> 
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
> 
> On Thu, Jun 16, 2016 at 4:34 AM, T.Riedle <tr206 at kent.ac.uk> wrote:
> 
>> Hi everybody,
>> 
>> I am trying to run an AR1 model using the ar() function as shown below.
>> 
>>> rollingarma<-rollapply(data,width=36,function(data) ar(data,aic=TRUE))
>>> head(rollingarma,50)
>>      order ar        var.pred x.mean   aic        n.used order.max
>> partialacf resid      method        series
>> [1,] 1     0.7433347 1.382908 49.99861 Numeric,16 36     15
>> Numeric,15 Numeric,36 "Yule-Walker" "data"
>> [2,] 1     0.7410181 1.565755 49.94778 Numeric,16 36     15
>> Numeric,15 Numeric,36 "Yule-Walker" "data"
>> [3,] 1     0.7636966 1.660581 49.86861 Numeric,16 36     15
>> Numeric,15 Numeric,36 "Yule-Walker" "data"
>> 
>> 
>> I get the table as shown above if I use head().
>> 
>> How can I extract the ar coefficients from this table? I have already
>> tried coef() and rollingarma$ar but both do not work.
>> What can I do?
>> 
>> Thanks for your help.
>> 
>> 
>>        [[alternative HTML version deleted]]
>> 
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list