Lapply to pull ADF test results on R

Asked

Viewed 48 times

3

This is my list:

mylist=dput(mylist)
list(list(c(30, 50, 35, 25, 45), c(40, 35, 35, 50, 45), c(40, 
20, 40, 50, 25), c(35, 45, 45, 45, 40), c(20, 30, 50, 45, 20), 
    c(40, 40, 50, 30, 40)), list(c(50, 50, 25, 40, 45, 40, 35, 
40, 45, 20), c(40, 35, 40, 40, 45, 30, 20, 50, 35, 25), c(20, 
30, 50, 35, 45, 40, 25, 50, 35, 50), c(20, 35, 30, 25, 40, 30, 
50, 20, 25, 35), c(40, 25, 25, 20, 50, 30, 50, 40, 35, 35), c(50, 
20, 45, 35, 50, 45, 30, 45, 35, 50)), list(c(45, 50, 25, 25, 
30, 25, 35, 35, 35, 30, 50, 50, 30, 30, 20), c(40, 20, 35, 35, 
50, 20, 25, 30, 35, 20, 40, 20, 45, 30, 20), c(50, 20, 25, 35, 
35, 30, 50, 25, 40, 35, 45, 45, 35, 45, 25), c(50, 50, 25, 35, 
25, 35, 20, 25, 45, 40, 35, 40, 50, 40, 30), c(50, 25, 20, 30, 
40, 45, 40, 50, 35, 40, 30, 45, 35, 50, 40), c(35, 50, 35, 45, 
25, 40, 50, 40, 50, 50, 50, 50, 35, 35, 40)), list(c(50, 50, 
50, 40, 20, 25, 50, 40, 50, 50, 45, 40, 30, 50, 35, 45, 50, 30, 
35, 45), c(45, 20, 25, 20, 25, 30, 20, 30, 45, 25, 50, 30, 30, 
25, 50, 45, 20, 45, 45, 50), c(20, 40, 50, 25, 40, 45, 25, 30, 
20, 20, 35, 45, 20, 40, 50, 45, 40, 40, 45, 35), c(40, 40, 20, 
25, 50, 50, 35, 45, 50, 45, 50, 35, 30, 40, 35, 45, 25, 45, 45, 
25), c(20, 25, 35, 45, 35, 40, 40, 35, 35, 40, 30, 30, 40, 50, 
25, 40, 30, 25, 20, 40)), list(c(35, 25, 45, 20, 25, 30, 30, 
35, 30, 40, 30, 20, 20, 30, 45, 40, 35, 35, 35, 35, 25, 45, 35, 
20, 50), c(50, 35, 30, 30, 35, 45, 45, 50, 25, 25, 40, 25, 50, 
45, 25, 30, 30, 25, 45, 45, 30, 20, 50, 30, 30), c(35, 40, 50, 
25, 40, 45, 30, 25, 50, 25, 35, 50, 50, 50, 25, 50, 20, 50, 40, 
25, 25, 35, 20, 20, 50), c(40, 35, 35, 40, 50, 35, 25, 40, 25, 
25, 30, 45, 50, 35, 20, 50, 20, 20, 45, 50, 40, 30, 35, 50, 45
), c(40, 25, 50, 50, 20, 50, 25, 50, 40, 30, 30, 50, 45, 45, 
40, 45, 20, 20, 45, 35, 45, 50, 40, 40, 35), c(40, 45, 35, 35, 
30, 45, 40, 40, 20, 50, 50, 45, 40, 40, 45, 45, 35, 40, 20, 30, 
35, 45, 30, 50, 25)))

this list has 5 entries. In each of these 5 entries I have 6 more entries. In my work each of the 5 entries represents samples of 5,10, 15, 20 and 25 observations.

In each of the positions mylist[[1]][[1]],mylist[[1]][[2]],mylist[[3]][[1]],mylist[[1]][[4]],mylist[[1]][[5]],mylist[[1]][[6]] (Until the mylist[[5]][[6]]) i want to calculate a statistical result which is the ADF test and catch the Pvalue.

I can do this +- for a simple media:

resultlist <- lapply(mylist, 
            function(x) 
            lapply(x, function(y) rep(mean(y), length(y)))
            )

I say +- pq if you notice the media response comes repeated, only one value should come.

How do I correct that?

Similarly, I want to do the adf test and remove the Pvalue, and take only one value, not that repeated value.

Below the code including the adf test. It is not coming out. Any help?

 resultlist <- lapply(mylist, 
                function(x) 
                lapply(x, function(y) rep(adf.test(mylist)$p.value(y), length(y)))
                )

Well, and the main thing is, I need to maintain this Lapply structure. My code is all in Lapply.

Some help?

1 answer

4


First question: means come repeated because you repeat this value with the function rep(). Taking this function will return only one value per list:

resultlist <- lapply(mylist,
              function(x)
              lapply(x, function(y) mean(y))
              )

Second question: the result of adf.test() is a list of 3 types of tests (type1, type2, type3). And each element of the list is one matrix. To get then only p.value you need to first select the type (I chose the arbritária form) and then the p.value position in Matrix ([1, 3]):

resultlist <- lapply(mylist,
              function(x)
              lapply(x, function(y) aTSA::adf.test(y)$type1[1, 3])
              )
  • 1

    Thank you very much. So to access the waste of a regression I can use only the sumary(x)$residuals commando?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.