[英]apply chi-square test in R for each level of a categorical variable
I'm having a data frame as below.我有一个如下的数据框。 I want to run a chi-square test between 'placement' and 'books_quantile' variables at each level of zip codes.
我想在 zip 代码的每个级别的 'placement' 和 'books_quantile' 变量之间运行卡方检验。 I've tried a few ways but not successful yet.
我尝试了几种方法,但还没有成功。 Can somebody help?
有人可以帮忙吗?
Thank you!谢谢!
str(zip2)
tibble [10,748 x 3] (S3: tbl_df/tbl/data.frame)
$ placement : Factor w/ 5 levels "3 or More Grade Levels Below",..: 5 3 3 3 5 2 2 5 3 5 ...
$ books_quantile: Factor w/ 4 levels "Q1 (>=56 books)",..: 2 2 2 2 3 3 3 2 1 2 ...
$ zip : Factor w/ 24 levels "38016","38018",..: 11 21 9 8 22 12 15 15 13 12 ...
You should do:你应该做:
apply(xtabs(~placement + books_quantile + zip, zip2), 3, chisq.test)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.