This repository has been archived by the owner on Dec 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Basic.R
71 lines (56 loc) · 2.5 KB
/
Basic.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
rm(list=ls())
options("scipen"=999, "digits"=4)
# import, check classes (already manually find/replaced -- for NA in excel prior to this import)
d.in <- read.csv("C:\\Users\\Josh Gaunt\\Documents\\R\\Germany Workflows SSI Survey-Cleaned\\Germany Workflows SSI Survey-Cleaned - 20160203142449-SurveyExport cleaned.csv", stringsAsFactors = FALSE)
lapply(d.in, 'class')
summary(d.in)
# drop fluff from task response names
t.names <- names(d.in[,1:27])
t.names <- gsub(".Did.you.do.you.do.the.following.on.the.Internet.in.the.last.week.", "", t.names, perl = TRUE)
t.names <- append(t.names, c('GOOD_EVERYDAY', 'NO_WEB_TOMORR', 'PRIVACY', 'NO_DO_WEB', 'START_YEAR',
'BRWSR_MAIN', 'BRWSR_MAINo', 'BRWSR_OTHER', 'BRWSR_OTHERo', 'BRWSR_MOBILE_MAIN', 'BRWSR_MOBILE_MAINo', 'BRWSR_MOBILE_OTHER', 'BRWSR_MOBILE_OTHERo',
'GENDER', 'AGE', 'COMM', 'INCOME', 'EDU'))
names(d.in) <- t.names
# rename nonFF browsers to Other to collapse data
d.in[d.in$BRWSR_MAIN!='Mozilla Firefox',33] <- 'Other'
# manually set datatypes (sigh)
for(i in 1:27) {d.in[,i] <- as.integer(d.in[,i])}
for(i in 28:45) {d.in[,i] <- factor(d.in[,i])}
# wound up using same approach for most problems
f.SurveyTaskByV <- function(V) {
d.final <- data.frame()
# run ChiSq on table of 1/0 responses by task, expanded over the column passed as arg
for(i in 2:27) {
result <- chisq.test(table(d.in[,V], d.in[,i]))
d.final <- rbind(d.final, cbind(i, ChiSq= result$statistic, p= result$p.value))
}
# copy to clipboard to paste into excel, quick/dirty
write.table(d.final, 'clipboard', sep = "\t")
}
### BROWSER VS. TASKS
f.SurveyTaskByV(33)
### PRIVACY VS. TASKS
f.SurveyTaskByV(30)
### DEMOS VS. TASK (GENDER)
f.SurveyTaskByV(41)
### DEMOS VS. TASK (AGE)
f.SurveyTaskByV(42)
### DEMOS VS. TASK (COMMUNITY)
f.SurveyTaskByV(43)
### DEMOS VS. TASK (INCOME)
f.SurveyTaskByV(44)
### DEMOS VS. TASK (EDU)
f.SurveyTaskByV(45)
### BROWSER VS. AGE (to clipboard)
write.table(table(d.in[,42], d.in[,33]), 'clipboard', sep = "\t")
# write function again to output standardized residuals
f.SurveyTaskByV <- function(V) {
d.final <- data.frame()
# run ChiSq on table of 1/0 responses by task, expanded over the column passed as arg
for(i in 2:27) {
result <- chisq.test(table(d.in[,V], d.in[,i]))
d.final <- rbind(d.final, cbind(i, ChiSq= result$statistic, p= result$p.value, resid= result$stdres))
}
# copy to clipboard to paste into excel, quick/dirty
write.table(d.final, 'clipboard', sep = "\t")
}