Note: _NN variable means non-normalized (w/o dividing by n_series or n_letters)

library(knitr)
library(dplyr)
library(htmlTable)
aospan_df <- read.csv("../../data/gorilla/cleaned_data/AOSPAN_scores.csv")
math_df <- read.csv("../../data/gorilla/cleaned_data/memory_math_task_cleaned.csv")
exc_id <- "9x66hax0"  # exclude Christina's data
math_df <- math_df %>% 
  filter(Participant.Public.ID != exc_id)
aospan_df <- aospan_df %>% 
  filter(Participant.Public.ID != exc_id) %>% 
  rename(PC_Unit_score = PC_unit_score, PC_Load_score = PC_load_score) %>% 
  mutate(
    AON_Unit_score_NN = AON_Unit_score * n_series,
    AON_Load_score_NN = AON_Load_score * n_letters_total,
    PC_Unit_score_NN = PC_Unit_score * n_series,
    PC_Load_score_NN = PC_Load_score * n_letters_total)
f <- function(X, FUN, ...) {
  fn <- as.character(match.call()$FUN)[-1]
  out <- sapply(FUN, mapply, X, ...)
  setNames(as.data.frame(out), fn)
}

plot_distributions <- function(type, vals){
  par(mfrow=c(1, length(vals)))
  for (val in vals){
    hist(
      aospan_df[aospan_df$type == type, val],
      main = NULL, xlab = val, col = "lightblue")
    abline(
      v = mean(aospan_df[aospan_df$type == type, val]),
      col = 2, lty = 2, lwd = 2)
    abline(
      v = median(aospan_df[aospan_df$type == type, val]),
      col = 3, lty = 2, lwd = 2)
  }
  
  legend(
    "topright",
    legend = c("Mean", "Median"),
    col = c(2, 3),
    lty = c(2, 2),
    lwd = c(2, 2),
    cex = 0.8
  )
}

clmns_to_keep <- c(
  "Correct_count", "Ratio_equations_correct", "AON_n_letters_correct", 
  "AON_Unit_score", "AON_Unit_score_NN", "AON_Load_score", "AON_Load_score_NN", 
  "PC_n_letters_correct_total",
  "PC_Unit_score", "PC_Unit_score_NN", "PC_Load_score", "PC_Load_score_NN"
)

Summary Statistics

Task

out <- round(
  f(
    aospan_df[aospan_df$type == "task", clmns_to_keep], 
    list(mean, sd, min, median, max)),
  2)

htmlTable(out, cgroup = 'Statistic', n.cgroup = 5, caption = 'Table 1: Task',
          ## padding to cells: top side bottom
          css.cell = 'padding: 0px 10px 0px;')
Table 1: Task
Statistic
mean sd min median max
Correct_count 10.1 3.25 3 11 14
Ratio_equations_correct 0.95 0.04 0.85 0.96 1
AON_n_letters_correct 46.14 18.11 11 50 71
AON_Unit_score 0.67 0.22 0.2 0.73 0.93
AON_Unit_score_NN 10.1 3.25 3 11 14
AON_Load_score 0.62 0.24 0.15 0.67 0.95
AON_Load_score_NN 46.14 18.11 11 50 71
PC_n_letters_correct_total 59.48 13.6 28 61 74
PC_Unit_score 0.82 0.16 0.42 0.86 0.99
PC_Unit_score_NN 12.36 2.41 6.36 12.86 14.86
PC_Load_score 0.79 0.18 0.37 0.81 0.99
PC_Load_score_NN 59.48 13.6 28 61 74

Practice

out <- round(
  f(
    aospan_df[aospan_df$type == "practice", clmns_to_keep], 
    list(mean, sd, min, median, max)),
  2)

htmlTable(out, cgroup = 'Statistic', n.cgroup = 5, caption = 'Table 2: Practice',
          ## padding to cells: top side bottom
          css.cell = 'padding: 0px 10px 0px;')
Table 2: Practice
Statistic
mean sd min median max
Correct_count 7.38 0.59 6 7 8
Ratio_equations_correct 0.95 0.06 0.81 0.95 1
AON_n_letters_correct 21.81 1.99 19 21 24
AON_Unit_score 0.92 0.07 0.75 0.88 1
AON_Unit_score_NN 7.38 0.59 6 7 8
AON_Load_score 0.91 0.08 0.79 0.88 1
AON_Load_score_NN 21.81 1.99 19 21 24
PC_n_letters_correct_total 22.71 1.49 19 23 24
PC_Unit_score 0.95 0.06 0.75 0.97 1
PC_Unit_score_NN 7.62 0.5 6 7.75 8
PC_Load_score 0.95 0.06 0.79 0.96 1
PC_Load_score_NN 22.71 1.49 19 23 24

Distributions

Task

All-or-nothing

plot_distributions(type = "task", vals = c("AON_Unit_score", "AON_Load_score"))

All-or-nothing (NN)

plot_distributions(type = "task", vals = c("AON_Unit_score_NN", "AON_Load_score_NN"))

Partial-credit

plot_distributions(type = "task", vals = c("PC_Unit_score", "PC_Load_score"))

Partial-credit (NN)

plot_distributions(type = "task", vals = c("PC_Unit_score_NN", "PC_Load_score_NN"))

Ratio of Correct Equations

Number of subjects below 85%:

cat(sum(aospan_df[aospan_df$type == "task", "Ratio_equations_correct"] < 0.85))
## 0
plot_distributions(type = "task", vals = c("Ratio_equations_correct"))

Practice

All-or-nothing

plot_distributions(type = "practice", vals = c("AON_Unit_score", "AON_Load_score"))

All-or-nothing (NN)

plot_distributions(type = "practice", vals = c("AON_Unit_score_NN", "AON_Load_score_NN"))

Partial-credit

plot_distributions(type = "practice", vals = c("PC_Unit_score", "PC_Load_score"))

Partial-credit (NN)

plot_distributions(type = "practice", vals = c("PC_Unit_score_NN", "PC_Load_score_NN"))

Ratio of Correct Equations

Number of subjects below 85%:

cat(sum(aospan_df[aospan_df$type == "practice", "Ratio_equations_correct"] < 0.85))
## 1
plot_distributions(type = "practice", vals = c("Ratio_equations_correct"))

Misc

Ratio of Correct Sequences

temp_df <- math_df %>% 
  filter(type == "task", display == "recall4") %>% 
  group_by(length) %>% 
  summarize(Correct_Seq_Ratio = mean(Correct))

barplot(
  height = temp_df$Correct_Seq_Ratio, names = temp_df$length, 
  col="lightblue", xlab = "Length", ylab = "Ratio of Correct Sequences")

Ratio of Correct Equations

temp_df <- math_df %>% 
  filter(type == "task", display == "trial") %>% 
  group_by(length) %>% 
  summarize(Correct_Seq_Ratio = mean(Correct))

barplot(
  height = temp_df$Correct_Seq_Ratio, names = temp_df$length, 
  col="lightblue", xlab = "Length", ylab = "Ratio of Correct Equations")

Score vs Correct Equations

par(mfrow=c(2, 2))
for (val in c("AON_Unit_score_NN", "AON_Load_score_NN", "PC_Unit_score_NN", "PC_Load_score_NN")){
  plot(
    aospan_df[aospan_df$type == "task", val],
    aospan_df[aospan_df$type == "task", "Ratio_equations_correct"],
    col = 4, lwd = 3, frame.plot=FALSE,
    xlab = val, ylab = "Ratio_equations_correct")
}