Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract numeric value from ACF in R

Tags:

r

This is what I am trying to do:

x <- c(1,2,3,3,2,3,4,5,6)

my_acf = acf(x,plot=F)


> my_acf

Autocorrelations of series ‘x’, by lag

     0      1      2      3      4      5      6      7      8 
 1.000  0.497  0.097 -0.047 -0.050 -0.075 -0.231 -0.376 -0.316 

I want to extract only 0.497, the correlation coefficient on the first lag, and I want to have it as a numeric value. How can I do that?

Thank You

like image 783
Akavall Avatar asked Feb 25 '12 02:02

Akavall


2 Answers

The answer is to use my_acf$acf[2]. Here is what lead me to the solution:

> attributes(my_acf)
$names
[1] "acf"    "type"   "n.used" "lag"    "series" "snames"

$class
[1] "acf"

> my_acf$acf
, , 1

             [,1]
 [1,]  1.00000000
 [2,]  0.49747475
 [3,]  0.09722222
 [4,] -0.04734848
 [5,] -0.04987374
 [6,] -0.07512626
 [7,] -0.23106061
 [8,] -0.37563131
 [9,] -0.31565657

> my_acf$acf[2]
[1] 0.4974747
like image 183
flodel Avatar answered Oct 04 '22 17:10

flodel


You can try like this

my_acf$acf
like image 43
MYaseen208 Avatar answered Oct 04 '22 16:10

MYaseen208