'Chi -Square test in R using dplyr
I would like to perform a chi-square test in R using dpylr. Specifically, I would like to investigate whether there is a difference in customer churn between male and female customers. Here a short example of my data.
sex churn
<fct> <lgl>
1 W FALSE
2 W FALSE
3 W FALSE
4 W FALSE
5 W FALSE
6 W FALSE
7 W FALSE
8 W FALSE
9 W FALSE
10 W FALSE
11 W FALSE
12 W FALSE
13 M FALSE
14 W FALSE
15 W FALSE
16 W FALSE
17 W FALSE
18 M FALSE
19 W FALSE
20 W TRUE
21 W TRUE
22 M FALSE
23 M FALSE
24 W TRUE
25 W FALSE
With the summarise and spread function I already get a nice summary table.
churn_latest %>%
group_by(sex, churn) %>%
summarise(n = n()) %>%
spread(key = sex, value = n)
Now I would like to apply a chi-square test to it, but I always get the following error: 'x' and 'y' must have at least 2 levels. This is of course the case for me, so I must have an error in the syntax.
churn_latest %>%
group_by(sex, churn) %>%
summarise(chi = chisq.test(sex, churn))
I would be very happy if someone had a solution to my problem. Many thanks in advance!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
