-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.Rhistory
372 lines (372 loc) · 16.2 KB
/
.Rhistory
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
install.packages("ggpubr")
install.packages("devtools")
devtools::install_github("langcog/langcog")
ch_loc <- hum %>% filter(DropLocation!="outside" & DropLocation!="space") %>%
group_by(DropChoice, DropLocation) %>%
summarise(n = n()) %>%
mutate(freq = n / sum(n))
ch_loc <- hum %>% filter(DropLocation!="outside" & DropLocation!="space") %>%
group_by(DropChoice, DropLocation) %>%
summarise(n = n()) %>%
mutate(freq = n / sum(n))
# 12 trials, 9 objects; random selection would be 9/12 = 75%...
uniq_s <- hum %>% group_by(SID, Age_Group) %>%
summarise(DropObjs = n_distinct(DropChoice), N=n(), prop=DropObjs/N)
knitr::opts_chunk$set(fig.width=3, fig.height=3, fig.crop = F,
fig.pos = "tb", fig.path='figs/',
echo=F, warning=F, cache=F,
message=F, sanitize = T)
library(png)
library(grid)
library(ggplot2)
library(xtable)
require(here)
require(tidyverse)
require(tidyboot)
library(apa) # for generating APA-style text to report statistical tests
library(ggpubr)
tower = read.csv2("../analysis/human-data/curiobaby_drop-data - cool tower.csv", sep=',', header=T, stringsAsFactors=F)
raw = read.csv2("../analysis/human-data/curiobaby_drop-data - drop exp.csv", sep=',', header=T, stringsAsFactors=F)
hum = subset(raw, Exclude!="Y")
hum = hum[-which(hum$StimSet=="bc" & hum$DropChoice=="bowl and dumbbell"),] # chose two - exclude
s_tr <- hum %>% group_by(SID, Age_Group) %>% summarise(max=max(Trial)) %>% arrange(max)
age = table(s_tr$Age_Group)
shapes = c("bowl","cone","dumbbell","octahedron","pentagon","pipe","pyramid","torus","trig prism")
a = c("pyramid", "torus", "trig prism")
b = c("cone", "octahedron", "pipe")
c = c("bowl", "dumbbell", "pentagon")
hum <- hum %>%
mutate(DropSet=ifelse(StimSet %in% c("ba","ca"), "A", ifelse(StimSet %in% c("ab","cb"), "B", "C")),
TargetSet=ifelse(StimSet %in% c("ab","ac"), "A", ifelse(StimSet %in% c("ba","bc"), "B", "C")))
img <- png::readPNG("figs/drop_sets.png")
grid::grid.raster(img)
img <- png::readPNG("figs/DropTaskFigure.png")
grid::grid.raster(img)
hum$TargetSpace = ifelse(hum$DropLocation=="space", hum$WhichSpace, hum$DropLocation)
report_chisq <- function(X) {
# e.g. X^2 (2, N = 88) = 2.1, p = .35
pval = round(X$p.value, 3)
if(pval==0) {
pval = ", p<.001"
} else {
pval = paste0(", p=",pval)
}
return(paste0("($X^2$(", X$parameter, ", N=", sum(X$expected), ") = ", round(X$statistic,2), pval, ")"))
}
# see if children's choices (per subset) are random
drop_ch = table(hum$StimSet, hum$DropChoice)
# chisq.test(rbind(colSums(drop_ch[,a]), rep(sum(drop_ch[,a]/3), 3)) )
Xa_drop = chisq.test( colSums(drop_ch[,a]) ) # p<.001
Xb_drop = chisq.test( colSums(drop_ch[,b]) ) # p=.01
Xc_drop = chisq.test( colSums(drop_ch[,c]) ) # p=.056
target_ch = table(hum$StimSet, hum$DropLocation)
Xa_targ = chisq.test( colSums(target_ch[,a]) ) # n.s.
Xb_targ = chisq.test( colSums(target_ch[,b]) ) # n.s.
Xc_targ = chisq.test( colSums(target_ch[,c]) ) # n.s.
targetloc_ch = table(hum$StimSet, hum$TargetSpace)
Xa_tloc = chisq.test( colSums(targetloc_ch[,a]) ) # n.s.
Xb_tloc = chisq.test( colSums(targetloc_ch[,b]) ) # n.s.
Xc_tloc = chisq.test( colSums(targetloc_ch[,c]) ) # n.s.
# 'misses' by age
space_age = table(subset(hum, DropLocation=="space")$Age_Group)
all_age = table(hum$Age_Group)
#Xmiss_age = chisq.test(space_age, p=all_age / sum(all_age)) # n.s.
prop_space = sum(space_age) / sum(all_age)
age_s <- hum %>%
group_by(SID, Age_Exact) %>%
summarise(miss=sum(DropLocation=="space"), N=n()) %>%
mutate(prop_miss = miss / N)
age_miss = cor.test(age_s$prop_miss, as.numeric(age_s$Age_Exact))
# now check DropChoice x TargetLocation interactions
# maybe we do chisq.test on particular combinations? e.g., for DropSet A and TargetSet B?
dA = subset(hum, DropSet=="A" & TargetSet=="B")
dto = table(dA$DropChoice, dA$DropLocation)[,1:3]
#dto = table(hum$DropChoice, hum$DropLocation)[,c(1:4,6:8,10:11)] # drop 'outside' and 'space'
Xdto = chisq.test(dto)
get_table_string <- function(tableX, set) {
tt = sort(colSums(tableX[,set]))
tstr = paste(paste0(names(tt), " (", tt, "),"), collapse=' ')
tstr = gsub('.{1}$', '', tstr)
return(tstr)
}
dA = get_table_string(drop_ch, a)
dB = get_table_string(drop_ch, b)
dC = get_table_string(drop_ch, c)
tabl <- tribble(~Set, ~`Drop Object (N)`,
"A", dA,
"B", dB,
"C", dC)
t1 <- xtable::xtable(tabl, caption="Children's drop object choices by set.")
#tab1 <- xtable::xtable(summary(out)$coef, digits=c(0, 2, 2, 1, 2),
# caption = "This table prints across one column.")
print(t1, type="latex", comment = F, table.placement = "H")
tA = get_table_string(target_ch, a)
tB = get_table_string(target_ch, b)
tC = get_table_string(target_ch, c)
tabl2 <- tribble(~Set, ~`Target Object (N)`,
"A", tA,
"B", tB,
"C", tC)
t2 <- xtable::xtable(tabl2, caption="Children's target object choices by set.")
print(t2, type="latex", comment = F, table.placement = "H")
tA = get_table_string(targetloc_ch, a)
tB = get_table_string(targetloc_ch, b)
tC = get_table_string(targetloc_ch, c)
tabl3 <- tribble(~Set, ~`Target Location (N)`,
"A", tA,
"B", tB,
"C", tC)
t3 <- xtable::xtable(tabl3, caption="Children's target location choices by set.")
print(t3, type="latex", comment = F, table.placement = "H")
ch_cond <- hum %>%
group_by(StimSet, DropChoice) %>%
summarise(n = n()) %>%
mutate(freq = n / sum(n))
ch_cond$StimSet <- factor(ch_cond$StimSet, levels = c("ba","ca","ab","cb","ac","bc"))
fig_drop <- ggplot(ch_cond, aes(x=StimSet, y=freq, shape=DropChoice, color=DropChoice)) + # , size=n
geom_point(alpha=.8) +
scale_shape_manual(values=10:19) +
#geom_linerange(aes(ymin = ci_lower, ymax = ci_upper)) +
xlab("Stimulus Set") + ylab("Rate of Drop Object Choice") + ylim(0,.66) +
langcog::scale_fill_solarized() + ggthemes::theme_few() +
geom_hline(yintercept=.33, lty='dashed') + labs(shape="Object", color="Object")
#print(fig_drop)
hum$Target = hum$DropLocation
ch_cond <- hum %>%
filter(Target!="outside") %>%
group_by(StimSet, Target) %>%
summarise(n = n()) %>%
mutate(freq = n / sum(n))
ch_cond$Target <- factor(ch_cond$Target, levels = c(shapes, "space"))
fig_targ_hit <- ggplot(ch_cond, aes(x=StimSet, y=freq, shape=Target, color=Target)) + # , size=n
geom_point(alpha=.8) +
scale_shape_manual(values=10:20) +
#geom_linerange(aes(ymin = ci_lower, ymax = ci_upper)) +
xlab("Stimulus Set") + ylab("Rate of Target Object Hit") + ylim(0,.66) +
langcog::scale_fill_solarized() + ggthemes::theme_few() +
geom_hline(yintercept=.33, lty='dashed')
#print(fig_targ_hit)
ch_cond <- hum %>%
filter(is.element(TargetSpace, shapes)) %>%
group_by(StimSet, TargetSpace) %>%
summarise(n = n()) %>%
mutate(freq = n / sum(n))
ch_cond$TargetSpace <- factor(ch_cond$TargetSpace, levels = shapes)
fig_targ_space <- ggplot(ch_cond, aes(x=StimSet, y=freq, shape=TargetSpace, color=TargetSpace)) + # , size=n
geom_point(alpha=.8) +
scale_shape_manual(values=10:19) +
#geom_linerange(aes(ymin = ci_lower, ymax = ci_upper)) +
xlab("Stimulus Set") + ylab("Rate of Targeted Location") + ylim(0,.66) +
langcog::scale_fill_solarized() + ggthemes::theme_few() +
geom_hline(yintercept=.33, lty='dashed')
#print(fig_targ_space)
ggarrange(fig_drop, fig_targ_hit, fig_targ_space, nrow=1,
#labels = c("Drop Choice", "Targeted Object Hit", "Targeted Location"),
common.legend=T, legend="bottom")
# 12 trials, 9 objects; random selection would be 9/12 = 75%...
uniq_s <- hum %>% group_by(SID, Age_Group) %>%
summarise(DropObjs = n_distinct(DropChoice), N=n(), prop=DropObjs/N)
uniq <- uniq_s %>% group_by(Age_Group) %>%
tidyboot_mean(prop)
ggplot(uniq, aes(x=Age_Group, y=mean)) + geom_point() +
geom_linerange(aes(ymin = ci_lower, ymax = ci_upper)) +
xlab("Age (years)") + ylab("Unique Objects Chosen") + ylim(0,1) +
langcog::scale_fill_solarized() + ggthemes::theme_few() +
geom_hline(yintercept=.75, lty='dashed')
ch_loc <- hum %>% filter(DropLocation!="outside" & DropLocation!="space") %>%
group_by(DropChoice, DropLocation) %>%
summarise(n = n()) %>%
mutate(freq = n / sum(n))
ggplot(ch_loc, aes(x=DropLocation, y=DropChoice)) + geom_tile(aes(fill=freq)) +
scale_fill_gradient(low = "white", high = "steelblue") +
xlab("Target Location") + ylab("Drop Object") +
ggthemes::theme_few()
# References will be generated automatically by Pandoc and included here.
# The following code is some latex to format the bibliography. Do not remove it.
# cor.test(hum$height_tallest, hum$age_rounded)
ch_height
# cor.test(hum$height_tallest, hum$age_rounded)
hum
# cor.test(hum$height_tallest, hum$age_rounded)
str(hum)
knitr::opts_chunk$set(fig.width=3, fig.height=3, fig.crop = F,
fig.pos = "tb", fig.path='figs/',
echo=F, warning=F, cache=F,
message=F, sanitize = T)
library(png)
library(grid)
library(ggplot2)
library(xtable)
require(here)
require(tidyverse)
require(tidyboot)
library(apa) # for generating APA-style text to report statistical tests
library(ggpubr)
tower = read.csv2("../analysis/human-data/curiobaby_drop-data - cool tower.csv", sep=',', header=T, stringsAsFactors=F)
raw = read.csv2("../analysis/human-data/curiobaby_drop-data - drop exp.csv", sep=',', header=T, stringsAsFactors=F)
hum = subset(raw, Exclude!="Y")
hum = hum[-which(hum$StimSet=="bc" & hum$DropChoice=="bowl and dumbbell"),] # chose two - exclude
s_tr <- hum %>% group_by(SID, Age_Group) %>% summarise(max=max(Trial)) %>% arrange(max)
age = table(s_tr$Age_Group)
shapes = c("bowl","cone","dumbbell","octahedron","pentagon","pipe","pyramid","torus","trig prism")
a = c("pyramid", "torus", "trig prism")
b = c("cone", "octahedron", "pipe")
c = c("bowl", "dumbbell", "pentagon")
hum <- hum %>%
mutate(DropSet=ifelse(StimSet %in% c("ba","ca"), "A", ifelse(StimSet %in% c("ab","cb"), "B", "C")),
TargetSet=ifelse(StimSet %in% c("ab","ac"), "A", ifelse(StimSet %in% c("ba","bc"), "B", "C")))
img <- png::readPNG("figs/drop_sets.png")
grid::grid.raster(img)
img <- png::readPNG("figs/DropTaskFigure.png")
grid::grid.raster(img)
hum$TargetSpace = ifelse(hum$DropLocation=="space", hum$WhichSpace, hum$DropLocation)
report_chisq <- function(X) {
# e.g. X^2 (2, N = 88) = 2.1, p = .35
pval = round(X$p.value, 3)
if(pval==0) {
pval = ", p<.001"
} else {
pval = paste0(", p=",pval)
}
return(paste0("($X^2$(", X$parameter, ", N=", sum(X$expected), ") = ", round(X$statistic,2), pval, ")"))
}
# see if children's choices (per subset) are random
drop_ch = table(hum$StimSet, hum$DropChoice)
# chisq.test(rbind(colSums(drop_ch[,a]), rep(sum(drop_ch[,a]/3), 3)) )
Xa_drop = chisq.test( colSums(drop_ch[,a]) ) # p<.001
Xb_drop = chisq.test( colSums(drop_ch[,b]) ) # p=.01
Xc_drop = chisq.test( colSums(drop_ch[,c]) ) # p=.056
target_ch = table(hum$StimSet, hum$DropLocation)
Xa_targ = chisq.test( colSums(target_ch[,a]) ) # n.s.
Xb_targ = chisq.test( colSums(target_ch[,b]) ) # n.s.
Xc_targ = chisq.test( colSums(target_ch[,c]) ) # n.s.
targetloc_ch = table(hum$StimSet, hum$TargetSpace)
Xa_tloc = chisq.test( colSums(targetloc_ch[,a]) ) # n.s.
Xb_tloc = chisq.test( colSums(targetloc_ch[,b]) ) # n.s.
Xc_tloc = chisq.test( colSums(targetloc_ch[,c]) ) # n.s.
# 'misses' by age
space_age = table(subset(hum, DropLocation=="space")$Age_Group)
all_age = table(hum$Age_Group)
#Xmiss_age = chisq.test(space_age, p=all_age / sum(all_age)) # n.s.
prop_space = sum(space_age) / sum(all_age)
age_s <- hum %>%
group_by(SID, Age_Exact) %>%
summarise(miss=sum(DropLocation=="space"), N=n()) %>%
mutate(prop_miss = miss / N)
age_miss = cor.test(age_s$prop_miss, as.numeric(age_s$Age_Exact))
# now check DropChoice x TargetLocation interactions
# maybe we do chisq.test on particular combinations? e.g., for DropSet A and TargetSet B?
dA = subset(hum, DropSet=="A" & TargetSet=="B")
dto = table(dA$DropChoice, dA$DropLocation)[,1:3]
#dto = table(hum$DropChoice, hum$DropLocation)[,c(1:4,6:8,10:11)] # drop 'outside' and 'space'
Xdto = chisq.test(dto)
get_table_string <- function(tableX, set) {
tt = sort(colSums(tableX[,set]))
tstr = paste(paste0(names(tt), " (", tt, "),"), collapse=' ')
tstr = gsub('.{1}$', '', tstr)
return(tstr)
}
dA = get_table_string(drop_ch, a)
dB = get_table_string(drop_ch, b)
dC = get_table_string(drop_ch, c)
tabl <- tribble(~Set, ~`Drop Object (N)`,
"A", dA,
"B", dB,
"C", dC)
t1 <- xtable::xtable(tabl, caption="Children's drop object choices by set.")
#tab1 <- xtable::xtable(summary(out)$coef, digits=c(0, 2, 2, 1, 2),
# caption = "This table prints across one column.")
print(t1, type="latex", comment = F, table.placement = "H")
tA = get_table_string(target_ch, a)
tB = get_table_string(target_ch, b)
tC = get_table_string(target_ch, c)
tabl2 <- tribble(~Set, ~`Target Object (N)`,
"A", tA,
"B", tB,
"C", tC)
t2 <- xtable::xtable(tabl2, caption="Children's target object choices by set.")
print(t2, type="latex", comment = F, table.placement = "H")
tA = get_table_string(targetloc_ch, a)
tB = get_table_string(targetloc_ch, b)
tC = get_table_string(targetloc_ch, c)
tabl3 <- tribble(~Set, ~`Target Location (N)`,
"A", tA,
"B", tB,
"C", tC)
t3 <- xtable::xtable(tabl3, caption="Children's target location choices by set.")
print(t3, type="latex", comment = F, table.placement = "H")
ch_cond <- hum %>%
group_by(StimSet, DropChoice) %>%
summarise(n = n()) %>%
mutate(freq = n / sum(n))
ch_cond$StimSet <- factor(ch_cond$StimSet, levels = c("ba","ca","ab","cb","ac","bc"))
fig_drop <- ggplot(ch_cond, aes(x=StimSet, y=freq, shape=DropChoice, color=DropChoice)) + # , size=n
geom_point(alpha=.8) +
scale_shape_manual(values=10:19) +
#geom_linerange(aes(ymin = ci_lower, ymax = ci_upper)) +
xlab("Stimulus Set") + ylab("Rate of Drop Object Choice") + ylim(0,.66) +
langcog::scale_fill_solarized() + ggthemes::theme_few() +
geom_hline(yintercept=.33, lty='dashed') + labs(shape="Object", color="Object")
#print(fig_drop)
hum$Target = hum$DropLocation
ch_cond <- hum %>%
filter(Target!="outside") %>%
group_by(StimSet, Target) %>%
summarise(n = n()) %>%
mutate(freq = n / sum(n))
ch_cond$Target <- factor(ch_cond$Target, levels = c(shapes, "space"))
fig_targ_hit <- ggplot(ch_cond, aes(x=StimSet, y=freq, shape=Target, color=Target)) + # , size=n
geom_point(alpha=.8) +
scale_shape_manual(values=10:20) +
#geom_linerange(aes(ymin = ci_lower, ymax = ci_upper)) +
xlab("Stimulus Set") + ylab("Rate of Target Object Hit") + ylim(0,.66) +
langcog::scale_fill_solarized() + ggthemes::theme_few() +
geom_hline(yintercept=.33, lty='dashed')
#print(fig_targ_hit)
ch_cond <- hum %>%
filter(is.element(TargetSpace, shapes)) %>%
group_by(StimSet, TargetSpace) %>%
summarise(n = n()) %>%
mutate(freq = n / sum(n))
ch_cond$TargetSpace <- factor(ch_cond$TargetSpace, levels = shapes)
fig_targ_space <- ggplot(ch_cond, aes(x=StimSet, y=freq, shape=TargetSpace, color=TargetSpace)) + # , size=n
geom_point(alpha=.8) +
scale_shape_manual(values=10:19) +
#geom_linerange(aes(ymin = ci_lower, ymax = ci_upper)) +
xlab("Stimulus Set") + ylab("Rate of Targeted Location") + ylim(0,.66) +
langcog::scale_fill_solarized() + ggthemes::theme_few() +
geom_hline(yintercept=.33, lty='dashed')
#print(fig_targ_space)
ggarrange(fig_drop, fig_targ_hit, fig_targ_space, nrow=1,
#labels = c("Drop Choice", "Targeted Object Hit", "Targeted Location"),
common.legend=T, legend="bottom")
# 12 trials, 9 objects; random selection would be 9/12 = 75%...
uniq_s <- hum %>% group_by(SID, Age_Group) %>%
summarise(DropObjs = n_distinct(DropChoice), N=n(), prop=DropObjs/N)
uniq <- uniq_s %>% group_by(Age_Group) %>%
tidyboot_mean(prop)
ggplot(uniq, aes(x=Age_Group, y=mean)) + geom_point() +
geom_linerange(aes(ymin = ci_lower, ymax = ci_upper)) +
xlab("Age (years)") + ylab("Unique Objects Chosen") + ylim(0,1) +
langcog::scale_fill_solarized() + ggthemes::theme_few() +
geom_hline(yintercept=.75, lty='dashed')
ch_loc <- hum %>% filter(DropLocation!="outside" & DropLocation!="space") %>%
group_by(DropChoice, DropLocation) %>%
summarise(n = n()) %>%
mutate(freq = n / sum(n))
ggplot(ch_loc, aes(x=DropLocation, y=DropChoice)) + geom_tile(aes(fill=freq)) +
scale_fill_gradient(low = "white", high = "steelblue") +
xlab("Target Location") + ylab("Drop Object") +
ggthemes::theme_few()
# cor.test(hum$height_tallest, hum$age_rounded)
# ch_height <- hum %>% group_by(Age_Group, height_tallest) %>%
# summarise(n = n()) %>%
# mutate(freq = n / sum(n))
#
# ggplot(ch_height, aes(x=age_group, y=height_tallest)) +
# geom_smooth(method="lm", level=0.90) + geom_point(alpha=.8, aes(size=n)) +
# scale_shape_manual(values=10:19) +
# xlab("Age") + ylab("Height_Tallest") + ylim(0,10) +
# langcog::scale_fill_solarized() + ggthemes::theme_few()
# References will be generated automatically by Pandoc and included here.
# The following code is some latex to format the bibliography. Do not remove it.