r - Using dplyr to compare models -


working through examples in dplyr documentation of do() function , until came across snippet summarize model comparisons: # compare %>% summarise(p.value = aov$`pr(>f)`) error "error: expecting single value". found way forward accessing list of aov elements directly. question sub-setting operators , ask if there better way this. here full attempt , solution.

     models <- group_by(mtcars,cyl) %>% do(mod_lin = lm(mpg ~ disp, data = .), mod_quad = lm(mpg ~ poly(disp,2), data = .))     compare <- models %>% do(aov = anova(.$mod_lin, .$mod_quad))     compare %>% summarise(p.value = aov$'pr(>f)')     error: expecting single value 

looking structure of compare

     select comparison 1     compare$aov[[1]]     select comparison 1 , of element 6 (the pvalues)      compare$aov[[1]][6]     pvalues     compare$aov[[1]][2,6]     compare %>% summarise(pvalue = aov[2,6]) # gets pvalues group 

suppose i'm wondering how object of classes (‘rowwise_df’, ‘tbl_df’ , 'data.frame') summarise can intuit [[]] operator. , if there might better way this.

you try

 compare %>% do(.$aov['pr(>f)']) %>% na.omit() 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -