r - How to extract a parameter from a list of functions in a loop -


i have large data set , want perform several functions @ once , extract each parameter.

the test dataset:

testdf <- data.frame(vy = rnorm(60), vx = rnorm(60) , gvar = rep(c("a","b"), each=30)) 

i first definded list of functions:

require(fbasics) normfuns <- list(jarqueberatest=jarqueberatest, shapirotest=shapirotest, lillietest=lillietest) 

then function perform tests grouping variable

mynormtest <- function(d) {   norm_test <- res_reg <- list()   (i in c("a","b")){     res_reg[[i]] <- residuals(lm(vy~vx, data=d[d$gvar==i,]))     norm_test[[i]] <- lapply(normfuns, function(f) f(res_reg[[i]]))     }   return(norm_test)  }  mynormtest(testdf) 

i obtain list of test summaries each grouping variable. however, interested in getting parameter "statistic" , did not manage find out how extract it.

you can obtain value stored "statistic" in output of various tests with

res_list <- mynormtest(testdf) res_list$a$shapirotest@test@statistic res_list$a$jarqueberatest@test@statistic res_list$a$lillietest@test@statistic 

and correspondingly set b:

res_list$b$shapirotest@test$statistic res_list$b$jarqueberatest@test$statistic res_listb$lillietest@test$statistic 

hope helps.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -