简体   繁体   中英

How do I compare the relative frequencies in R?

I ran a study asking participants to choose between options A, B, and C based on various parameters.

For example: Which of the following did you find to be most inspirational?

My data looks something like this:

ID Inspiration
1 A
2 C
3 B
4 C
5 B
6 C
7 B
8 C
9 A
10 B
11 A
12 B

I have calculated the relative frequencies so my data now looks like this:

ID Inspiration Proportion
1 A .25
2 C .33
3 B .42
4 C .33
5 B .42
6 C .33
7 B .42
8 C .33
9 A .25
10 B .42
11 A .25
12 B .42

My question is: how do I test to see if the relative frequency of each choice is significantly different from one another? That is, how do I know if the frequency of which people chose Option A is significantly different from the frequency of which they chose either B or C?

I have tried running t-tests, anovas, chi-squared tests, and two-proportion z-tests, but none of these options seem to be exactly what I'm looking for.

First use dput() to provide your data:

dta <- structure(list(ID = 1:12, Inspiration = c("A", "C", "B", "C", 
"B", "C", "B", "C", "A", "B", "A", "B")), class = "data.frame", row.names = c(NA, -12L))

Now construct a table of the relative frequencies:

tbl <- table(dta$Inspiration)
tbl 
# A B C 
# 3 5 4 

Now the null hypothesis that each choice is selected equally (ie frequency of A == B == C):

chisq.test(tbl)
# 
#   Chi-squared test for given probabilities
# 
# data:  tbl
# X-squared = 0.5, df = 2, p-value = 0.7788
# 
# Warning message:
# In chisq.test(tbl) : Chi-squared approximation may be incorrect

No significant difference between the categories.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM