Function for Tidy chisq.test Output for Visualizing or Filtering P-Values

雨燕双飞 提交于 2019-12-01 11:39:48

You can do this all within the tidyverse workflow, using map in place of lapply. There's no need for nest unless you're going to be subsetting the data to compare the results in some fashion (e.g an age group)

df <- happy%>%
  select(-id, -year,-age,-wtssall) %>% 
  map(~chisq.test(.x, happy$happy)) %>% 
  tibble(names = names(.), data = .) %>% 
  mutate(stats = map(data, tidy))

unnest(df, stats)

# A tibble: 6 × 6
    names        data   statistic       p.value parameter                     method
    <chr>      <list>       <dbl>         <dbl>     <int>                     <fctr>
1   happy <S3: htest> 92606.00000  0.000000e+00         4 Pearson's Chi-squared test
2     sex <S3: htest>    11.46604  3.237288e-03         2 Pearson's Chi-squared test
3 marital <S3: htest>  2695.18474  0.000000e+00         8 Pearson's Chi-squared test
4  degree <S3: htest>   659.33013 4.057952e-137         8 Pearson's Chi-squared test
5 finrela <S3: htest>  2374.24165  0.000000e+00         8 Pearson's Chi-squared test
6  health <S3: htest>  2928.62829  0.000000e+00         6 Pearson's Chi-squared test
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!