[R] Naive Q re applying AR(p) models to matrix data

Achim Zeileis zeileis at ci.tuwien.ac.at
Tue Oct 14 19:21:39 CEST 2003


On Tuesday 14 October 2003 17:41, Laura Quinn wrote:

> As a total beginner still, I am having great difficulty trying to
> apply ar models to column data in a matrix.
>
> As each matrix has 20 columns (and some of these contain NA data) it
> is obviously a long, slow process to calculate ar models for each
> column individually, though I am (probably extremely stupidly)
> struggling to see how I am doing this wrong.
>
> I have tried using:
>
> for (i in 1:20)
> apply(mydata,c(,i),ar(mydata[!is.na(mydata)],order.max=3))
>
> and
>
> apply(mydata,ar(mydata[!is.na(mydata)],order.max=3))
>
> and
>
> apply(mydata,c(,1:20),ar(mydata[,1:20][!is.na(mydata[,1:20])],order.
>max=3))
>
> and none of these work - can someone tell me what I am doing wrong??

Try

   apply(mydata, 2, function(x) ar(x[!is.na(x)]))

and then look at

  help(apply)

to understand what you have done wrong.

hth,
Z

> Thank you in advance, and excuse me for my stupidity..
> Laura
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help




More information about the R-help mailing list