-
Notifications
You must be signed in to change notification settings - Fork 0
/
07_graph_cognitive.R
52 lines (39 loc) · 1.51 KB
/
07_graph_cognitive.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
# visualize numeracy and graph literacy
# 11.25.19 KLS
# load required packages
library(here)
library(ggplot2)
# load source functions
source(here('scr', 'isolate_skew.R'))
source(here('scr', 'isolate_measure.R'))
source(here('scr', 'SummarySE.R'))
# set hard-coded variables
# load data
dt <- read.csv(here("data", "bound_skew2_data.csv"))
dict <- read.csv(here("data", "bound_skew2_data_dictionary.csv"))
# isolate graph literacy
Sys.setlocale('LC_ALL','C')
qs <- as.character(dict$Question)
first <- grep("bar charts", qs)
last <- grep("newspapers", qs)
d0 <- isolate_skew(dt,c(1,2), first:last)
# graph literacy score
d1 <- score_graph_lit(d0)
# visualize graph literacy
sgl1 <- ggplot(d1, (aes(x=graph_lit))) + geom_histogram(binwidth = 0.5) +
geom_vline(aes(xintercept=mean(graph_lit, na.rm=T)), color="red", linetype="dashed", size=1)
sgl2 <- ggplot(d1, aes(Age, graph_lit)) + geom_point() + geom_smooth(method=lm)
# isolate numeracy
first <- grep("six-sided", qs)
last <- grep("10,000 doctors", qs)
d2 <- isolate_skew(dt,c(1,2), first:last)
# score numeracy
ans_key <- create_num_answer_key()
d3 <- as.data.frame(score_num(d2, ans_key))
# graph numeracy
num1 <- ggplot(d3, (aes(x=Numeracy))) + geom_histogram(binwidth = 0.5) +
geom_vline(aes(xintercept=mean(Numeracy, na.rm=T)), color="red", linetype="dashed", size=1)
num2 <- ggplot(d3, aes(Age, Numeracy)) + geom_point() + geom_smooth(method=lm)
# make table
d4 <- merge(d1, d3, by = c("ID", "Age"))
write.csv(d4, here::here('output', 'cog2.csv'), row.names = FALSE)