-
Notifications
You must be signed in to change notification settings - Fork 0
/
mesoudi2015_analysis_copyfreq.R
287 lines (175 loc) · 13.5 KB
/
mesoudi2015_analysis_copyfreq.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#summary of findings:
#mainland chinese copy more than other groups in S1 and S2, no differences in S3
library(Hmisc)
library(ggplot2)
library(car)
#load data HKdata.csv into dataframe HKdata-------------------------------
library(foreign, pos=4)
HKdata <- read.csv("HKdata.csv")
#re-order so that UK is ref group
HKdata$culture <- factor(HKdata$culture, levels=c('UK','HK','CI','CM'))
#descriptive stats----------------------------
library(pastecs)
stat.desc(HKdata$season1_copies/29)
stat.desc(HKdata$season2_copies/29)
stat.desc(HKdata$season3_copies/29)
by(HKdata$season1_copies/29, HKdata$culture, stat.desc)
by(HKdata$season2_copies/29, HKdata$culture, stat.desc)
by(HKdata$season3_copies/29, HKdata$culture, stat.desc)
by(HKdata$s1s2_copies/29, HKdata$culture, stat.desc)
#cross cultural comparison of season 1 copy rates-----------------------------------
#now same for S1
#plot data, barchart - indicates higher mean for chinese rural, all others look equal
ggplot(HKdata, aes(culture, season1_copies/29)) + stat_summary(fun = mean, geom = "bar", fill = "White", color = "Black", size = 1) + coord_cartesian(ylim = c(0, 0.42)) + labs(x = "", y = "frequency of copying") + stat_summary(fun.data = mean_cl_boot, geom = "errorbar", width = 0.2, size = 1) + theme(axis.text.x = element_text(family="Times", color = "Black", size = 28), axis.text.y = element_text(family="Times", color = "Black", size = 24), axis.title.y = element_text(family="Times", size = 28, vjust = 1.7), panel.background = element_rect(fill = "white"), axis.line = element_line(size = 1), panel.grid.minor = element_blank(), axis.ticks = element_line(size = 1, color = "black"))
#boxplots might be better, but suggests non-normally distributed vars
plot(season1_copies ~ culture, data = HKdata)
#plot log(season1_copies): suggests brit and HK are identical, chinese immigrant and rural are higher
clog <- function(x) log(x + 0.5)
plot(clog(season1_copies) ~ culture, data = HKdata)
#histograms show data is non-normally distributed, lots of zeroes; confirms brit & HK are similar
ggplot(HKdata, aes(season1_copies), fill = "white", color = "black") + facet_wrap(~ culture) + geom_histogram()
#test for normality indicates it is not normal (sig = not normal)
shapiro.test(HKdata$season1_copies)
#levene's test for homogeneity of variance also indicates no homogeneity (sig = heterogenous var)
leveneTest(HKdata$season1_copies, HKdata$culture, center=median)
#quasibinomial
summary(nullmodelS1bin <- glm(copy_frequency_s1 ~ 1, family = quasibinomial, data = HKdata))
#goodness of fit test is non-sig, indicating good overall fit
with(nullmodelS1bin, cbind(res.deviance = deviance, df = df.residual, p = pchisq(deviance, df.residual, lower.tail = FALSE)))
#add cultural group
summary(culturemodelS1bin <- glm(copy_frequency_s1 ~ culture, family = quasibinomial, data = HKdata))
#goodness of fit test is still non-sig; model fits well
with(culturemodelS1bin, cbind(res.deviance = deviance, df = df.residual, p = pchisq(deviance, df.residual, lower.tail = FALSE)))
#compare null and culture models; sig diff, so fit is improved by culture
anova(nullmodelS1bin, culturemodelS1bin, test = "Chisq")
#do post-hoc tests: indicate that Hk, Brit and immigrant are identical
#mainland sig diff to every other group
library(multcomp)
summary(posthocs <- glht(culturemodelS1bin, linfct = mcp(culture = "Tukey")))
#add sex, age; neither significant
summary(agesexmodelS1bin <- glm(copy_frequency_s1 ~ culture + age + sex, family = quasibinomial, data = HKdata))
#compare agesex and culture-only models; no sig diff so drop age & sex
anova(agesexmodelS1bin, culturemodelS1bin, test = "Chisq")
#culture+sex - sigificant
summary(sexculturemodelS1bin <- glm(copy_frequency_s1 ~ culture + sex, family = quasibinomial, data = HKdata))
anova(sexculturemodelS1bin, culturemodelS1bin, test = "Chisq")
library(multcomp)
summary(posthocs <- glht(sexculturemodelS1bin, linfct = mcp(culture = "Tukey")))
#just age
summary(ageonlymodelS1bin <- glm(copy_frequency_s1 ~ age, family = quasibinomial, data = HKdata))
anova(ageonlymodelS1bin, nullmodelS1bin, test = "Chisq")
#add IND and COL; neither sig
summary(indcolmodelS1bin <- glm(copy_frequency_s1 ~ culture + individualist_reversed + collectivist_reversed, family = quasibinomial, data = HKdata))
#compare ind/col and culture-only models; no sig diff
anova(indcolmodelS1bin, nullmodelS1bin, test = "Chisq")
#culture x sex interaction? No
summary(sexXculturemodelS1bin <- glm(copy_frequency_s1 ~ culture*sex, family = quasibinomial, data = HKdata))
anova(sexXculturemodelS1bin, culturemodelS1bin, test = "Chisq")
#just for interest, the full model; culture still sig but sex also now marginally sig
summary(fullmodelS1bin <- glm(copy_frequency_s1 ~ culture + age + sex + individualist_reversed + collectivist_reversed, family = quasibinomial, data = HKdata))
#although full model is no better fit than culture model, so ignore sig sex in full
anova(fullmodelS1bin, sexculturemodelS1bin, test = "Chisq")
#get confidence intervals
confint(sexculturemodelS1bin)
confint.default(sexculturemodelS1bin)
#conclusion from quasibinomial model for S1: HK, British and immigrant groups are identical, mainland Chinese group copy sig more than others
#specifically, for every copy done by a Brit, Chinese mainlanders copy exp(0.7612)=2.14 times (over twice as likely to copy). Other groups are similarly different.
#cross cultural comparison of season 2 copy rates--------------------------------------
#graphs
#plot data, barchart - indicates higher mean for chinese rural, all others look equal
library(ggplot2)
ggplot(HKdata, aes(culture, copy_frequency_all)) + stat_summary(fun = mean, geom = "bar", fill = "White", color = "Black", size = 1) + coord_cartesian(ylim = c(0, 0.42)) + labs(x = "", y = "frequency of copying") + stat_summary(fun.data = mean_cl_boot, geom = "errorbar", width = 0.2, size = 1) + theme(axis.text.x = element_text(family="Times", color = "Black", size = 28), axis.text.y = element_text(family="Times", color = "Black", size = 24), axis.title.y = element_text(family="Times", size = 28, vjust = 1.7), panel.background = element_rect(fill = "white"), axis.line = element_line(size = 1), panel.grid.minor = element_blank(), axis.ticks = element_line(size = 1, color = "black"))
#boxplots might be better, but suggests non-normally distributed vars
plot(season2_copies ~ culture, data = HKdata)
#plot log(season2_copies): suggests brit and HK are identical, chinese immigrant and rural are higher
clog <- function(x) log(x + 0.5)
plot(clog(season2_copies) ~ culture, data = HKdata)
#histograms show data is non-normally distributed, lots of zeroes; confirms brit & HK are similar
ggplot(HKdata, aes(season2_copies), fill = "white", color = "black") + facet_wrap(~ culture) + geom_histogram()
#assumption tests
#test for normality indicates it is not normal (sig = not normal)
shapiro.test(HKdata$copy_frequency_s2)
#levene's test for homogeneity of variance also indicates no homogeneity (sig = heterogenous var)
library(car)
leveneTest(HKdata$copy_frequency_s2, HKdata$culture, center=median)
#quasibinomial
summary(nullmodelS2bin <- glm(copy_frequency_s2 ~ 1, family = quasibinomial, data = HKdata))
#goodness of fit test is non-sig, indicating good overall fit
with(nullmodelS2bin, cbind(res.deviance = deviance, df = df.residual, p = pchisq(deviance, df.residual, lower.tail = FALSE)))
#add cultural group
summary(culturemodelS2bin <- glm(copy_frequency_s2 ~ culture, family = quasibinomial, data = HKdata))
#goodness of fit test is still non-sig; model fits well
with(culturemodelS2bin, cbind(res.deviance = deviance, df = df.residual, p = pchisq(deviance, df.residual, lower.tail = FALSE)))
#compare null and culture models; sig diff, so fit is improved by culture
anova(nullmodelS2bin, culturemodelS2bin, test = "Chisq")
#do post-hoc tests: indicate that Hk, Brit and immigrant are identical
#mainland sig diff to every other group
library(multcomp)
summary(posthocs <- glht(culturemodelS2bin, linfct = mcp(culture = "Tukey")))
#add sex, age; neither significant
summary(agesexmodelS2bin <- glm(copy_frequency_s2 ~ culture + age + sex, family = quasibinomial, data = HKdata))
#compare agesex and culture-only models; no sig diff so drop age & sex
anova(agesexmodelS2bin, culturemodelS2bin, test = "Chisq")
#just sex, ns
summary(sexonlymodelS2bin <- glm(copy_frequency_s2 ~ sex, family = quasibinomial, data = HKdata))
#sex + culture, marginal
summary(sexculturemodelS2bin <- glm(copy_frequency_s2 ~ culture + sex, family = quasibinomial, data = HKdata))
anova(culturemodelS2bin, sexculturemodelS2bin, test = "Chisq")
summary(posthocs <- glht(sexculturemodelS2bin, linfct = mcp(culture = "Tukey")))
#get confidence intervals
confint(sexculturemodelS2bin)
confint.default(sexculturemodelS2bin)
#add IND and COL; neither sig
summary(indcolmodelS2bin <- glm(copy_frequency_s2 ~ culture + individualist_reversed + collectivist_reversed, family = quasibinomial, data = HKdata))
#compare ind/col and culture-only models; no sig diff
anova(indcolmodelS2bin, culturemodelS2bin, test = "Chisq")
#just for interest, the full model; culture still sig but sex also now marginally sig
summary(fullmodelS2bin <- glm(copy_frequency_s2 ~ culture + age + sex + individualist_reversed + collectivist_reversed, family = quasibinomial, data = HKdata))
#although full model is no better fit than culture model, so ignore sig sex in full
anova(fullmodelS2bin, sexculturemodelS2bin, test = "Chisq")
#conclusion from quasibinomial model: HK, British and immigrant groups are identical, mainland Chinese group copy sig more than others
#specifically, for every copy done by a Brit, Chinese mainlanders copy exp(0.79964)=2.22 times (over twice as likely to copy). Other groups are similarly different.
#cross cultural comparison of season 3 copy rates---------------------------------------------
#plot data, barchart - indicates higher mean for chinese rural, all others look equal
ggplot(HKdata, aes(culture, season3_copies/29)) + stat_summary(fun = mean, geom = "bar", fill = "White", color = "Black", size = 1) + coord_cartesian(ylim = c(0, 0.42)) + labs(x = "", y = "frequency of copying") + stat_summary(fun.data = mean_cl_boot, geom = "errorbar", width = 0.2, size = 1) + theme(axis.text.x = element_text(family="Times", color = "Black", size = 28), axis.text.y = element_text(family="Times", color = "Black", size = 24), axis.title.y = element_text(family="Times", size = 28, vjust = 1.7), panel.background = element_rect(fill = "white"), axis.line = element_line(size = 1), panel.grid.minor = element_blank(), axis.ticks = element_line(size = 1, color = "black"))
#boxplots might be better, but suggests non-normally distributed vars
plot(season3_copies ~ culture, data = HKdata)
#plot log(season3_copies): suggests brit and HK are identical, chinese immigrant and rural are higher
clog <- function(x) log(x + 0.5)
plot(clog(season3_copies) ~ culture, data = HKdata)
#histograms show data is non-normally distributed, lots of zeroes; confirms brit & HK are similar
ggplot(HKdata, aes(season3_copies), fill = "white", color = "black") + facet_wrap(~ culture) + geom_histogram()
#test for normality indicates it is not normal (sig = not normal)
shapiro.test(HKdata$season3_copies)
#levene's test for homogeneity of variance also indicates no homogeneity (sig = heterogenous var)
leveneTest(HKdata$season3_copies, HKdata$culture, center=median)
#quasibinomial
summary(nullmodelS3bin <- glm(copy_frequency_s3 ~ 1, family = quasibinomial, data = HKdata))
#goodness of fit test is non-sig, indicating good overall fit
with(nullmodelS3bin, cbind(res.deviance = deviance, df = df.residual, p = pchisq(deviance, df.residual, lower.tail = FALSE)))
#add cultural group
summary(culturemodelS3bin <- glm(copy_frequency_s3 ~ culture, family = quasibinomial, data = HKdata))
#goodness of fit test is still non-sig; model fits well
with(culturemodelS3bin, cbind(res.deviance = deviance, df = df.residual, p = pchisq(deviance, df.residual, lower.tail = FALSE)))
#compare null and culture models; no sig diff, so fit is not improved by culture
anova(nullmodelS3bin, culturemodelS3bin, test = "Chisq")
#do post-hoc tests: again no sig diffs
library(multcomp)
summary(posthocs <- glht(culturemodelS3bin, linfct = mcp(culture = "Tukey")))
#add sex, age; neither significant
summary(agesexmodelS3bin <- glm(copy_frequency_s3 ~ culture + age + sex, family = quasibinomial, data = HKdata))
#compare agesex and culture-only models; no sig diff so drop age & sex
anova(agesexmodelS3bin, culturemodelS3bin, test = "Chisq")
#just sex, also not sig (unlike S1 and S2)
summary(sexmodelS3bin <- glm(copy_frequency_s3 ~ culture + sex, family = quasibinomial, data = HKdata))
#add IND and COL; neither sig
summary(indcolmodelS3bin <- glm(copy_frequency_s3 ~ culture + individualist_reversed + collectivist_reversed, family = quasibinomial, data = HKdata))
#compare ind/col and culture-only models; no sig diff
anova(indcolmodelS3bin, culturemodelS3bin, test = "Chisq")
#just for interest, the full model; culture still sig but sex also now marginally sig
summary(fullmodelS3bin <- glm(copy_frequency_s3 ~ culture + age + sex + individualist_reversed + collectivist_reversed, family = quasibinomial, data = HKdata))
#although full model is no better fit than culture model, so ignore sig sex in full
anova(fullmodelS3bin, culturemodelS3bin, test = "Chisq")
anova(fullmodelS3bin, nullmodelS3bin, test = "Chisq")
#conclusion from quasibinomial model for S3: No differences between any groups
#conclusion: S3 shows no or marginal effect of culture; same trend as before (mainland diff to others)