-
Notifications
You must be signed in to change notification settings - Fork 0
/
Firefly_Dashboard.Rmd
executable file
·737 lines (600 loc) · 24.1 KB
/
Firefly_Dashboard.Rmd
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
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
---
title: "PriorKnowledge"
author: "Ally Williams"
date: "2023-08-01"
output: html_document
---
```{r setup, include=FALSE}
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(SlimStampenRData) # SlimStampen-specific functions
# Dashboard
library(flexdashboard) # Dashboard creation
library(lme4)
library(sjPlot)
```
### All SoF
```{r fig.width= 10, fig.height= 4.5}
cleandata_lastRep <- read_csv("cleandata_lastrep.csv")
graph=ggplot(cleandata_lastRep, aes(x=lessonId, y=alpha, col=lessonId, fill=lessonId)) +
geom_boxplot(width=.4,size=0.1, alpha=0.2) +
stat_summary(fun.y=mean, geom="pointrange", size=0.1, shape=1, color="black") +
geom_point(size=2, position=position_jitter(0.1)) +
xlab("Lesson") +
#scale_x_discrete(labels=xlabels) +
ylab("SoF") +
ylim(0.1, 0.55) +
ggtitle("Speed of Forgetting Across Lessons") +
theme_hc() +
theme(legend.position="none",
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
ggplotly(graph, tooltip=c("y", "text")) %>%
layout(legend = list(orientation = "h")) %>%
config(displayModeBar=FALSE)
```
### SoF by Lesson
```{r, echo=FALSE}
# Speed of Forgetting by Participant
graph=ggplot(cleandata_lastRep, aes(x=prior_knowledge, y=alpha, text=paste0(email))) +
geom_boxplot(size=0.1, alpha=0.2) +
geom_line(aes(group = email, col = email), size = 0.1, position = position_dodge(0)) +
geom_point(aes(col = email), size = 2, shape = 20, stroke = 0, position = position_dodge(0)) +
xlab("Lesson") +
#scale_x_discrete(labels=xlabels) +
ylab("SoF") +
ylim(0.29, 0.31) +
ggtitle("Speed of Forgetting by Participant") +
labs(fill="Participant", col="Participant") +
theme_hc() +
theme(axis.title.x=element_blank(),
panel.grid.major = element_blank(),
axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))
ggplotly(graph, tooltip=c("y", "text")) %>%
layout(legend = list(orientation = "")) %>%
config(displayModeBar=FALSE)
```
#Prior Knowledge by Fact
```{r}
ggplot(cleandata_lastRep, aes(x=answer, y=alpha, col=prior_knowledge))+
#geom_boxplot()+
geom_point(size=0.5, 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, size=8),
panel.grid.major = element_blank())
ggsave("figures/Prior_Knowledge_Across_Facts.png")
```
## Effect of prior knowledge on SOF across ppl
```{r}
ggplot(cleandata_lastRep, 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, size=5),
panel.grid.major = element_blank())
ggsave("figures/Prior_Knowledge_Across_Participants.png")
```
## Prior Knowledge across participants: point plot
```{r}
ggplot(cleandata_lastRep, aes(y = alpha, x = userId, col = prior_knowledge, fill = prior_knowledge)) +
stat_summary(geom="point", fun.data = "mean_se", size=2,
position = position_dodge()) +
stat_summary(geom="errorbar", size=0.3, 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, size=5),
panel.grid.major = element_blank())
```
##Prior Knowledge across participants: bar graph
```{r}
#Plot with added error bars
plot_with_stacked_bar_and_error_bars <- ggplot(cleandata_lastRep, 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")
```
## Correlations between known and unknwon fact SOF
Is there a correlation between the SOFs of the known and unknown facts?
```{r, fig.width=5, fig.height=5}
SOF_corr <- cleandata_lastRep %>%
group_by(userId, prior_knowledge) %>%
summarize(alpha = mean(alpha)) %>%
pivot_wider(names_from = prior_knowledge, values_from = alpha)
correlation_value <- cor(SOF_corr$no, SOF_corr$yes, use = "complete.obs")
ggplot(SOF_corr, 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") +
annotate(geom = "text", x = 0.25, y = 0.35, label = paste("r =", round(correlation_value, 2))) +
ggtitle("SOF by Prior Knowledge") +
theme_minimal()
cor_test_result <- cor.test(SOF_corr$no, SOF_corr$yes, use = "complete.obs")
p_value <- cor_test_result$p.value
print(p_value)
ggsave("figures/PriorKnowledgeCorrelations.png")
```
And finally, some MLM:
```{r}
base <- lmer(alpha ~ prior_knowledge + (1|userId) +(0+prior_knowledge|userId),
cleandata_lastRep)
tab_model(base)
```
# DOES MLE WORK???
```{r}
recovered_blc <- read_csv("optimize/results_MLE.csv", show_col_types = FALSE)
recovered_blc$answer <- tolower(recovered_blc$answer)
recovered_blc$answer <- URLdecode(recovered_blc$answer)
#recovered_blc <- recovered_blc %>%
# rename(userId = Subject) %>%
# rename(answer = Fact) %>%
# rename(lessonId = Lesson)
recovered_blc$...1 <- NULL
recovered_blc$userId <- as.character(recovered_blc$userId)
cleandata_lastRep$userId <- as.character(cleandata_lastRep$userId)
recovered_blc <- left_join(recovered_blc, cleandata_lastRep, by = c("userId", "answer"))
```
```{r}
recovered_blc <- recovered_blc %>%
mutate(prior_knowledge = if_else(prior_knowledge == "yes", 1, 0))
correlation <- ggplot(recovered_blc, aes(x = BLC, y = alpha)) +
geom_point(color = "darkblue") +
geom_smooth(method = "lm", color = "darkblue") +
labs(title = "Scatterplot of Recovered BLC vs. SOF",
x = "BLC",
y = "SOF")
# Calculate correlation and p-value
test <- cor.test(recovered_blc$BLC, recovered_blc$prior_knowledge)
# Add correlation coefficient and p-value to the plot
correlation <- correlation +
annotate("text", x = Inf, y = -Inf,
label = paste("r =", round(test$estimate, 2),
"\n",
"p < .0001"),
hjust = 1, vjust = -0.5)
# Display the scatterplot with correlation
print(correlation)
pv <- format(test$pv, digits = 2)
print(pv)
```
```{r}
# 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")
ggplot(recovered_blc %>% filter(BLC >= -1), aes(y=BLC, x=as.factor(prior_knowledge), fill=as.factor(prior_knowledge))) +
stat_summary(geom="bar", fun.data = "mean_se") +
stat_summary(geom="errorbar", fun.data = "mean_se", width=0.1) +
geom_point(position = position_jitterdodge(jitter.width = 0.2, dodge.width = 0.75), color = "black", size = 0.01) +
scale_fill_manual(values = c("darkblue", "lightgreen"), name = "Prior Knowledge Status",
labels = c("no", "yes")) +
xlab("Prior Knowledge Status") +
theme_minimal()
```
```{r}
ggplot(recovered_blc %>% filter(flags_click.time <= 15), aes(y = flags_click.time, x = as.factor(prior_knowledge), fill = as.factor(prior_knowledge))) +
stat_summary(geom = "bar", fun.data = "mean_se") +
stat_summary(geom = "errorbar", fun.data = "mean_se", width = 0.1) +
geom_point(position = position_jitterdodge(jitter.width = 0.2, dodge.width = 0.75), color = "black", size = 0.1) +
scale_fill_manual(values = c("darkblue", "lightgreen"), name = "Prior Knowledge Status",
labels = c("no", "yes")) +
xlab("Prior Knowledge Status") +
theme_minimal()
```
##Group-level BLC for each fact
```{r}
avg_BLC <- recovered_blc %>%
group_by(answer) %>%
summarize(mean_BLC = mean(BLC, na.rm = TRUE)) %>% # added na.rm = TRUE to handle any missing values
arrange(desc(mean_BLC))
# Reorder the 'answer' factor based on mean_BLC in descending order
avg_BLC$answer <- fct_reorder(avg_BLC$answer, avg_BLC$mean_BLC, .desc = TRUE)
# Create the bar graph with a gradient color from lightgreen to darkblue
ggplot(avg_BLC, aes(x = answer, y = mean_BLC, fill = mean_BLC)) +
geom_bar(stat = "identity") +
labs(title = "Average BLC for Each Fact",
x = "Fact",
y = "Average BLC") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 70, hjust = 1, vjust = 1, size = 12),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank()) +
scale_fill_gradient(low = "darkblue", high = "lightgreen")
#ggsave("figures/group-level_avgBLC.png", dpi=300)
```
##Prior knowledge across participants
```{r}
prior_knowledge_percent <- recovered_blc %>%
group_by(answer) %>%
summarize(percent_yes = mean(prior_knowledge) * 100) %>% # Calculate mean to get percentage
arrange(desc(percent_yes)) # Sort by descending percentage (optional)
# Reorder the 'answer' factor based on percent_yes in descending order (if needed)
prior_knowledge_percent$answer <- fct_reorder(prior_knowledge_percent$answer, prior_knowledge_percent$percent_yes, .desc = TRUE)
# Create the bar graph with a gradient color from lightgreen to darkblue
ggplot(prior_knowledge_percent, aes(x = answer, y = percent_yes, fill = percent_yes)) +
geom_bar(stat = "identity") +
labs(title = "Percentage of Prior Knowledge for Each Fact",
x = "Fact",
y = "Percentage of Prior Knowledge") +
theme_minimal() +
theme(
axis.text.x = element_text(angle = 70, hjust = 1, vjust = 1, size = 12), # Increase font size for x-axis labels
panel.grid.major = element_blank(),
panel.grid.minor = element_blank()
) +
scale_fill_gradient(low = "darkblue", high = "lightgreen")
ggsave("figures/grouplevel_priorknowledge.png", dpi=300)
```
## Is there a significant difference in BLC?
```{r}
base <- lmer(BLC ~ prior_knowledge + (1|userId) +(0+prior_knowledge|userId),
recovered_blc)
tab_model(base)
```
#And what is the classification accuracy (using a single threshold for all participants)?
```{r}
recovered_blc1 <- recovered_blc %>%
mutate(observed = if_else(prior_knowledge == 1, 1, -1))
curve = NULL
for (cutoff in seq(-1, 1.5, 0.1)) {
subthreshold <- recovered_blc1 %>%
mutate(prediction = ifelse(BLC <= cutoff, -1, 1)) %>%
mutate(observed = if_else(prior_knowledge == 1, 1, -1)) %>%
mutate(accuracy = ifelse(prediction == observed, 1, 0)) %>%
group_by(observed) %>%
summarise(accuracy = mean(accuracy))
tnr <- subthreshold %>%
filter(observed == -1) %>%
dplyr::select(accuracy) %>%
as.numeric()
tpr <- subthreshold %>%
filter(observed == 1) %>%
dplyr::select(accuracy) %>%
as.numeric()
partial <- tibble(Threshold = cutoff,
TNR = tnr,
TPR = tpr)
if (is.null(curve)) {
curve <- partial
} else {
curve <- rbind(curve, partial)
}
}
```
And now, we can visualize the ROC graph. First, we can compute the global AUC
```{r}
blc_AUC <- 0
step <- 0.01
for (tnr in seq(0, 1-step, step)) {
y <- curve %>% filter (TNR <= tnr) %>% filter(TNR == max(TNR)) %>% summarise(TPR = mean(TPR)) %>% as.numeric()
if (!is.nan(y)) {
blc_AUC <- blc_AUC + (y * step)
}
}
```
The global AUC is `r blc_AUC`.
```{r, fig.width=5, fig.height=5}
ggplot(arrange(curve, TPR), aes(x=TNR, y=TPR, col=Threshold)) +
geom_point(size=2, alpha=1) +
geom_line() +
geom_text_repel(aes(label=paste("BLC =", Threshold)),
direction="both",
size=3) +
ylab("Sensitivity (True Positive Rate)") +
xlab("Specificity (True Negative Rate)") +
scale_x_reverse() +
scale_color_viridis(option="viridis") +
labs(col="Recovered BLC") +
ylim(0, 1) +
xlim(1, 0) +
coord_equal() +
ggtitle("Classification Accuracy for BLC Estimates") +
geom_abline(slope=1, intercept = 1, col="grey", linetype = "dashed") +
annotate(geom="text", x=1/3, y=1/5,
label = paste("AUC = ",
round(blc_AUC, 2))) +
labs(col="BLC Threshold") +
theme_minimal() +
theme(legend.position = "bottom")
ggsave("figure8.png", dpi=300)
max_j <- curve %>%
mutate(J = TPR - (1 - TNR)) %>%
filter(J == max(J)) %>%
select(Threshold)
cat("Threshold for Maximum Youden's J Statistic:", max_j$Threshold, "\n")
```
#identifying plausible correction
```{r}
known_SOFs <- cleandata_lastRep %>%
filter(prior_knowledge == "yes")
known_SOFs <- known_SOFs %>%
group_by(userId, lessonId) %>%
summarize(mean_alpha = mean(alpha))
predicted_known_SOFs <- recovered_blc %>%
filter(BLC > 0.5)
predicted_unknown_SOFs <- recovered_blc %>%
filter(BLC <= 0.5)
avg_known <- mean(known_SOFs$mean_alpha)
avg_unknown <- mean(unknown_SOFs$mean_alpha)
avg_predicted_known <- mean(predicted_known_SOFs$alpha)
avg_predicted_unknown <- mean(predicted_unknown_SOFs$alpha)
cat("Average SOF for facts with prior knowledge:", avg_known, "\n")
cat("Average SOF for facts without prior knowledge:", avg_unknown, "\n")
cat("Average SOF for facts predicted to have prior knowledge", avg_predicted_known, "\n")
cat("Average SOF for facts predicted to not have prior knowledge", avg_predicted_unknown, "\n")
calibration_factor <- mean(.346/.227)
cat("Calibration_factor:", calibration_factor, "\n")
```
#correcting facts with predicted prior knowledge
```{r}
#corrected_values <- uncorrected_values * calibration_factor
recovered_blc_corrected <- recovered_blc %>%
mutate(alpha = ifelse(BLC > 0.5, alpha * 1.52, alpha))
```
#comparing corrected to uncorrected data
```{r}
#after correction
ggplot(recovered_blc_corrected, aes(y = alpha, x = as.factor(userId), col = factor(prior_knowledge), fill = factor(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 ("Corrected Prior Knowledge Data"))) +
labs(col="Prior Knowledge", fill="Prior Knowledge") +
theme_minimal() +
theme(legend.position = "right",
axis.text.x = element_text (angle=90, size=5),
panel.grid.major = element_blank())
#original plot
ggplot(cleandata_lastRep, 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 ("Original 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, size=5),
panel.grid.major = element_blank())
```
# Andy's section
## New figure Global Results
A new figure for the global results
```{r, fig.width=5, fig.height=5}
adata <- cleandata_lastRep %>%
group_by(userId, prior_knowledge) %>%
summarise(SoF = mean(alpha))
ggplot(adata, aes(x=prior_knowledge, y=SoF,
col=prior_knowledge, fill= prior_knowledge)) +
geom_line(aes(group=userId), color="grey", size=0.25) +
stat_summary(geom="point", fun.data = "mean_se", size=3) +
stat_summary(geom="errorbar", fun.data ="mean_sdl", width=0.1) +
geom_boxplot(alpha=0.25) +
scale_color_manual(values=c("darkblue", "lightgreen", "orange")) +
scale_fill_manual(values=c("darkblue", "lightgreen", "orange")) +
labs(col="Previously Known?") +
xlab("Previously Known?") +
ylab("Speed of Forgetting (SoF)") +
ggtitle("Effect of Prior Knowledge on SoF Estimates") +
theme_minimal() +
guides(fill="none") +
theme(legend.position = "bottom")
ggsave(filename="figure5.png", dpi=300)
```
## Correlations
```{r, fig.width=5, fig.height=5}
adata_w <- adata %>% pivot_wider(values_from = SoF, names_from = prior_knowledge)
ggplot(adata_w, aes(x = no, y = yes)) +
scale_x_continuous() +
scale_y_continuous() +
coord_equal() +
#coord_cartesian(xlim=c(0.15, 0.38), ylim=c(0.15, 0.38),) +
geom_smooth(method = "lm", fullrange=TRUE, fill="grey") +
geom_point(size = 4, col="blue", alpha = 0.5) +
xlab("SoF: Previously Unknown") +
ylab("SoF: Previously Known") +
ggtitle("SoF by Prior Knowledge") +
geom_abline(slope=1, intercept = 0, col="black", linetype="dashed") +
theme_minimal() +
annotate(geom="text", x=0.275, y=0.325, label=paste("r(70) = ", round(cor(adata_w$yes,
adata_w$no),
2))) +
theme(aspect.ratio = 1)
ggsave(filename="figure6.png", dpi = 300)
```
## BLC
```{r, fig.width=5, fig.height=5}
blcdata <-recovered_blc_corrected %>%
mutate(prior = if_else(prior_knowledge == 0, "no", "yes")) %>%
group_by(userId, prior) %>%
summarise(BLC = mean(BLC))
ggplot(blcdata, aes(x=prior, y=BLC,
col=prior, fill= prior)) +
geom_line(aes(group=userId), color="grey", size=0.25) +
stat_summary(geom="point", fun.data = "mean_se", size=3) +
#stat_summary(geom="errorbar", fun.data ="mean_sdl", width=0.1) +
geom_boxplot(alpha=0.3) +
scale_color_manual(values=c("darkblue", "lightgreen", "orange")) +
scale_fill_manual(values=c("darkblue", "lightgreen", "orange")) +
labs(col="Previously Known?") +
xlab("Previously Known?") +
ylab("MLE Estimates of BLC") +
ggtitle("MLE-Recovered BLC Values") +
theme_minimal() +
guides(fill="none") +
theme(legend.position = "bottom")
ggsave("figure7.png")
```
```{r}
t.test(BLC ~ prior, paired=T, data=blcdata)
```
##
Previous knowledge can be approximated as a constant
```{r, fig.width=5, fig.height=5}
month <- 60*60*24*30
year <- month * 12
delta <- 60*60
time <- seq(1, month, delta)
gen_traces <- function(n, within=month) {
timestep <- within / n
seq(0, within-timestep, timestep)
}
activation <- function(t, traces) {
timeline <- seq(1, t-delta, delta)
activations <- c(1)
for (time in timeline) {
O <- 0
d = 0.3
for (trace in traces) {
if (trace < time) {
O <- O +(time - trace)**-d
d <- 0.5 * O + 0.3
}
}
activations <- append(activations, log(O))
}
activations
}
#plot(activation(30000, traces=c(1, 2000, 50000)), type="l")
time <- seq(1, month*12, delta)
n1 <- activation(month*12, traces=gen_traces(1))
n10 <- activation(month*12, traces=gen_traces(10))
n100 <- activation(month*12, traces=gen_traces(100))
df <- data.frame(Time=time, N1 = n1, N10 = n10, N100 = n100)
activations <- tibble(df)
lactivations <- activations %>% pivot_longer(cols = c("N1", "N10", "N100"),
values_to = "Activation",
names_to = "NEncodings") %>%
mutate(Encodings = if_else(NEncodings == "N1", "1", if_else(NEncodings=="N10", "10", "100")))
ggplot(lactivations, aes(x=Time, y=Activation, col=Encodings)) +
geom_line() +
scale_x_continuous(breaks=seq(1,12)*month,
labels = paste(seq(1,12))) +
xlab("Time (Months)") +
ggtitle("Simulated Effect of Prior Knowledge Over Time") +
scale_color_viridis(discrete=T, end=0.8) +
theme_minimal() +
theme(legend.position = "bottom")
ggsave("figure2.png", dpi=300)
```
# MLM Model
Random slope model.
```{r}
base <- lmer(alpha ~ prior_knowledge
+ (1|userId) # Intercept
+ (0+prior_knowledge|userId), # Slope
recovered_blc_corrected)
tab_model(base)
```