-
Notifications
You must be signed in to change notification settings - Fork 0
/
.Rhistory
512 lines (512 loc) · 23.3 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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
View(d2)
View(d2)
View(d2)
affect <- ggplot(d2, aes(names, Mean, fill = names)) + geom_bar(stat='identity') + annotate("text", x=1, y=0, label="Never") +
annotate("text", x=1, y=5, label="All the time") +
geom_errorbar(aes(ymin = Mean-SE, ymax = Mean + SE), width = .2, position=position_dodge(.9)) +
theme_minimal() + theme(legend.position = 'none', axis.text.x = element_text(angle=90, vjust=0.5, size = 10)) + xlab("Affect") + ylab('Average Rating') +
expand_limits(y=c(1,5)) + geom_vline(aes(xintercept=3.5))
affect
d2$names <- c( 'high arousal','high arousal -negative','high arousal - positive',
'low arousal', 'low arousal - negative', 'low arousal - positive' )
d2$names <- factor(d2$names, levels =c('low arousal', 'low arousal - negative', 'low arousal - positive',
'high arousal','high arousal -negative', 'high arousal - positive'))
affect <- ggplot(d2, aes(names, Mean, fill = names)) + geom_bar(stat='identity') + annotate("text", x=1, y=0, label="Never") +
annotate("text", x=1, y=5, label="All the time") +
geom_errorbar(aes(ymin = Mean-SE, ymax = Mean + SE), width = .2, position=position_dodge(.9)) +
theme_minimal() + theme(legend.position = 'none', axis.text.x = element_text(angle=90, vjust=0.5, size = 10)) + xlab("Affect") + ylab('Average Rating') +
expand_limits(y=c(1,5)) + geom_vline(aes(xintercept=3.5))
affect
View(d2)
# Graph means
d2 <- cbind(colMeans(d1), apply(d1, 2, sd), apply(d1, 2, sd)/sqrt(nrow(d1)))
d2 <- d2[3:nrow(d2),]
colnames(d2) <- c('Mean', 'SD', 'SE')
names <- rownames(d2); rownames(d2) <- NULL
d2 <- cbind(names, d2)
d2 <- data.frame(d2)
d2$Mean <- as.numeric(as.character(d2$Mean))
d2$SD <- as.numeric(as.character(d2$SD))
d2$SE <- as.numeric(as.character(d2$SE))
View(d2)
d2$names <- revalue('ha' = 'high arousal','han' = 'high arousal -negative','hap' = 'high arousal - positive',
'la' = 'low arousal', 'lan' = 'low arousal - negative', 'lap' = 'low arousal - positive')
library(plyr)
d2$names <- revalue('ha' = 'high arousal','han' = 'high arousal -negative','hap' = 'high arousal - positive',
'la' = 'low arousal', 'lan' = 'low arousal - negative', 'lap' = 'low arousal - positive')
d2$names <- revalue(d2$names, c('ha' = 'high arousal','han' = 'high arousal - negative',
'hap' = 'high arousal - positive', 'la' = 'low arousal',
'lan' = 'low arousal - negative', 'lap' = 'low arousal - positive'))
View(d2)
d2$names <- factor(d2$names, levels =c('low arousal', 'low arousal - negative', 'low arousal - positive',
'high arousal','high arousal -negative', 'high arousal - positive'))
affect <- ggplot(d2, aes(names, Mean, fill = names)) + geom_bar(stat='identity') + annotate("text", x=1, y=0, label="Never") +
annotate("text", x=1, y=5, label="All the time") +
geom_errorbar(aes(ymin = Mean-SE, ymax = Mean + SE), width = .2, position=position_dodge(.9)) +
theme_minimal() + theme(legend.position = 'none', axis.text.x = element_text(angle=90, vjust=0.5, size = 10)) + xlab("Affect") + ylab('Average Rating') +
expand_limits(y=c(1,5)) + geom_vline(aes(xintercept=3.5))
affect
d2$names <- factor(d2$names, levels =c('low arousal', 'low arousal - negative', 'low arousal - positive',
'high arousal','high arousal - negative', 'high arousal - positive'))
affect <- ggplot(d2, aes(names, Mean, fill = names)) + geom_bar(stat='identity') + annotate("text", x=1, y=0, label="Never") +
annotate("text", x=1, y=5, label="All the time") +
geom_errorbar(aes(ymin = Mean-SE, ymax = Mean + SE), width = .2, position=position_dodge(.9)) +
theme_minimal() + theme(legend.position = 'none', axis.text.x = element_text(angle=90, vjust=0.5, size = 10)) + xlab("Affect") + ylab('Average Rating') +
expand_limits(y=c(1,5)) + geom_vline(aes(xintercept=3.5))
affect
d2$names <- revalue(d2$names, c('ha' = 'high arousal','han' = 'high arousal - negative',
'hap' = 'high arousal - positive', 'la' = 'low arousal',
'lan' = 'low arousal - negative', 'lap' = 'low arousal - positive'))
# Graph means
d2 <- cbind(colMeans(d1), apply(d1, 2, sd), apply(d1, 2, sd)/sqrt(nrow(d1)))
d2 <- d2[3:nrow(d2),]
colnames(d2) <- c('Mean', 'SD', 'SE')
names <- rownames(d2); rownames(d2) <- NULL
d2 <- cbind(names, d2)
d2 <- data.frame(d2)
d2$Mean <- as.numeric(as.character(d2$Mean))
d2$SD <- as.numeric(as.character(d2$SD))
d2$SE <- as.numeric(as.character(d2$SE))
d2$names <- revalue(d2$names, c('ha' = 'high arousal','han' = 'high arousal - negative',
'hap' = 'high arousal - positive', 'la' = 'low arousal',
'lan' = 'low arousal - negative', 'lap' = 'low arousal - positive'))
d2$names <- factor(d2$names, levels =c('low arousal', 'low arousal - negative', 'low arousal - positive',
'high arousal','high arousal - negative', 'high arousal - positive'))
View(d2)
affect <- ggplot(d2, aes(names, Mean, fill = names)) + geom_bar(stat='identity') + annotate("text", x=1, y=0, label="Never") +
annotate("text", x=1, y=5, label="All the time") +
geom_errorbar(aes(ymin = Mean-SE, ymax = Mean + SE), width = .2, position=position_dodge(.9)) +
theme_minimal() + theme(legend.position = 'none', axis.text.x = element_text(angle=90, vjust=0.5, size = 10)) + xlab("Affect") + ylab('Average Rating') +
expand_limits(y=c(1,5)) + geom_vline(aes(xintercept=3.5))
affect
# load required packages
library(here)
library(ggplot2)
library(tidyr)
library(plyr)
# load source functions
source(here::here('scr', 'isolate_skew.R'))
source(here::here('scr', 'isolate_measure.R'))
source(here::here('scr', 'SummarySE.R'))
source(here::here('scr', 'pairedttable.R'))
# graph affective
# 11.11.19 KLS
# load required packages
library(here)
library(ggplot2)
library(tidyr)
library(plyr)
# load source functions
source(here::here('scr', 'isolate_skew.R'))
source(here::here('scr', 'isolate_measure.R'))
source(here::here('scr', 'SummarySE.R'))
source(here::here('scr', 'pairedttable.R'))
source(here::here('scr', 'corrTableCI.R'))
source(here::here('scr', 'multiplot.R'))
# set hard-coded variables
# load data
dt <- read.csv(here::here("data", "bound_skew2_data.csv"))
dict <- read.csv(here::here("data", "bound_skew2_data_dictionary.csv"))
# graph affective
# 11.11.19 KLS
# load required packages
library(here)
library(ggplot2)
library(tidyr)
library(plyr)
# load source functions
source(here::here('scr', 'isolate_skew.R'))
source(here::here('scr', 'isolate_measure.R'))
source(here::here('scr', 'SummarySE.R'))
source(here::here('scr', 'pairedttable.R'))
source(here::here('scr', 'corrTableCI.R'))
source(here::here('scr', 'multiplot.R'))
# set hard-coded variables
# load data
dt <- read.csv(here::here("data", "bound_skew2_data.csv"))
dict <- read.csv(here::here("data", "bound_skew2_data_dictionary.csv"))
View(pairedttable)
source(here::here('scr', 'pairedttable.R'))
source(here::here('scr', 'corrTableCI.R'))
source(here::here('scr', 'multiplot.R'))
# load data
dt <- read.csv(here::here("data", "bound_skew2_data.csv"))
dict <- read.csv(here::here("data", "bound_skew2_data_dictionary.csv"))
# isolate AVI data
Sys.setlocale('LC_ALL','C')
qs <- as.character(dict$Question)
first <- grep("Enthusiastic", qs)
last <- grep("Lonely", qs)
#last <- grep("Serene", qs)
d0 <- isolate_skew(dt,c(1,2), first:last)
# add labels to AVI data
d0 <- add_correct_avi_labels(d0, "Enthusiastic", "Lonely", dict)
#d0 <- add_correct_avi_labels(d0, "Enthusiastic", "Serene", dict)
d1 <- score_avi(d0)
# Graph means
d2 <- cbind(colMeans(d1), apply(d1, 2, sd), apply(d1, 2, sd)/sqrt(nrow(d1)))
d2 <- d2[3:nrow(d2),]
colnames(d2) <- c('Mean', 'SD', 'SE')
names <- rownames(d2); rownames(d2) <- NULL
d2 <- cbind(names, d2)
d2 <- data.frame(d2)
d2$Mean <- as.numeric(as.character(d2$Mean))
d2$SD <- as.numeric(as.character(d2$SD))
d2$SE <- as.numeric(as.character(d2$SE))
d2$names <- revalue(d2$names, c('ha' = 'high arousal','han' = 'high arousal - negative',
'hap' = 'high arousal - positive', 'la' = 'low arousal',
'lan' = 'low arousal - negative', 'lap' = 'low arousal - positive'))
d2$names <- factor(d2$names, levels =c('low arousal', 'low arousal - negative', 'low arousal - positive',
'high arousal','high arousal - negative', 'high arousal - positive'))
affect <- ggplot(d2, aes(names, Mean, fill = names)) + geom_bar(stat='identity') + annotate("text", x=1, y=0, label="Never") +
annotate("text", x=1, y=5, label="All the time") +
geom_errorbar(aes(ymin = Mean-SE, ymax = Mean + SE), width = .2, position=position_dodge(.9)) +
theme_minimal() + theme(legend.position = 'none', axis.text.x = element_text(angle=90, vjust=0.5, size = 10)) + xlab("Affect") + ylab('Average Rating') +
expand_limits(y=c(1,5)) + geom_vline(aes(xintercept=3.5))
# ANOVA
d3 <- gather(d1, condition, rating, hap:ha)
affectaov <- aov(rating ~ condition + Error(ID), d3)
summary(affectaov)
ttable <- pairedttable(d1[c(1,3:8)],colnames(d1)[3:8])
# Examine correlations with age
agecorr <- corrTableCI(d1[2:8])
#graphs
age_lap <- ggplot(d1, aes(Age, lap)) + geom_point() + geom_smooth(method=lm) +
ggtitle('Low Arousal - Positive')
age_lan <- ggplot(d1, aes(Age, lan)) + geom_point() + geom_smooth(method=lm) +
ggtitle('Low Arousal - Negative')
age_han <- ggplot(d1, aes(Age, han)) + geom_point() + geom_smooth(method=lm) +
ggtitle('High Arousal - Negative')
age_ha <- ggplot(d1, aes(Age, ha)) + geom_point() + geom_smooth(method=lm) +
ggtitle('High Arousal')
#multiplot(age_lap, age_lan, age_ha, age_han, cols = 2)
ttable
View(ttable)
knitr::opts_chunk$set(echo = TRUE)
library(kableExtra)
source('../06_graph_affect.R')
ttable$tval %>%
kable() %>%
kable_styling("striped", full_width = F)
ttable$tval %>%
kable() %>%
kable_styling("striped", full_width = F)
ttable$`p values` %>%
kable() %>%
kable_styling("striped", full_width = F)
ttable$`p values` %>%
kable() %>%
kable_styling("striped", full_width = F)
ttable$pvalues %>%
kable() %>%
kable_styling("striped", full_width = F)
ttable$`p values` %>%
kable() %>%
kable_styling("striped", full_width = F)
agecorr[,1:2] %>%
kable() %>%
kable_styling("striped", full_width = F) %>%
row_spec(c(3,5:7), bold = T, background = 'yellow')
# graph affective
# 11.11.19 KLS
# load required packages
library(here)
library(ggplot2)
library(tidyr)
library(plyr)
# load source functions
source(here::here('scr', 'isolate_skew.R'))
source(here::here('scr', 'isolate_measure.R'))
source(here::here('scr', 'SummarySE.R'))
source(here::here('scr', 'pairedttable.R'))
source(here::here('scr', 'corrTableCI.R'))
source(here::here('scr', 'multiplot.R'))
# set hard-coded variables
# load data
dt <- read.csv(here::here("data", "bound_skew2_data.csv"))
dict <- read.csv(here::here("data", "bound_skew2_data_dictionary.csv"))
# isolate AVI data
Sys.setlocale('LC_ALL','C')
qs <- as.character(dict$Question)
first <- grep("Enthusiastic", qs)
last <- grep("Lonely", qs)
#last <- grep("Serene", qs)
d0 <- isolate_skew(dt,c(1,2), first:last)
# add labels to AVI data
d0 <- add_correct_avi_labels(d0, "Enthusiastic", "Lonely", dict)
#d0 <- add_correct_avi_labels(d0, "Enthusiastic", "Serene", dict)
d1 <- score_avi(d0)
# Graph means
d2 <- cbind(colMeans(d1), apply(d1, 2, sd), apply(d1, 2, sd)/sqrt(nrow(d1)))
d2 <- d2[3:nrow(d2),]
colnames(d2) <- c('Mean', 'SD', 'SE')
names <- rownames(d2); rownames(d2) <- NULL
d2 <- cbind(names, d2)
d2 <- data.frame(d2)
d2$Mean <- as.numeric(as.character(d2$Mean))
d2$SD <- as.numeric(as.character(d2$SD))
d2$SE <- as.numeric(as.character(d2$SE))
d2$names <- revalue(d2$names, c('ha' = 'high arousal','han' = 'high arousal - negative',
'hap' = 'high arousal - positive', 'la' = 'low arousal',
'lan' = 'low arousal - negative', 'lap' = 'low arousal - positive'))
d2$names <- factor(d2$names, levels =c('low arousal', 'low arousal - negative', 'low arousal - positive',
'high arousal','high arousal - negative', 'high arousal - positive'))
write.csv(d2, here::here('output', 'affect2.csv'), row.names = FALSE)
View(d2)
View(score_avi)
View(score_avi)
# 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"))
View(d4)
write.csv(d4, here::here('output', 'cog2.csv'), row.names = FALSE)
source('~/github/boundSkew2/09_individual_differences.R', echo=TRUE)
source('~/github/boundSkew2/01_graph_skew.R', echo=TRUE)
# load required packages
library(here)
# load data
dt <- read.csv(here("data", "bound_skew2_data.csv"))
View(dt)
grep('SC0', colnames(dt))
# clean
dt <- dt[-c(1:2, 140:(ncol(dt)-1))]
View(dt)
# load data
dt <- read.csv(here('data', 'boundskew2raw.csv'))
# add id column
dt$ID <- c(0,0,seq(1,nrow(dt)-2,1))
# clean
dt <- dt[-c(1:2, 139:(ncol(dt)-1))]
dt <- dt[c(ncol(dt),1:(ncol(dt)-1))]
View(dt)
# load data
dt <- read.csv(here('data', 'boundskew2raw.csv'))
# add id column
dt$ID <- c(0,0,seq(1,nrow(dt)-2,1))
# clean
dt <- dt[-c(1:2, 139:(ncol(dt)-1))]
View(dt)
# load data
dt <- read.csv(here('data', 'boundskew2raw.csv'))
# add id column
dt$ID <- c(0,0,seq(1,nrow(dt)-2,1))
# clean
dt <- dt[-c(1:2, 140:(ncol(dt)-1))]
View(dt)
# load data
dt <- read.csv(here('data', 'boundskew2raw.csv'))
# add id column
dt$ID <- c(0,0,seq(1,nrow(dt)-2,1))
# clean
dt <- dt[-c(1:2, 142:(ncol(dt)-1))]
View(dt)
# clean
dt <- dt[-c(1:2, 141:(ncol(dt)-1))]
# load data
dt <- read.csv(here('data', 'boundskew2raw.csv'))
# add id column
dt$ID <- c(0,0,seq(1,nrow(dt)-2,1))
# clean
dt <- dt[-c(1:2, 141:(ncol(dt)-1))]
View(dt)
dt <- dt[c(ncol(dt),1:(ncol(dt)-1))]
# create data dictionary
dd <- t(dt[1,])
dd <- cbind(rownames(dd), data.frame(dd, row.names = NULL))
colnames(dd) <- c('Variable', 'Question')
# finish cleaning
dt <- dt[-c(1:2),]
dt$Age <- as.integer(as.character(dt$Age))
dt$Age <- dt$Age + 19
View(dd)
source('~/github/boundSkew2/00_load_data.R', echo=TRUE)
# load required packages
library(here)
# load data
dt <- read.csv(here("data", "bound_skew2_data.csv"))
# add and populate variable names column
dd[,'Variable Names'] <- NA
dd$`Variable Names`[1:9] <- c(as.character(dd$Variable[1:7]), 'Practice 1', 'Practice 2')
dd <- read.csv(here("data", "bound_skew2_data_dictionary.csv"))
# add and populate variable names column
dd[,'Variable Names'] <- NA
dd$`Variable Names`[1:9] <- c(as.character(dd$Variable[1:7]), 'Practice 1', 'Practice 2')
gambles <- list(a = (10:19), b = (22:31), c = (34:43), d = (46:55), e = (58:67))
View(dd)
for (g in 1:length(gambles)){
print(g)
b <- rep(NA, length(gambles[g][[1]]))
for (x in 1:length(gambles[g][[1]])){
print(x)
y <- gambles[g][[1]][x]
z <- as.character(dd$Variable[y])
a <- strsplit(z, '_')
b[x] <- paste0(sub('X', '', a[[1]][1]), '_EV_', a[[1]][2], '_', a[[1]][3], '_Gamble')
}
dd$`Variable Names`[gambles[g][[1]]] <- b
}
rm(a, b, g, x, y, z, gambles)
dd$`Variable Names`[c(20:21, 32:33, 44:45, 56:57, 68:69)] <- paste0('Catch_', seq(1,10))
dd$`Variable Names`[c(70:75)] <- paste0('Strategy_', seq(1,6))
dd$`Variable Names`[c(76:84)] <- paste0('Investment_', seq(1,9))
dd$`Variable Names`[c(85:93)] <- paste0('Fraud_', seq(1,9))
dd$`Variable Names`[c(94:117)] <- paste0('AVI_', seq(1,24))
View(dd)
# load required packages
library(here)
# load data
dt <- read.csv(here("data", "bound_skew2_data.csv"))
dd <- read.csv(here("data", "bound_skew2_data_dictionary.csv"))
View(dt)
View(dd)
# add and populate variable names column
dd[,'Variable Names'] <- NA
dd$`Variable Names`[1:10] <- c(as.character(dd$Variable[1:7]), 'Practice 1', 'Practice 2', 'Practice 3')
gambles <- list(a = (11:19), b = (22:30), c = (33:41), d = (44:52), e = (55:63))
for (g in 1:length(gambles)){
print(g)
b <- rep(NA, length(gambles[g][[1]]))
for (x in 1:length(gambles[g][[1]])){
print(x)
y <- gambles[g][[1]][x]
z <- as.character(dd$Variable[y])
a <- strsplit(z, '_')
b[x] <- paste0(sub('X', '', a[[1]][1]), '_EV_', a[[1]][2], '_', a[[1]][3], '_Gamble')
}
dd$`Variable Names`[gambles[g][[1]]] <- b
}
rm(a, b, g, x, y, z, gambles)
dd$`Variable Names`[c(20:21, 31:32, 42:43, 53:54, 64:65)] <- paste0('Catch_', seq(1,10))
dd$`Variable Names`[c(66:71)] <- paste0('Strategy_', seq(1,6))
dd$`Variable Names`[c(72:80)] <- paste0('Investment_', seq(1,9))
dd$`Variable Names`[c(81:89)] <- paste0('Fraud_', seq(1,9))
dd$`Variable Names`[c(90:113)] <- paste0('AVI_', seq(1,24))
dd$`Variable Names`[c(114:128)] <- paste0('Numeracy_', seq(1,14))
dd$`Variable Names`[c(129:138)] <- paste0('Graph_Lit_', seq(1,10))
dd$`Variable Names`[139] <- 'DOB'
# add measurement units
dt[c(73, 75, 77, 80, 87, 89, 119:124, 126:127)] <- sapply(dt[c(73, 75, 77, 80, 87, 89, 119:124, 126:127)], as.character)
dd$`Measurement Units` <- sapply(dt, class)
dd$`Measurement Units`[143] <- 'mm/dd/yyyy'
dd$`Measurement Units`[143] <- 'mm/dd/yyyy'
dd$`Measurement Units`[143] <- 'mm/dd/yyyy'
dd$`Measurement Units`[139] <- 'mm/dd/yyyy'
# Create and populate allowed_values in data dictionary
dd[,'Allowed Values'] <- NA
dd$`Allowed Values`[1] <- '1-209'
dd$`Allowed Values`[2] <- '22-85'
dd$`Allowed Values`[c(3, 8:69, 76, 88, 129)] <- '1-2'
dd$`Allowed Values`[c(4, 83, 92, 133:142)] <- '1-6'
dd$`Allowed Values`[5] <- '1-8'
dd$`Allowed Values`[6] <- '1-16'
dd$`Allowed Values`[c(7,70:75, 79:80, 94:117)] <- '1-5'
dd$`Allowed Values`[c(3, 8:65, 72, 84, 125)] <- '1-2'
dd$`Allowed Values`[c(4, 79, 88, 129:138)] <- '1-6'
dd$`Allowed Values`[5] <- '1-8'
dd$`Allowed Values`[6] <- '1-16'
dd$`Allowed Values`[c(7, 66:71, 75:76, 90:113)] <- '1-5'
dd$`Allowed Values`[c(73, 85, 114:115)] <- 'Positive integers'
dd$`Allowed Values`[74] <- 'Monetary amount'
dd$`Allowed Values`[c(77, 80, 87, 89, 119:124, 126:127)] <- 'Text'
dd$`Allowed Values`[c(79, 117:118, 128)] <- '1-3'
dd$`Allowed Values`[c(81:83, 86)] <- '1-7'
dd$`Allowed Values`[116] <- 'decimal'
dd$`Allowed Values`[139] <- 'mm/dd/yyyy'
# Create and populate description of variable
dd[,'Description of Variable'] <- NA
dd$`Description of Variable`[2] <- 'Age in years'
dd$`Description of Variable`[3] <- "1 = Male, 2 = Female"
dd$`Description of Variable`[4] <- "1 = Middle School, 2 = High School Diploma, 3 = Some College,
4 = Bachelor's Degree, 5 = Master's Degree, 6 = Doctoral Degree"
dd$`Description of Variable`[5] <- "1 = White/Caucasian, 2 = Black/African American, 3 = Asian, 4 = Hispanic/Latino,
5 = American Indian/Alaska Native, 6 = Pacific Islander, 7 = Multiracial, 8 = Other"
dd$`Description of Variable`[6] <- '1 = less than $10,000, 2 = $10,000-$19,999,
3 = $20,000-$29,999, 4 = $30,000-$39,999, 5 = $40,000-$49,999, 6 = $50,000-$59,999, 7 = $60,000-$69,999,
8 = $70,000-$79,999, 9 = $80,000-$89,999, 10 = $90,000-$99,999, 11 = $100,000-$109,999, 12 = $110,000-$119,999,
13 = $120,000-$129,999, 14 = $130,000-$139,999, 15 = $140,000-$149,999, 16 = $150,000 or more'
dd$`Description of Variable`[7] <- "1 = Not healthy at all, 5 = Very healthy"
# Create and populate description of variable
dd[,'Description of Variable'] <- NA
dd$`Description of Variable`[2] <- 'Age in years'
dd$`Description of Variable`[3] <- "1 = Male, 2 = Female"
dd$`Description of Variable`[4] <- "1 = Middle School, 2 = High School Diploma, 3 = Some College,
4 = Bachelor's Degree, 5 = Master's Degree, 6 = Doctoral Degree"
dd$`Description of Variable`[5] <- "1 = White/Caucasian, 2 = Black/African American, 3 = Asian, 4 = Hispanic/Latino,
5 = American Indian/Alaska Native, 6 = Pacific Islander, 7 = Multiracial, 8 = Other"
dd$`Description of Variable`[6] <- '1 = less than $10,000, 2 = $10,000-$19,999,
3 = $20,000-$29,999, 4 = $30,000-$39,999, 5 = $40,000-$49,999, 6 = $50,000-$59,999, 7 = $60,000-$69,999,
8 = $70,000-$79,999, 9 = $80,000-$89,999, 10 = $90,000-$99,999, 11 = $100,000-$109,999, 12 = $110,000-$119,999,
13 = $120,000-$129,999, 14 = $130,000-$139,999, 15 = $140,000-$149,999, 16 = $150,000 or more'
dd$`Description of Variable`[7] <- "1 = Not healthy at all, 5 = Very healthy"
dd$`Description of Variable`[8:65] <- "1 = symmetric gamble, 2 = skewed gamble"
dd$`Description of Variable`[66:71] <- '1 = Strongly Disagree, 2 = Somewhat Disagree, 3 =
Neutral, 4 = Somewhat Agree, 5 = Strongly Agree'
dd$`Description of Variable`[c(72, 84)] <- '1 = Yes, 2 = No'
dd$`Description of Variable`[75] <- "1 = Less than a year ago, 2 = 1-3 years ago, 3 = 4-5 years ago,
4 = More than 5 years ago, 5 = Don't know/can't remember"
dd$`Description of Variable`[76] <- " 1 = I just made a bad investment,
2 = The market took a downward turn,
3 = I didn'tknow enough about the type of investment I was making,
4 = I was misled or defrauded by the person or organization that sold me the investment,
5 = Other"
dd$`Description of Variable`[77] <- 'This is the explanatory text they completed if they chose other on the previous quesiton.'
dd$`Description of Variable`[78] <- '1 = Yes, 2 = No, 3 = Not applicable'
dd$`Description of Variable`[80] <- 'This is the explanatory text they completed if they chose other on the previous quesiton.'
dd$`Description of Variable`[81] <- '1 = not at all able to detect, 7 = very able to detect'
dd$`Description of Variable`[82] <- '1 = not at all likely, 7 = very likely'
dd$`Description of Variable`[83] <- '1 = not at all able to resist, 7 = very able to resist'
dd$`Description of Variable`[85] <- 'This is the explanatory text they answered yes on the previous quesiton.'
dd$`Description of Variable`[86] <- '1 = Mail, 2 = Phone call, 3 = Email, 4 = Website, 5 = Seminar,
6 = Other, 7 = Not applicable'
dd$`Description of Variable`[88] <- '1 = Stranger, 2 = Co-worker, 3 = Friend, 4 = Family member, 5 = Other, 6 = Not applicable'
dd$`Description of Variable`[90:113] <- '1 = Never, 2 = A small amount of time, 3 = Half of the time, 4 = Most of the time, 5 = All of the time'
dd$`Description of Variable`[117] <- '1 = 1 in 100, 2 = 1 in 1000, 3 = 1 in 10'
dd$`Description of Variable`[118] <- '1 = 1%, 2 = 10%, 3 = 5%'
dd$`Description of Variable`[125] <- '1 = 1 chance in 12, 2 = 1 chance in 37'
dd$`Description of Variable`[128] <- '1 = The both tested positive for SARS and therefore are equally likely to have the disease,
2 = They both tested positive for SARS and the doctor is more likely t0 have the disease,
3 = They both tested positive for SARS and the person in the at-risk population is more likely to have the disease'
dd$`Description of Variable`[129:134] <- '1 = Not good at all, 6 = Extremely good'
dd$`Description of Variable`[135] <- '1 = Not at all, 6 = Much easier'
dd$`Description of Variable`[136] <- '1 = Never, 6 = Very often'
dd$`Description of Variable`[137:138] <- '1 Not at all, 6 = Extremely'
dd$`Description of Variable` <- sapply(dd$`Description of Variable`, as.character)
dd$`Description of Variable`[is.na(dd$`Description of Variable`)] <- ''
# Reorder columns
dd <- dd[c(1,3,4,5,2,6)]
write.csv(dd, here("data", "bound_skew2_data_dictionary.csv"), row.names = FALSE)