-
Notifications
You must be signed in to change notification settings - Fork 0
/
.Rhistory
423 lines (423 loc) · 18.5 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
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
# Data Manipulation and Analysis
library(tidyverse) # Data manipulation and visualization
library(dplyr) # Data manipulation
library(broom) # Statistical analysis utilities
library(reshape2) # Data reshaping
library(glmnet) # Regularized regression models
library(readr) # Data import
# Graphics
library(ggplot2) # Data visualization
library(ggridges) # Ridgeline plots
library(ggthemes) # Additional ggplot2 themes
library(ggrepel) # Label placement in ggplot2
library(ppcor) # Partial and semi-partial correlation
library(ggExtra) # Additional ggplot2 functions
library(ggsci) # Scientific journal-inspired color palettes
library(viridis) # Color palettes
library(scales) # Scale functions
library(patchwork) # Multi-plot alignment
library(ggcorrplot) # Correlation plot
library(gapminder) # Dataset used to make the box plot connected by lines
library(RColorBrewer)# Color palettes
library(plotly) # Interactive graphs
library(lubridate) # Date functions
library(stringr) # Text functions
library(extrafont) # Font customization on graphs
library(htmlwidgets) # Interactive exports
library(cowplot) # Plot arrangement
library(png) # PNG image format support
library(apyramid) # Create age pyramids
# Themes: "default", "bootstrap", "cerulean", "cosmo", "darkly", "flatly", "journal", "lumen", "paper", "readable", "sandstone", "simplex", "spacelab", "united", "yeti"
# Tables
library(kableExtra) # Table formatting
library(xtable) # Table formatting
library(reactable) # Interactive tables
library(htmltools) # HTML table formatting
# Date functions
library(anytime) # Date conversion
library(lubridate) # Date manipulation
# SlimStampen
library(SlimStampeRData) # SlimStampen-specific functions
# Dashboard
library(flexdashboard) # Dashboard creation
library(lme4)
library(sjPlot)
#prior_knowledge_analysis <- read_csv("prior_knowledge.csv", show_col_types = FALSE)
#prior_knowledge_analysis$userId <- as.factor(prior_knowledge_analysis$userId)
prior_knowledge_alldata <- read_csv("prior_knowledge_all.csv", show_col_types = FALSE)
ggplot(prior_knowledge_alldata, aes(x=answer, y=alpha, col=prior_knowledge))+
#geom_boxplot()+
geom_point(size=3, position=position_jitter(0.2)) +
#geom_line(aes(group=prior_knowledge), size=0.1, position=position_dodge(0)) +
xlab("Fact") +
ylab("SoF") +
scale_color_manual(values=c("darkblue", "lightgreen")) +
scale_fill_manual(values=c("darkblue", "lightgreen")) +
ggtitle(paste("Prior Knowledge and SoF across Facts")) +
labs(col="prior_knowledge") +
theme_hc() +
theme(legend.position = "right",
axis.text.x = element_text (angle=90),
panel.grid.major = element_blank())
ggsave("figures/Prior_Knowledge_Across_Facts.png")
#prior_knowledge_analysis <- prior_knowledge_analysis %>%
# left_join(cleandata_avg %>% select(userId, MeanAlpha))
prior_knowledge_analysis1 <- read_csv("prior_knowledge_analysis1.csv", show_col_types = FALSE)
ggplot(prior_knowledge_analysis1, aes(y = alpha, x = as.factor(userId), col = prior_knowledge, fill = prior_knowledge)) +
stat_summary(geom="point", fun.data = "mean_sdl", size=2.5) +
stat_summary(geom="ribbon", fun.data = "mean_se",
aes(group = prior_knowledge),
col = NA,
alpha = 0.25) +
stat_summary(geom="line", fun = "mean", aes(group = prior_knowledge)) +
xlab("Participant ID") +
scale_color_manual(values=c("darkblue", "lightgreen", "orange")) +
scale_fill_manual(values=c("darkblue", "lightgreen", "orange")) +
scale_x_discrete() +
ylab(expression(paste(italic("SoF")))) +
ylim(0.1, 0.5) +
ggtitle(expression(paste ("Effect of Prior Knowledge Across Participants"))) +
labs(col="Prior Knowledge", fill="Prior Knowledge") +
theme_minimal() +
theme(legend.position = "right",
axis.text.x = element_text (angle=90),
panel.grid.major = element_blank())
ggplot(prior_knowledge_alldata, aes(y = alpha, x = userId, col = prior_knowledge, fill = prior_knowledge)) +
stat_summary(geom="point", fun.data = "mean_sdl", size=2.5) +
stat_summary(geom="ribbon", fun.data = "mean_se",
aes(group = prior_knowledge),
col = NA,
alpha = 0.25) +
stat_summary(geom="line", fun = "mean", aes(group = prior_knowledge)) +
xlab("Participant ID") +
scale_color_manual(values=c("darkblue", "lightgreen")) +
scale_fill_manual(values=c("darkblue", "lightgreen")) +
scale_x_discrete() +
ylab(expression(paste(italic("SoF")))) +
ylim(0.1, 0.5) +
ggtitle(expression(paste ("Effect of Prior Knowledge Across Participants"))) +
labs(col="Prior Knowledge", fill="Prior Knowledge") +
theme_minimal() +
theme(legend.position = "right",
axis.text.x = element_text (angle=90),
panel.grid.major = element_blank())
#ggsave("figures/Prior_Knowledge_Across_Participants.png")
ggplot(prior_knowledge_alldata, aes(y = alpha, x = userId, col = prior_knowledge, fill = prior_knowledge)) +
stat_summary(geom="point", fun.data = "mean_se", size=5,
position = position_dodge()) +
stat_summary(geom="errorbar", size=0.8, color = "black", fun.data = "mean_se", aes(group = prior_knowledge)) +
xlab("Participant ID") +
scale_color_manual(values=c("darkblue", "lightgreen")) +
scale_fill_manual(values=c("darkblue", "lightgreen")) +
scale_x_discrete() +
ylab(expression(paste(italic("SoF")))) +
ylim(0, 0.5) +
ggtitle(expression(paste ("Effect of Prior Knowledge Across Participants"))) +
labs(col="Prior Knowledge", fill="Prior Knowledge") +
theme_minimal() +
theme(legend.position = "right",
axis.text.x = element_text (angle=90),
panel.grid.major = element_blank())
prior_knowledge_alldata$prior_knowledge <- factor(prior_knowledge_alldata$prior_knowledge,
levels = c("no", "yes"))
#Plot with added error bars
plot_with_stacked_bar_and_error_bars <- ggplot(prior_knowledge_alldata, aes(x = factor(userId), y = alpha, fill = prior_knowledge)) +
geom_bar(stat = "summary", fun = "mean", position = "dodge", alpha = 0.7) +
geom_errorbar(stat = "summary", fun.data = "mean_se", position = position_dodge(width = 0.75), width = 0.25, size = 0.7) +
xlab("Participant ID") +
ylab(expression(paste(italic("SoF")))) +
ylim(0.0, 0.7) +
ggtitle(expression(paste("Effect of Prior Knowledge Across Participants"))) +
scale_fill_manual(values = c("darkblue", "lightgreen")) +
labs(fill = "Prior Knowledge") +
theme_minimal() +
theme(legend.position = "right",
axis.text.x = element_text(angle = 90),
panel.grid.major = element_blank())
print(plot_with_stacked_bar_and_error_bars)
ggsave("figures/Prior_Knowledge_Across_Participants_bargraph.png")
prior_agg <- prior_knowledge_analysis %>%
group_by(userId, prior_knowledge) %>%
summarize(alpha = mean(alpha)) %>%
pivot_wider(names_from = prior_knowledge, values_from = alpha)
prior_agg <- prior_knowledge_alldata %>%
group_by(userId, prior_knowledge) %>%
summarize(alpha = mean(alpha)) %>%
pivot_wider(names_from = prior_knowledge, values_from = alpha)
ggplot(prior_agg, aes(x=no, y=yes)) +
geom_smooth(method ="lm") +
geom_point(size=4, col="blue", alpha=0.5) +
geom_text_repel(aes(label=userId)) +
xlab("SOF: Previously Unknown") +
ylab("SOF: Previously Known") +
ggtitle("SOF by Prior Knwledge") +
theme_minimal()
ggsave("figures/PriorKnowledgeCorrelations.png")
base <- lmer(alpha ~ prior_knowledge + (1|userId) +(0+prior_knowledge|userId),
prior_knowledge_analysis)
base <- lmer(alpha ~ prior_knowledge + (1|userId) +(0+prior_knowledge|userId),
prior_knowledge_alldata)
tab_model(base)
#write.csv(cleandata_lastRep, "prior_knowledge_all.csv", row.names = FALSE)
#cleandata_lastRep <- cleandata_lastRep %>%
# mutate(BLC = -log(cleandata_firstRep$reactionTime - .300))
#new_dataframe <- cleandata_avg %>%
# select(MeanAlpha, userId, lessonTitle) %>%
# mutate(prior_knowledge = "all")%>%
# mutate(factId = 11111)%>%
# mutate(answer = "ans")%>%
# rename(alpha = MeanAlpha)
scatter_plot <- ggplot(prior_knowledge_alldata, aes(x = BLC, y = alpha)) +
geom_point(data = filter(prior_knowledge_alldata, prior_knowledge == "yes"),
color = "blue") +
geom_smooth(method ="lm") +
labs(title = "Scatterplot of BLC vs. Alpha",
x = "BLC",
y = "Alpha")
correlation_result <- cor.test(prior_knowledge_alldata$BLC,
prior_knowledge_alldata$alpha)
# Add correlation coefficient to the plot
scatter_plot <- scatter_plot +
annotate("text", x = Inf, y = -Inf,
label = paste("r =", round(correlation_result$estimate, 2)),
hjust = 1, vjust = 0)
# Display the scatterplot with correlation
print(scatter_plot)
recovered_blc <- read_csv("example.csv", show_col_types = FALSE)
# Create a scatterplot
scatterplot <- ggplot(recovered_blc, aes(x = BLC, y = prior_knowledge)) +
geom_point(color = "darkblue") +
geom_smooth(method = "lm", color = "darkblue") +
labs(title = "Scatterplot of Recovered BLC vs. Prior Knowledge",
x = "BLC",
y = "Prior Knowledge")
# Calculate correlation and p-value
correlationResult <- cor.test(recovered_blc$BLC, recovered_blc$prior_knowledge)
# Add correlation coefficient and p-value to the plot
scatterplot <- scatterplot +
annotate("text", x = Inf, y = -Inf,
label = paste("r =", round(correlationResult$estimate, 2),
"\n",
"p < .0001"),
hjust = 1, vjust = -0.5)
# Display the scatterplot with correlation
print(scatterplot)
p.value <- format(correlationResult$p.value, digits = 2)
print(p.value)
ggsave("figures/recovered_blc_correlations.png")
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
# Data Manipulation and Analysis
library(tidyverse) # Data manipulation and visualization
library(dplyr) # Data manipulation
library(broom) # Statistical analysis utilities
library(reshape2) # Data reshaping
library(glmnet) # Regularized regression models
library(readr) # Data import
# Graphics
library(ggplot2) # Data visualization
library(ggridges) # Ridgeline plots
library(ggthemes) # Additional ggplot2 themes
library(ggrepel) # Label placement in ggplot2
library(ppcor) # Partial and semi-partial correlation
library(ggExtra) # Additional ggplot2 functions
library(ggsci) # Scientific journal-inspired color palettes
library(viridis) # Color palettes
library(scales) # Scale functions
library(patchwork) # Multi-plot alignment
library(ggcorrplot) # Correlation plot
library(gapminder) # Dataset used to make the box plot connected by lines
library(RColorBrewer)# Color palettes
library(plotly) # Interactive graphs
library(lubridate) # Date functions
library(stringr) # Text functions
library(extrafont) # Font customization on graphs
library(htmlwidgets) # Interactive exports
library(cowplot) # Plot arrangement
library(png) # PNG image format support
library(apyramid) # Create age pyramids
# Themes: "default", "bootstrap", "cerulean", "cosmo", "darkly", "flatly", "journal", "lumen", "paper", "readable", "sandstone", "simplex", "spacelab", "united", "yeti"
# Tables
library(kableExtra) # Table formatting
library(xtable) # Table formatting
library(reactable) # Interactive tables
library(htmltools) # HTML table formatting
# Date functions
library(anytime) # Date conversion
library(lubridate) # Date manipulation
# SlimStampen
library(SlimStampeRData) # SlimStampen-specific functions
# Dashboard
library(flexdashboard) # Dashboard creation
library(lme4)
library(sjPlot)
#prior_knowledge_analysis <- read_csv("prior_knowledge.csv", show_col_types = FALSE)
#prior_knowledge_analysis$userId <- as.factor(prior_knowledge_analysis$userId)
prior_knowledge_alldata <- read_csv("prior_knowledge_all.csv", show_col_types = FALSE)
ggplot(prior_knowledge_alldata, aes(x=answer, y=alpha, col=prior_knowledge))+
#geom_boxplot()+
geom_point(size=3, position=position_jitter(0.2)) +
#geom_line(aes(group=prior_knowledge), size=0.1, position=position_dodge(0)) +
xlab("Fact") +
ylab("SoF") +
scale_color_manual(values=c("darkblue", "lightgreen")) +
scale_fill_manual(values=c("darkblue", "lightgreen")) +
ggtitle(paste("Prior Knowledge and SoF across Facts")) +
labs(col="prior_knowledge") +
theme_hc() +
theme(legend.position = "right",
axis.text.x = element_text (angle=90),
panel.grid.major = element_blank())
ggsave("figures/Prior_Knowledge_Across_Facts.png")
#prior_knowledge_analysis <- prior_knowledge_analysis %>%
# left_join(cleandata_avg %>% select(userId, MeanAlpha))
prior_knowledge_analysis1 <- read_csv("prior_knowledge_analysis1.csv", show_col_types = FALSE)
ggplot(prior_knowledge_analysis1, aes(y = alpha, x = as.factor(userId), col = prior_knowledge, fill = prior_knowledge)) +
stat_summary(geom="point", fun.data = "mean_sdl", size=2.5) +
stat_summary(geom="ribbon", fun.data = "mean_se",
aes(group = prior_knowledge),
col = NA,
alpha = 0.25) +
stat_summary(geom="line", fun = "mean", aes(group = prior_knowledge)) +
xlab("Participant ID") +
scale_color_manual(values=c("darkblue", "lightgreen", "orange")) +
scale_fill_manual(values=c("darkblue", "lightgreen", "orange")) +
scale_x_discrete() +
ylab(expression(paste(italic("SoF")))) +
ylim(0.1, 0.5) +
ggtitle(expression(paste ("Effect of Prior Knowledge Across Participants"))) +
labs(col="Prior Knowledge", fill="Prior Knowledge") +
theme_minimal() +
theme(legend.position = "right",
axis.text.x = element_text (angle=90),
panel.grid.major = element_blank())
ggplot(prior_knowledge_alldata, aes(y = alpha, x = userId, col = prior_knowledge, fill = prior_knowledge)) +
stat_summary(geom="point", fun.data = "mean_sdl", size=2.5) +
stat_summary(geom="ribbon", fun.data = "mean_se",
aes(group = prior_knowledge),
col = NA,
alpha = 0.25) +
stat_summary(geom="line", fun = "mean", aes(group = prior_knowledge)) +
xlab("Participant ID") +
scale_color_manual(values=c("darkblue", "lightgreen")) +
scale_fill_manual(values=c("darkblue", "lightgreen")) +
scale_x_discrete() +
ylab(expression(paste(italic("SoF")))) +
ylim(0.1, 0.5) +
ggtitle(expression(paste ("Effect of Prior Knowledge Across Participants"))) +
labs(col="Prior Knowledge", fill="Prior Knowledge") +
theme_minimal() +
theme(legend.position = "right",
axis.text.x = element_text (angle=90),
panel.grid.major = element_blank())
#ggsave("figures/Prior_Knowledge_Across_Participants.png")
ggplot(prior_knowledge_alldata, aes(y = alpha, x = userId, col = prior_knowledge, fill = prior_knowledge)) +
stat_summary(geom="point", fun.data = "mean_se", size=5,
position = position_dodge()) +
stat_summary(geom="errorbar", size=0.8, color = "black", fun.data = "mean_se", aes(group = prior_knowledge)) +
xlab("Participant ID") +
scale_color_manual(values=c("darkblue", "lightgreen")) +
scale_fill_manual(values=c("darkblue", "lightgreen")) +
scale_x_discrete() +
ylab(expression(paste(italic("SoF")))) +
ylim(0, 0.5) +
ggtitle(expression(paste ("Effect of Prior Knowledge Across Participants"))) +
labs(col="Prior Knowledge", fill="Prior Knowledge") +
theme_minimal() +
theme(legend.position = "right",
axis.text.x = element_text (angle=90),
panel.grid.major = element_blank())
prior_knowledge_alldata$prior_knowledge <- factor(prior_knowledge_alldata$prior_knowledge,
levels = c("no", "yes"))
#Plot with added error bars
plot_with_stacked_bar_and_error_bars <- ggplot(prior_knowledge_alldata, aes(x = factor(userId), y = alpha, fill = prior_knowledge)) +
geom_bar(stat = "summary", fun = "mean", position = "dodge", alpha = 0.7) +
geom_errorbar(stat = "summary", fun.data = "mean_se", position = position_dodge(width = 0.75), width = 0.25, size = 0.7) +
xlab("Participant ID") +
ylab(expression(paste(italic("SoF")))) +
ylim(0.0, 0.7) +
ggtitle(expression(paste("Effect of Prior Knowledge Across Participants"))) +
scale_fill_manual(values = c("darkblue", "lightgreen")) +
labs(fill = "Prior Knowledge") +
theme_minimal() +
theme(legend.position = "right",
axis.text.x = element_text(angle = 90),
panel.grid.major = element_blank())
print(plot_with_stacked_bar_and_error_bars)
ggsave("figures/Prior_Knowledge_Across_Participants_bargraph.png")
prior_agg <- prior_knowledge_alldata %>%
group_by(userId, prior_knowledge) %>%
summarize(alpha = mean(alpha)) %>%
pivot_wider(names_from = prior_knowledge, values_from = alpha)
ggplot(prior_agg, aes(x=no, y=yes)) +
geom_smooth(method ="lm") +
geom_point(size=4, col="blue", alpha=0.5) +
geom_text_repel(aes(label=userId)) +
xlab("SOF: Previously Unknown") +
ylab("SOF: Previously Known") +
ggtitle("SOF by Prior Knwledge") +
theme_minimal()
ggsave("figures/PriorKnowledgeCorrelations.png")
base <- lmer(alpha ~ prior_knowledge + (1|userId) +(0+prior_knowledge|userId),
prior_knowledge_alldata)
tab_model(base)
#write.csv(cleandata_lastRep, "prior_knowledge_all.csv", row.names = FALSE)
#cleandata_lastRep <- cleandata_lastRep %>%
# mutate(BLC = -log(cleandata_firstRep$reactionTime - .300))
#new_dataframe <- cleandata_avg %>%
# select(MeanAlpha, userId, lessonTitle) %>%
# mutate(prior_knowledge = "all")%>%
# mutate(factId = 11111)%>%
# mutate(answer = "ans")%>%
# rename(alpha = MeanAlpha)
scatter_plot <- ggplot(prior_knowledge_alldata, aes(x = BLC, y = alpha)) +
geom_point(data = filter(prior_knowledge_alldata, prior_knowledge == "yes"),
color = "blue") +
geom_smooth(method ="lm") +
labs(title = "Scatterplot of BLC vs. Alpha",
x = "BLC",
y = "Alpha")
correlation_result <- cor.test(prior_knowledge_alldata$BLC,
prior_knowledge_alldata$alpha)
# Add correlation coefficient to the plot
scatter_plot <- scatter_plot +
annotate("text", x = Inf, y = -Inf,
label = paste("r =", round(correlation_result$estimate, 2)),
hjust = 1, vjust = 0)
# Display the scatterplot with correlation
print(scatter_plot)
recovered_blc <- read_csv("example.csv", show_col_types = FALSE)
# Create a scatterplot
scatterplot <- ggplot(recovered_blc, aes(x = BLC, y = prior_knowledge)) +
geom_point(color = "darkblue") +
geom_smooth(method = "lm", color = "darkblue") +
labs(title = "Scatterplot of Recovered BLC vs. Prior Knowledge",
x = "BLC",
y = "Prior Knowledge")
# Calculate correlation and p-value
correlationResult <- cor.test(recovered_blc$BLC, recovered_blc$prior_knowledge)
# Add correlation coefficient and p-value to the plot
scatterplot <- scatterplot +
annotate("text", x = Inf, y = -Inf,
label = paste("r =", round(correlationResult$estimate, 2),
"\n",
"p < .0001"),
hjust = 1, vjust = -0.5)
# Display the scatterplot with correlation
print(scatterplot)
p.value <- format(correlationResult$p.value, digits = 2)
print(p.value)
ggsave("figures/recovered_blc_correlations.png")
user_id_to_keep <- 83678
recovered_data_83678 <- recovered_blc[recovered_blc$Subject == user_id_to_keep, ]
ScatterPlot <- ggplot(recovered_data_83678, aes(x = Fact, y = BLC, color = factor(prior_knowledge))) +
geom_point(size = 3) + # Adjust the size of the dots
labs(title = "Participant 83678 Recovered BLC and Prior Knowledge",
x = "Fact",
y = "BLC") +
scale_color_manual(values = c("darkblue", "lightgreen")) +
theme_minimal() +
theme(legend.position = "right",
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1)) + # Rotate x-axis labels
ylim(-2, 1) # Set y-axis limits from -2 to +1
print(ScatterPlot)