Lapply to remove ADF test results in R

3

Here's 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 mylist[[1]][[1]],mylist[[1]][[2]],mylist[[3]][[1]],mylist[[1]][[4]],mylist[[1]][[5]],mylist[[1]][[6]] (Up to mylist[[5]][[6]] ) positions I want to calculate a statistic result that is the ADF test and get 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 + - because if you notice the response to media comes repeated, it should only come with a value.

How do I fix this?

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

Below the code including the adf test. It's 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, I need to keep this structure of Lapply. My code is all in Lapply.

Any help?

    
asked by anonymous 28.08.2018 / 00:00

1 answer

4

First question : Averages are repeated because you repeat this value with the rep() function. If you remove this function it 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 test types ( type1 , type2 , type3 ). And every element in the list is matrix . To get only the p.value you first need to select the type (which I chose in an arbitrary way) and then the position of the p.value in the matrix ( [1, 3] ):

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