-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwk2quizchisquare.R
37 lines (26 loc) · 1.1 KB
/
wk2quizchisquare.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
prefs = read.csv("//Users/ritaraher/Documents/Coursera/untitled folder/experiments/deviceprefs.csv")
View(prefs)
prefs$Disability = factor(prefs$Disability) # convert to nominal factor
prefs$Subject = factor(prefs$Subject) # convert to nominal factor
prefs$Subject = factor(prefs$Subject) # convert to nominal factor
summary(prefs)
plot(prefs$Pref)
# Pearson chi-square test
prfs = xtabs( ~ Pref, data=prefs)
prfs # show counts
chisq.test(prfs)
# people without disabilities and a preference for touchpad
binom.test(sum(prefs[prefs$Disability == "0", ]$Pref == "touchpad"),
nrow(prefs[prefs$Disability == "0",]), p=1/2)
# people with disabilities and a preference for touchpad
binom.test(sum(prefs[prefs$Disability == "1", ]$Pref == "touchpad"),
nrow(prefs[prefs$Disability == "1",]), p=1/2)
# Pearson chi-square test of proportions of preferences by disability status
prfs = xtabs( ~ Pref + Disability, data=prefs) # the '+' sign indicates two vars
View(prfs)
chisq.test(prfs)
# G-test, asymptotic like chi-square
library(RVAideMemoire)
G.test(prfs)
# Fisher's exact test
fisher.test(prfs)