Load task and task outcome data
# outcomes %>% select(adid, ftldcdr_global)tr
outcomes = read_excel(path = "C:/Users/mark/Documents/Current Projects/Reliability/reliability_analysis_for_validation_manuscript_09.2023/update datasets 100320223/mobile_mApp_baseline_validation_manuscript_10.02.2023.xlsx") %>%
mutate(first_login = ymd(first_login)) %>%
filter(!(prim_language %in% c("Spanish", "Russian", "Other")))
outcomes= outcomes %>%
mutate(stroop_correct_n = as.numeric(stroop_correct_n),
stroop_speed_accuracy=as.numeric(stroop_speed_accuracy),
flanker_total_time=as.numeric(flanker_total_time),
flanker_speed_accuracy=as.numeric(flanker_speed_accuracy),
gonogo_cor_hits_min_inc_rej=as.numeric(gonogo_cor_hits_min_inc_rej),
humi_corr_by_chap=as.numeric(humi_corr_by_chap),
nback_dprime=as.numeric(nback_dprime),
card_total_rounds=as.numeric(card_total_rounds)
)
## Warning: There were 8 warnings in `mutate()`.
## The first warning was:
## ℹ In argument: `stroop_correct_n = as.numeric(stroop_correct_n)`.
## Caused by warning:
## ! NAs introduced by coercion
## ℹ Run `dplyr::last_dplyr_warnings()` to see the 7 remaining warnings.
#############################################
#############################################
#############################################
#############################################
outcomes = outcomes %>%
filter(new_cohort==0 | new_cohort==1) # so can adjust based on if want new cohort or not.
#############################################
#############################################
#############################################
#############################################
# outcomes_stroop %>% View()
outcomes_stroop = outcomes %>%
select(adid, visit_chapter, participant_id,
chapter_adjusted, stroop_correct_n, stroop_speed_accuracy) %>%
filter(!is.na(stroop_correct_n)) %>%
arrange(adid, chapter_adjusted) %>%
group_by(adid) %>%
mutate(task_iteration = row_number()) %>%
select(adid, visit_chapter, participant_id, task_iteration, stroop_correct_n, stroop_speed_accuracy) #first time person got the task is now "task_iteration", some of the task outcome names are not current. so line 46 will need change names. They're similar though. Longer names.
outcomes_stroop_first_itrn = outcomes_stroop %>% filter(task_iteration == 1) %>%
ungroup() %>%
select(participant_id, visit_chapter) #this is new dataset with first iteration.
outcomes_flanker = outcomes %>%
select(adid, visit_chapter, participant_id,
chapter_adjusted, flanker_total_time, flanker_speed_accuracy) %>%
filter(!is.na(flanker_total_time)) %>%
arrange(adid, chapter_adjusted) %>%
group_by(adid) %>%
mutate(task_iteration = row_number()) %>%
select(adid, visit_chapter, participant_id, task_iteration, flanker_total_time, flanker_speed_accuracy)
outcomes_flanker_first_itrn = outcomes_flanker %>% filter(task_iteration == 1) %>%
ungroup() %>%
select(participant_id, visit_chapter)
outcomes_gonogo = outcomes %>%
select(adid, visit_chapter, participant_id,
chapter_adjusted, gonogo_cor_hits_min_inc_rej) %>%
filter(!is.na(gonogo_cor_hits_min_inc_rej)) %>%
arrange(adid, chapter_adjusted) %>%
group_by(adid) %>%
mutate(task_iteration = row_number()) %>%
select(adid, visit_chapter, participant_id, task_iteration, gonogo_cor_hits_min_inc_rej)
outcomes_gonogo_first_itrn = outcomes_gonogo %>% filter(task_iteration == 1) %>%
ungroup() %>%
select(participant_id, visit_chapter)
outcomes_humi = outcomes %>%
select(adid, visit_chapter, participant_id,
chapter_adjusted, humi_corr_by_chap) %>%
filter(!is.na(humi_corr_by_chap)) %>%
arrange(adid, chapter_adjusted) %>%
group_by(adid) %>%
mutate(task_iteration = row_number()) %>%
select(adid, visit_chapter, participant_id, task_iteration, humi_corr_by_chap)
outcomes_humi_first_itrn = outcomes_humi %>% filter(task_iteration == 1) %>%
ungroup() %>%
select(participant_id, visit_chapter)
outcomes_nback = outcomes %>%
select(adid, visit_chapter, participant_id,
chapter_adjusted, nback_dprime) %>%
filter(!is.na(nback_dprime)) %>%
arrange(adid, chapter_adjusted) %>%
group_by(adid) %>%
mutate(task_iteration = row_number()) %>%
select(adid, visit_chapter, participant_id, task_iteration, nback_dprime)
outcomes_nback_first_itrn = outcomes_nback %>% filter(task_iteration == 1) %>%
ungroup() %>%
select(participant_id, visit_chapter)
outcomes_card = outcomes %>%
select(adid, visit_chapter, participant_id,
chapter_adjusted, card_total_rounds) %>%
filter(!is.na(card_total_rounds)) %>%
arrange(adid, chapter_adjusted) %>%
group_by(adid) %>%
mutate(task_iteration = row_number()) %>%
select(adid, visit_chapter, participant_id, task_iteration, card_total_rounds)
outcomes_card_first_itrn = outcomes_card %>% filter(task_iteration == 1) %>%
ungroup() %>%
select(participant_id, visit_chapter) #this isn't the raw data here, this is an index for if they have data at that timepoint.
outcomes_task_itrn = outcomes %>% select(adid) %>% unique()
outcomes_task_itrn =
outcomes_task_itrn %>%
full_join(outcomes_stroop %>% select(-visit_chapter, -participant_id), by = "adid") %>%
mutate(task_iteration = as.numeric(task_iteration),
task_iteration = if_else(is.na(task_iteration), 1, task_iteration)) %>%
full_join(outcomes_flanker %>% select(-visit_chapter, -participant_id), by = c("adid", "task_iteration")) %>%
full_join(outcomes_gonogo %>% select(-visit_chapter, -participant_id), by = c("adid", "task_iteration")) %>%
full_join(outcomes_humi %>% select(-visit_chapter, -participant_id), by = c("adid", "task_iteration")) %>%
full_join(outcomes_nback %>% select(-visit_chapter, -participant_id), by = c("adid", "task_iteration")) %>%
full_join(outcomes_card %>% select(-visit_chapter, -participant_id), by = c("adid", "task_iteration")) %>%
arrange(adid, task_iteration) #joining together all task outcomes that are reindexed with "task iteration" as opposed to chapter number. Should range 1-3, if no value then didn't comeplte that task once within Visit 1.
## full task datasets
# outcomes_stroop_first_itrn
#these are in box folder. Will have to change file paths.
stroop = read_csv(file = "C:/Users/mark/Documents/Current Projects/Reliability/reliability_analysis_for_validation_manuscript_09.2023/combined_tasks/stroop_raw_combined_202210.csv") %>%
inner_join(outcomes_stroop_first_itrn, by = c("participant_id", "visit_chapter")) #only pull raw data from first iteration of the task.
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
## dat <- vroom(...)
## problems(dat)
flanker = read_csv(file = "C:/Users/mark/Documents/Current Projects/Reliability/reliability_analysis_for_validation_manuscript_09.2023/combined_tasks/flanker_raw_combined_202210.csv") %>%
inner_join(outcomes_flanker_first_itrn, by = c("participant_id", "visit_chapter"))
gonogo = read_csv(file = "C:/Users/mark/Documents/Current Projects/Reliability/reliability_analysis_for_validation_manuscript_09.2023/combined_tasks/gonogo_raw_combined_202210.csv") %>%
inner_join(outcomes_gonogo_first_itrn, by = c("participant_id", "visit_chapter"))
humi = read_csv(file = "C:/Users/mark/Documents/Current Projects/Reliability/reliability_analysis_for_validation_manuscript_09.2023/combined_tasks/humi_raw_combined_202210.csv") %>%
inner_join(outcomes_humi_first_itrn, by = c("participant_id", "visit_chapter"))
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
## dat <- vroom(...)
## problems(dat)
nback = read_csv(file = "C:/Users/mark/Documents/Current Projects/Reliability/reliability_analysis_for_validation_manuscript_09.2023/combined_tasks/nback_raw_combined_202210.csv") %>%
inner_join(outcomes_nback_first_itrn, by = c("participant_id", "visit_chapter"))
card = read_csv(file = "C:/Users/mark/Documents/Current Projects/Reliability/reliability_analysis_for_validation_manuscript_09.2023/combined_tasks/card_raw_combined_202210.csv") %>%
inner_join(outcomes_card_first_itrn, by = c("participant_id", "visit_chapter"))
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
## dat <- vroom(...)
## problems(dat)
#was some sort of QC, shouldn't be an issue. Count should never be more than 1. If it does then run deduping, or can just run depuping anyhow.
#file name may be in different format if this doesn't work. Can ask Clayton if issues.
stroop %>% group_by(participant_id) %>% count() %>% arrange(desc(n))
## # A tibble: 222 × 2
## # Groups: participant_id [222]
## participant_id n
## <dbl> <int>
## 1 9218 181
## 2 5393 135
## 3 7843 120
## 4 9476 118
## 5 7730 112
## 6 9018 112
## 7 6466 111
## 8 8860 110
## 9 7287 109
## 10 8376 109
## # ℹ 212 more rows
stroop %>% group_by(participant_id, file_name) %>% count() %>% arrange(desc(n))
## # A tibble: 223 × 3
## # Groups: participant_id, file_name [223]
## participant_id file_name n
## <dbl> <chr> <int>
## 1 5393 participant5393_2021-08-06 16꞉52꞉52.csv 135
## 2 7843 participant7843_2022-01-22 15꞉39꞉37.csv 120
## 3 9476 participant9476_2022-08-10 13꞉50꞉35.csv 118
## 4 7730 participant7730_2022-01-07 06꞉06꞉02.csv 112
## 5 9018 participant9018_2022-06-08 16꞉49꞉00.csv 112
## 6 6466 participant6466_2021-09-13 15꞉31꞉08.csv 111
## 7 8860 participant8860_2022-05-13 00꞉45꞉19.csv 110
## 8 7287 participant7287_2021-11-16 01꞉44꞉53.csv 109
## 9 8376 participant8376_2022-03-19 14꞉10꞉35.csv 109
## 10 9040 participant9040_2022-05-29 17꞉13꞉39.csv 107
## # ℹ 213 more rows
flanker %>% group_by(participant_id) %>% count() %>% arrange(desc(n))
## # A tibble: 279 × 2
## # Groups: participant_id [279]
## participant_id n
## <dbl> <int>
## 1 9582 220
## 2 765 110
## 3 782 110
## 4 783 110
## 5 785 110
## 6 815 110
## 7 818 110
## 8 819 110
## 9 848 110
## 10 849 110
## # ℹ 269 more rows
flanker %>% group_by(participant_id, file_name) %>% count() %>% arrange(desc(n))
## # A tibble: 280 × 3
## # Groups: participant_id, file_name [280]
## participant_id file_name n
## <dbl> <chr> <int>
## 1 765 participant765.csv 110
## 2 782 participant782.csv 110
## 3 783 participant783.csv 110
## 4 785 participant785.csv 110
## 5 815 participant815.csv 110
## 6 818 participant818.csv 110
## 7 819 participant819.csv 110
## 8 848 participant848.csv 110
## 9 849 participant849.csv 110
## 10 867 participant867.csv 110
## # ℹ 270 more rows
humi %>% group_by(participant_id) %>% count() %>% arrange(desc(n))
## # A tibble: 276 × 2
## # Groups: participant_id [276]
## participant_id n
## <dbl> <int>
## 1 8376 78
## 2 8410 78
## 3 9273 78
## 4 7287 76
## 5 9038 76
## 6 868 75
## 7 2040 75
## 8 4567 74
## 9 6466 74
## 10 8697 74
## # ℹ 266 more rows
humi %>% group_by(participant_id, file_name) %>% count() %>% arrange(desc(n))
## # A tibble: 276 × 3
## # Groups: participant_id, file_name [276]
## participant_id file_name n
## <dbl> <chr> <int>
## 1 8376 participant8376_2022-03-20 22꞉08꞉42.csv 78
## 2 8410 participant8410_2022-03-30 22꞉03꞉43.csv 78
## 3 9273 participant9273_2022-07-13 20꞉10꞉11.csv 78
## 4 7287 participant7287_2021-11-16 21꞉10꞉34.csv 76
## 5 9038 participant9038_2022-05-29 02꞉59꞉47.csv 76
## 6 868 participant868.csv 75
## 7 2040 participant2040_2020-07-28 02꞉05꞉07.csv 75
## 8 4567 participant4567_2021-06-04 01꞉02꞉52.csv 74
## 9 6466 participant6466_2021-09-15 00꞉05꞉54.csv 74
## 10 8697 participant8697_2022-04-24 20꞉19꞉12.csv 74
## # ℹ 266 more rows
gonogo %>% group_by(participant_id) %>% count() %>% arrange(desc(n))
## # A tibble: 255 × 2
## # Groups: participant_id [255]
## participant_id n
## <dbl> <int>
## 1 9575 198
## 2 1018 101
## 3 2245 101
## 4 8907 101
## 5 2157 100
## 6 2304 100
## 7 4729 100
## 8 5265 100
## 9 6506 100
## 10 7420 100
## # ℹ 245 more rows
gonogo %>% group_by(participant_id, file_name) %>% count() %>% arrange(desc(n))
## # A tibble: 256 × 3
## # Groups: participant_id, file_name [256]
## participant_id file_name n
## <dbl> <chr> <int>
## 1 1018 participant1018.csv 101
## 2 2245 participant2245_2020-09-14 22꞉26꞉33.csv 101
## 3 8907 participant8907_2022-05-26 16꞉55꞉27.csv 101
## 4 2157 participant2157_2020-08-20 18꞉34꞉00.csv 100
## 5 2304 participant2304_2020-09-16 21꞉43꞉13.csv 100
## 6 4729 participant4729_2021-06-11 01꞉17꞉48.csv 100
## 7 5265 participant5265_2021-07-23 18꞉36꞉58.csv 100
## 8 6506 participant6506_2021-09-23 01꞉30꞉46.csv 100
## 9 7420 participant7420_2021-12-02 02꞉04꞉33.csv 100
## 10 8232 participant8232_2022-03-19 15꞉14꞉53.csv 100
## # ℹ 246 more rows
card %>% group_by(participant_id) %>% count() %>% arrange(desc(n))
## # A tibble: 220 × 2
## # Groups: participant_id [220]
## participant_id n
## <dbl> <int>
## 1 2037 48
## 2 2130 48
## 3 2131 48
## 4 2245 48
## 5 2448 48
## 6 2520 48
## 7 2616 48
## 8 2670 48
## 9 2728 48
## 10 2921 48
## # ℹ 210 more rows
card %>% group_by(participant_id, file_name) %>% count() %>% arrange(desc(n))
## # A tibble: 220 × 3
## # Groups: participant_id, file_name [220]
## participant_id file_name n
## <dbl> <chr> <int>
## 1 2037 participant2037_2020-07-27 21꞉36꞉19.csv 48
## 2 2130 participant2130_2020-08-16 03꞉23꞉46.csv 48
## 3 2131 participant2131_2020-08-15 19꞉17꞉17.csv 48
## 4 2245 participant2245_2020-09-12 12꞉24꞉17.csv 48
## 5 2448 participant2448_2020-10-07 22꞉02꞉07.csv 48
## 6 2520 participant2520_2020-10-12 17꞉14꞉33.csv 48
## 7 2616 participant2616_2020-10-21 19꞉22꞉31.csv 48
## 8 2670 participant2670_2020-10-27 00꞉08꞉11.csv 48
## 9 2728 participant2728_2020-11-05 21꞉34꞉10.csv 48
## 10 2921 participant2921_2020-11-16 23꞉00꞉18.csv 48
## # ℹ 210 more rows
nback %>% group_by(participant_id) %>% count() %>% arrange(desc(n))
## # A tibble: 215 × 2
## # Groups: participant_id [215]
## participant_id n
## <dbl> <int>
## 1 8928 114
## 2 785 113
## 3 2040 113
## 4 3155 113
## 5 4465 113
## 6 4478 113
## 7 4855 113
## 8 6944 113
## 9 8373 113
## 10 8383 113
## # ℹ 205 more rows
nback %>% group_by(participant_id, file_name) %>% count() %>% arrange(desc(n))
## # A tibble: 215 × 3
## # Groups: participant_id, file_name [215]
## participant_id file_name n
## <dbl> <chr> <int>
## 1 8928 participant8928_2022-05-21 01꞉39꞉30.csv 114
## 2 785 participant785.csv 113
## 3 2040 participant2040_2020-07-28 02꞉12꞉23.csv 113
## 4 3155 participant3155_2020-12-26 22꞉23꞉39.csv 113
## 5 4465 participant4465_2021-05-11 20꞉51꞉23.csv 113
## 6 4478 participant4478_2021-05-13 15꞉35꞉48.csv 113
## 7 4855 participant4855_2021-07-16 18꞉05꞉49.csv 113
## 8 6944 participant6944_2021-12-01 14꞉53꞉55.csv 113
## 9 8373 participant8373_2022-03-19 22꞉25꞉58.csv 113
## 10 8383 participant8383_2022-03-23 05꞉57꞉27.csv 113
## # ℹ 205 more rows
stroop_dedupe =
stroop %>% select(participant_id, file_name) %>% unique() %>%
mutate(file_name2 = file_name) %>%
separate(file_name2, into = c("a", "b"), sep = "_") %>%
separate(b, into = "b", sep = ".csv", extra = "drop") %>%
mutate(date = ymd_hms(b)) %>%
select(-a, -b) %>%
arrange(participant_id, date) %>%
group_by(participant_id) %>%
mutate(index = row_number())
## Warning: Expected 2 pieces. Missing pieces filled with `NA` in 18 rows [1, 2, 3, 4, 5,
## 6, 7, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223].
stroop =
stroop %>%
left_join(stroop_dedupe, by = c("participant_id", "file_name")) %>%
filter(index == 1)
flanker_dedupe =
flanker %>% select(participant_id, file_name) %>% unique() %>%
mutate(file_name2 = file_name) %>%
separate(file_name2, into = c("a", "b"), sep = "_") %>%
separate(b, into = "b", sep = ".csv", extra = "drop") %>%
mutate(date = ymd_hms(b)) %>%
select(-a, -b) %>%
arrange(participant_id, date) %>%
group_by(participant_id) %>%
mutate(index = row_number())
## Warning: Expected 2 pieces. Missing pieces filled with `NA` in 18 rows [1, 2, 3, 4, 5,
## 6, 7, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280].
flanker =
flanker %>%
left_join(flanker_dedupe, by = c("participant_id", "file_name")) %>%
filter(index == 1)
gonogo_dedupe =
gonogo %>% select(participant_id, file_name) %>% unique() %>%
mutate(file_name2 = file_name) %>%
separate(file_name2, into = c("a", "b"), sep = "_") %>%
separate(b, into = "b", sep = ".csv", extra = "drop") %>%
mutate(date = ymd_hms(b)) %>%
select(-a, -b) %>%
arrange(participant_id, date) %>%
group_by(participant_id) %>%
mutate(index = row_number())
## Warning: Expected 2 pieces. Missing pieces filled with `NA` in 7 rows [1, 2, 3, 4, 5, 6,
## 7].
gonogo =
gonogo %>%
left_join(gonogo_dedupe, by = c("participant_id", "file_name")) %>%
filter(index == 1)
humi_dedupe =
humi %>% select(participant_id, file_name) %>% unique() %>%
mutate(file_name2 = file_name) %>%
separate(file_name2, into = c("a", "b"), sep = "_") %>%
separate(b, into = "b", sep = ".csv", extra = "drop") %>%
mutate(date = ymd_hms(b)) %>%
select(-a, -b) %>%
arrange(participant_id, date) %>%
group_by(participant_id) %>%
mutate(index = row_number())
## Warning: Expected 2 pieces. Missing pieces filled with `NA` in 18 rows [1, 2, 3, 4, 5,
## 6, 7, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276].
humi =
humi %>%
left_join(humi_dedupe, by = c("participant_id", "file_name")) %>%
filter(index == 1)
nback_dedupe =
nback %>% select(participant_id, file_name) %>% unique() %>%
mutate(file_name2 = file_name) %>%
separate(file_name2, into = c("a", "b"), sep = "_") %>%
separate(b, into = "b", sep = ".csv", extra = "drop") %>%
mutate(date = ymd_hms(b)) %>%
select(-a, -b) %>%
arrange(participant_id, date) %>%
group_by(participant_id) %>%
mutate(index = row_number())
## Warning: Expected 2 pieces. Missing pieces filled with `NA` in 18 rows [1, 2, 3, 4, 5,
## 6, 7, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215].
nback =
nback %>%
left_join(nback_dedupe, by = c("participant_id", "file_name")) %>%
filter(index == 1)
card_dedupe =
card %>% select(participant_id, file_name) %>% unique() %>%
mutate(file_name2 = file_name) %>%
separate(file_name2, into = c("a", "b"), sep = "_") %>%
separate(b, into = "b", sep = ".csv", extra = "drop") %>%
mutate(date = ymd_hms(b)) %>%
select(-a, -b) %>%
arrange(participant_id, date) %>%
group_by(participant_id) %>%
mutate(index = row_number())
card =
card %>%
left_join(card_dedupe, by = c("participant_id", "file_name")) %>%
filter(index == 1)
library(ICC)
# ICCest(adid, stp_tot_corr_wo_to , data = outcomes_task_itrn)
#stroop_correct_n, stroop_speed_accuracy
icc.row<-c("stroop_speed_accuracy","flanker_speed_accuracy",
"gonogo_cor_hits_min_inc_rej","humi_corr_by_chap","nback_dprime")
icc.col<- c("ICC", "LCI","UCI","Sample Size")
icc_matrix<-matrix(nrow = 5, ncol = 4, dimnames = list(icc.row, icc.col))
ICC.stroop_speed_accuracy<-ICCest(adid, stroop_speed_accuracy , data = outcomes_task_itrn) #this data is not raw, just the outcomes.
## NAs removed from rows:
## 55 56 57 81 85 86 87 91 101 102 103 104 105 106 107 108 109 110 135 136 137 141 142 143 155 156 175 176 177 188 189 190 191 192 193 201 202 208 209 210 217 218 219 233 234 235 241 242 261 262 263 264 265 266 267 268 269 276 277 278 282 283 284 301 302 327 339 341 342 343 353 354 355 356 357 358 371 410 411 412 420 428 429 430 431 432 436 437 447 448 449 450 451 452 459 460 461 465 466 467 502 503 504 512 513 514 515 516 517 518 519 523 524 525 526 527 528 534 542 548 560 561 590 607 608 609 634 635 636 649 650 653 654 658 659 660 671 672 673 687 688 689 695 696 697 698 703 704 705 711 712 717 718 733 734 735 736 737 738 744 745 752 753 755 756 757 764 780 786 787 788 789 790 791 798 799 800 801 807 808 821 827 828 829 850 851 852 853 857 860 862 863 865 866 868 869 871 872 873 874 875
## Warning in ICCest(adid, stroop_speed_accuracy, data = outcomes_task_itrn):
## Warning in ICCest(adid, stroop_speed_accuracy, data = outcomes_task_itrn): 'x'
## has been coerced to a factor
icc_matrix["stroop_speed_accuracy", 1]<-round(ICC.stroop_speed_accuracy$ICC,3)
icc_matrix["stroop_speed_accuracy", 2]<-round(ICC.stroop_speed_accuracy$LowerCI,3)
icc_matrix["stroop_speed_accuracy", 3]<-round(ICC.stroop_speed_accuracy$UpperCI,3)
icc_matrix["stroop_speed_accuracy", 4]<-round(ICC.stroop_speed_accuracy$N,3)
# ICCest(adid, fkr_satt_tot_time, data = outcomes_task_itrn)
ICC.flanker_speed_accuracy<-ICCest(adid, flanker_speed_accuracy, data = outcomes_task_itrn)
## NAs removed from rows:
## 71 81 115 118 134 307 363 446 458 493 551 686 767
## Warning in ICCest(adid, flanker_speed_accuracy, data = outcomes_task_itrn):
## Warning in ICCest(adid, flanker_speed_accuracy, data = outcomes_task_itrn): 'x'
## has been coerced to a factor
icc_matrix["flanker_speed_accuracy", 1]<-round(ICC.flanker_speed_accuracy$ICC,3)
icc_matrix["flanker_speed_accuracy", 2]<-round(ICC.flanker_speed_accuracy$LowerCI,3)
icc_matrix["flanker_speed_accuracy", 3]<-round(ICC.flanker_speed_accuracy$UpperCI,3)
icc_matrix["flanker_speed_accuracy", 4]<-round(ICC.flanker_speed_accuracy$N,3)
ICC.gonogo_cor_hits_min_inc_rej<-ICCest(adid, gonogo_cor_hits_min_inc_rej, data = outcomes_task_itrn)
## NAs removed from rows:
## 1 2 3 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 38 47 71 72 73 74 75 81 87 96 97 100 104 112 115 118 134 159 161 174 185 189 190 197 229 240 248 271 275 278 307 314 323 332 335 343 357 358 363 367 371 397 403 416 424 446 458 461 479 493 507 514 541 542 551 563 602 611 612 618 642 686 695 739 740 751 767 770 797 801 853 860
## Warning in ICCest(adid, gonogo_cor_hits_min_inc_rej, data =
## outcomes_task_itrn):
## Warning in ICCest(adid, gonogo_cor_hits_min_inc_rej, data =
## outcomes_task_itrn): 'x' has been coerced to a factor
icc_matrix["gonogo_cor_hits_min_inc_rej", 1]<-round(ICC.gonogo_cor_hits_min_inc_rej$ICC,3)
icc_matrix["gonogo_cor_hits_min_inc_rej", 2]<-round(ICC.gonogo_cor_hits_min_inc_rej$LowerCI,3)
icc_matrix["gonogo_cor_hits_min_inc_rej", 3]<-round(ICC.gonogo_cor_hits_min_inc_rej$UpperCI,3)
icc_matrix["gonogo_cor_hits_min_inc_rej", 4]<-round(ICC.gonogo_cor_hits_min_inc_rej$N,3)
# outcomes_task_itrn %>%
# ggplot(aes(x = adid, y = gng_cor_hits_min_inc_rej)) +
# geom_point()
ICC.humi_corr_by_chap<-ICCest(adid, humi_corr_by_chap, data = outcomes_task_itrn)
## NAs removed from rows:
## 21 38 71 75 87 96 97 115 118 134 174 190 240 248 307 314 335 358 363 397 424 446 458 493 541 551 612 618 686 740 767 797 801 853 855
## Warning in ICCest(adid, humi_corr_by_chap, data = outcomes_task_itrn):
## Warning in ICCest(adid, humi_corr_by_chap, data = outcomes_task_itrn): 'x' has
## been coerced to a factor
icc_matrix["humi_corr_by_chap", 1]<-round(ICC.humi_corr_by_chap$ICC,3)
icc_matrix["humi_corr_by_chap", 2]<-round(ICC.humi_corr_by_chap$LowerCI,3)
icc_matrix["humi_corr_by_chap", 3]<-round(ICC.humi_corr_by_chap$UpperCI,3)
icc_matrix["humi_corr_by_chap", 4]<-round(ICC.humi_corr_by_chap$N,3)
ICC.nback_dprime<-ICCest(adid, nback_dprime, data = outcomes_task_itrn)
## NAs removed from rows:
## 9 38 47 55 56 57 71 73 75 81 85 86 87 91 96 97 100 101 102 103 104 105 106 107 108 109 110 115 118 134 135 136 137 141 142 143 155 156 159 161 174 175 176 177 185 188 189 190 191 192 193 201 202 208 209 210 217 218 219 229 233 234 235 240 241 242 248 261 262 263 264 265 266 267 268 269 275 276 277 278 282 283 284 301 302 307 314 327 335 339 341 342 343 353 354 355 356 357 358 363 371 397 403 410 411 412 416 420 424 428 429 430 431 432 436 437 446 447 448 449 450 451 452 458 459 460 461 465 466 467 479 493 502 503 504 512 513 514 515 516 517 518 519 523 524 525 526 527 528 534 541 542 548 551 560 561 563 590 602 607 608 609 611 612 618 634 635 636 649 650 653 654 658 659 660 671 672 673 686 687 688 689 695 696 697 698 703 704 705 711 712 717 718 733 734 735 736 737 738 739 740 744 745 751 752 753 755 756 757 764 767 770 780 786 787 788 789 790 791 797 798 799 800 801 807 808 821 827 828 829 850 851 852 853 855 862 863 865 866 868 869 871 872 873 874 875
## Warning in ICCest(adid, nback_dprime, data = outcomes_task_itrn):
## Warning in ICCest(adid, nback_dprime, data = outcomes_task_itrn): 'x' has been
## coerced to a factor
icc_matrix["nback_dprime", 1]<-round(ICC.nback_dprime$ICC,3)
icc_matrix["nback_dprime", 2]<-round(ICC.nback_dprime$LowerCI,3)
icc_matrix["nback_dprime", 3]<-round(ICC.nback_dprime$UpperCI,3)
icc_matrix["nback_dprime", 4]<-round(ICC.nback_dprime$N,3)
print(icc_matrix)
## ICC LCI UCI Sample Size
## stroop_speed_accuracy 0.835 0.800 0.865 277
## flanker_speed_accuracy 0.926 0.912 0.939 364
## gonogo_cor_hits_min_inc_rej 0.631 0.570 0.687 334
## humi_corr_by_chap 0.786 0.747 0.820 358
## nback_dprime 0.645 0.578 0.705 269
#
# nback_poor_scores =
# outcomes_task_itrn %>%
# select(adid, task_iteration, nbk_dprime) %>%
# filter(nbk_dprime >= 4) %>%
# select(adid) %>% unique() %>%
# mutate(flag = 1)
#
# nback_sans_poor =
# outcomes_task_itrn %>%
# select(adid, task_iteration, nbk_dprime) %>%
# full_join(nback_poor_scores, by = "adid") %>%
# mutate(flag = if_else(is.na(flag), 0, flag)) %>%
# filter(flag == 0) %>% select(-flag)
#
#
# ICCest(adid, nbk_dprime, data = nback_sans_poor)
#
# nback_sans_poor %>% select(adid) %>% unique()
#had to pivot data wider, need every row to be one participant and every column to be 1 trial. Can't have ID either, need a matrix.
stroop_cronbach_cong =
stroop %>%
filter(data_rounds_on_practice_mode == "FALSE",
data_rounds_trial_type == "CONGRUENT") %>%
mutate(rxntime = (data_rounds_end - data_rounds_start)/100) %>%
select(participant_id, data_rounds_trial_number, rxntime) %>%
arrange(participant_id, data_rounds_trial_number) %>%
group_by(participant_id) %>%
mutate(trial_number_index = row_number()) %>%
select(-data_rounds_trial_number) %>%
pivot_wider(names_from = "trial_number_index", values_from = "rxntime", names_prefix = "trial_") %>%
ungroup() %>%
select(-participant_id, -trial_1)
stroop_cronbach_incong =
stroop %>%
filter(data_rounds_on_practice_mode == "FALSE",
data_rounds_trial_type == "INCONGRUENT") %>%
mutate(rxntime = (data_rounds_end - data_rounds_start)/100) %>%
select(participant_id, data_rounds_trial_number, rxntime) %>%
arrange(participant_id, data_rounds_trial_number) %>%
group_by(participant_id) %>%
mutate(trial_number_index = row_number()) %>%
select(-data_rounds_trial_number) %>%
pivot_wider(names_from = "trial_number_index", values_from = "rxntime", names_prefix = "trial_") %>%
ungroup() %>%
select(-participant_id, -trial_1)
flanker_cronbach_cong =
flanker %>%
filter(data_rounds_on_practice_mode == "FALSE",
data_rounds_trial_type == "congruent") %>%
mutate(rxntime = as.numeric(data_rounds_end) - as.numeric(data_rounds_start)) %>%
select(participant_id, data_rounds_trial_number, rxntime) %>%
arrange(participant_id, data_rounds_trial_number) %>%
group_by(participant_id) %>%
mutate(trial_number_index = row_number()) %>%
select(-data_rounds_trial_number) %>%
pivot_wider(names_from = "trial_number_index", values_from = "rxntime", names_prefix = "trial_") %>%
ungroup() %>%
select(-participant_id, -trial_1)
flanker_cronbach_incong =
flanker %>%
filter(data_rounds_on_practice_mode == "FALSE",
data_rounds_trial_type == "incongruent") %>%
mutate(rxntime = as.numeric(data_rounds_end) - as.numeric(data_rounds_start)) %>%
select(participant_id, data_rounds_trial_number, rxntime) %>%
arrange(participant_id, data_rounds_trial_number) %>%
group_by(participant_id) %>%
mutate(trial_number_index = row_number()) %>%
select(-data_rounds_trial_number) %>%
pivot_wider(names_from = "trial_number_index", values_from = "rxntime", names_prefix = "trial_") %>%
ungroup() %>%
select(-participant_id, -trial_1)
gonogo_cronbach_go =
gonogo %>%
filter(data_rounds_on_practice_mode == "FALSE",
data_rounds_trial_type == "Go") %>%
mutate(rxntime = data_rounds_end - data_rounds_start) %>%
select(participant_id, data_rounds_trial_number, rxntime) %>%
arrange(participant_id, data_rounds_trial_number) %>%
group_by(participant_id) %>%
mutate(trial_number_index = row_number()) %>%
select(-data_rounds_trial_number) %>%
pivot_wider(names_from = "trial_number_index", values_from = "rxntime", names_prefix = "trial_") %>%
ungroup() %>%
select(-participant_id, -trial_1)
gonogo_cronbach_nogo =
gonogo %>%
filter(data_rounds_on_practice_mode == "FALSE",
data_rounds_trial_type == "No-go") %>%
mutate(rxntime = data_rounds_end - data_rounds_start) %>%
select(participant_id, data_rounds_trial_number, rxntime) %>%
arrange(participant_id, data_rounds_trial_number) %>%
group_by(participant_id) %>%
mutate(trial_number_index = row_number()) %>%
select(-data_rounds_trial_number) %>%
pivot_wider(names_from = "trial_number_index", values_from = "rxntime", names_prefix = "trial_") %>%
ungroup() %>%
select(-participant_id, -trial_1)
humi_cronbach =
humi %>%
filter(data_rounds_on_practice_mode == "FALSE") %>%
mutate(data_round_correct = if_else(data_rounds_is_correct == "TRUE", 1, 0)) %>%
select(participant_id, data_rounds_order_delivery_time, data_round_correct) %>%
arrange(participant_id, data_rounds_order_delivery_time) %>%
group_by(participant_id) %>%
mutate(trial_number_index = row_number()) %>%
select(-data_rounds_order_delivery_time) %>%
pivot_wider(names_from = "trial_number_index", values_from = "data_round_correct", names_prefix = "trial_") %>%
ungroup() %>%
select(-participant_id, -trial_1)
card_cronbach =
card %>%
mutate(data_round_correct = if_else(data_rounds_correct == "TRUE", 1, 0)) %>%
select(participant_id, data_rounds_trial_number, data_round_correct) %>%
arrange(participant_id, data_rounds_trial_number) %>%
group_by(participant_id) %>%
mutate(trial_number_index = row_number()) %>%
select(-data_rounds_trial_number) %>%
pivot_wider(names_from = "trial_number_index", values_from = "data_round_correct", names_prefix = "trial_") %>%
ungroup() %>%
select(-participant_id, -trial_1)
nback_cronbach =
nback %>%
filter(data_on_practice_mode == "FALSE") %>%
mutate(data_rounds_correct = if_else(data_rounds_correct == "TRUE", 1, 0)) %>%
select(participant_id, data_rounds_trial_number, data_rounds_correct) %>%
filter(!is.na(data_rounds_correct)) %>%
arrange(participant_id, data_rounds_trial_number) %>%
group_by(participant_id) %>%
mutate(trial_number_index = row_number()) %>%
select(-data_rounds_trial_number) %>%
pivot_wider(names_from = "trial_number_index", values_from = "data_rounds_correct", names_prefix = "trial_") %>%
ungroup() %>%
select(-participant_id, -trial_1)
library(ltm)
## Loading required package: MASS
##
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
##
## select
## Loading required package: msm
## Loading required package: polycor
#
# stroop_cronbach_cong %>% View()
# #open up the above df, scroll all the way to right, and see tail of dataset, play around with limiting the trial number.
#might need like 3 or 4 participants? If like 2 or 3 might get weird estimate. Want maximize data
#could do a plot here and chose elbow, loop selecitng increasing numebr of non-NA values. Then plot it. With CI.
#start at trial 2 because first trial is likely a wash.
0.961 - 0.985
## [1] -0.024
df.list<-list(stroop_cronbach_cong,stroop_cronbach_incong,
flanker_cronbach_cong,flanker_cronbach_incong,
gonogo_cronbach_go, gonogo_cronbach_nogo,
humi_cronbach,
nback_cronbach,
card_cronbach) #datasets
df.list.string<-c("stroop_cronbach_cong","stroop_cronbach_incong",
"flanker_cronbach_cong","flanker_cronbach_incong",
"gonogo_cronbach_go", "gonogo_cronbach_nogo",
"humi_cronbach",
"nback_cronbach",
"card_cronbach") #names need to match names of datasets, in same order
min.participants<-10
bootstrap.n<-10
###do not change below###
df.list.string.count<-1
df.i=df.list[1]
for (df.i in df.list) {
df.cba<-df.i
for (co.i in colnames(df.cba)) {
na.sum<-sum(is.na(df.cba[co.i]))
cnt<-nrow(df.cba)-na.sum
if (cnt<min.participants) {
df.cba[co.i]<-NULL
}
} #co.i
cba.names<-colnames(df.cba)[2:length(colnames(df.cba))]
cba.name.start<-colnames(df.cba)[1]
for (col.it.i in 1:length(cba.names)) {
#
# tempdf<-as.data.frame(df.cba[cba.names[col.it.i]])
# temodf.2<-as.data.frame(df.cba[cba.name.start[1]])
# df.cba$start<-temodf.2[,1]
# df.cba$end<-tempdf[,1]
cba.temp<-cronbach.alpha(df.cba %>% dplyr::select(cba.name.start[1]: cba.names[col.it.i]), standardized = FALSE, CI = TRUE, B = bootstrap.n, na.rm = TRUE)
mat.CBA<-matrix(nrow=1, ncol=6, dimnames = list(c( df.list.string[df.list.string.count]), c("[items]","[alpha]","[LCI]","[UCI]","[CI width]","[Final trial sample Size]")))
if (col.it.i==1) {
mat.CBA[1,"[items]"]<-round(as.numeric(cba.temp[3]),3)
mat.CBA[1,"[alpha]"]<-round(as.numeric(cba.temp[1]),3)
mat.CBA[1,"[LCI]"]<-round(as.numeric(cba.temp$ci[1]),3)
mat.CBA[1,"[UCI]"]<-round(as.numeric(cba.temp$ci[2]),3)
mat.CBA[1,"[CI width]"]<- mat.CBA[1,"[UCI]"]- mat.CBA[1,"[LCI]"]
mat.CBA[1,"[Final trial sample Size]"]<-nrow(df.cba)-sum(is.na(df.cba[,cba.names[col.it.i]]))
mat.CBA.int<-mat.CBA
} else{
mat.CBA[1,"[items]"]<-round(as.numeric(cba.temp[3]),3)
mat.CBA[1,"[alpha]"]<-round(as.numeric(cba.temp[1]),3)
mat.CBA[1,"[LCI]"]<-round(as.numeric(cba.temp$ci[1]),3)
mat.CBA[1,"[UCI]"]<-round(as.numeric(cba.temp$ci[2]),3)
mat.CBA[1,"[CI width]"]<- mat.CBA[1,"[UCI]"]- mat.CBA[1,"[LCI]"]
mat.CBA[1,"[Final trial sample Size]"]<-nrow(df.cba)-sum(is.na(df.cba[,cba.names[col.it.i]]))
mat.CBA.int<-rbind(mat.CBA.int,mat.CBA)
} #ifelse
} #col.it.i
plot(mat.CBA.int[,1], mat.CBA.int[,2], main = df.list.string[df.list.string.count])
save.name<-paste(df.list.string[df.list.string.count],"Cronbachalpha", sep="_")
gnu.save(file = mat.CBA.int, filename = save.name)
df.list.string.count<-df.list.string.count+1
mat.CBA.int
}

## [1] "Rows: 57"
## [1] "Cols: 6"
## File saved as: stroop_cronbach_cong_Cronbachalpha_2023-10-03.csv
## File saved in: C:/Users/mark/Documents/GitHub/Reliability-october-2023

## [1] "Rows: 23"
## [1] "Cols: 6"
## File saved as: stroop_cronbach_incong_Cronbachalpha_2023-10-03.csv
## File saved in: C:/Users/mark/Documents/GitHub/Reliability-october-2023

## [1] "Rows: 44"
## [1] "Cols: 6"
## File saved as: flanker_cronbach_cong_Cronbachalpha_2023-10-03.csv
## File saved in: C:/Users/mark/Documents/GitHub/Reliability-october-2023

## [1] "Rows: 43"
## [1] "Cols: 6"
## File saved as: flanker_cronbach_incong_Cronbachalpha_2023-10-03.csv
## File saved in: C:/Users/mark/Documents/GitHub/Reliability-october-2023

## [1] "Rows: 83"
## [1] "Cols: 6"
## File saved as: gonogo_cronbach_go_Cronbachalpha_2023-10-03.csv
## File saved in: C:/Users/mark/Documents/GitHub/Reliability-october-2023

## [1] "Rows: 18"
## [1] "Cols: 6"
## File saved as: gonogo_cronbach_nogo_Cronbachalpha_2023-10-03.csv
## File saved in: C:/Users/mark/Documents/GitHub/Reliability-october-2023

## [1] "Rows: 64"
## [1] "Cols: 6"
## File saved as: humi_cronbach_Cronbachalpha_2023-10-03.csv
## File saved in: C:/Users/mark/Documents/GitHub/Reliability-october-2023

## [1] "Rows: 94"
## [1] "Cols: 6"
## File saved as: nback_cronbach_Cronbachalpha_2023-10-03.csv
## File saved in: C:/Users/mark/Documents/GitHub/Reliability-october-2023

## [1] "Rows: 46"
## [1] "Cols: 6"
## File saved as: card_cronbach_Cronbachalpha_2023-10-03.csv
## File saved in: C:/Users/mark/Documents/GitHub/Reliability-october-2023
#function for bootstrapped Cbas
# cronbach.alpha(stroop_cronbach_cong %>% dplyr::select(trial_2:trial_58), standardized = TRUE, CI = TRUE, na.rm = TRUE)
# cronbach.alpha(stroop_cronbach_cong %>% dplyr::select(trial_2:trial_58), standardized = FALSE, CI = TRUE, B = 1000, na.rm = TRUE)
#
# stroop_cronbach_incong %>% View()
# cronbach.alpha(stroop_cronbach_incong %>% dplyr::select(trial_2:trial_25), standardized = TRUE, CI = TRUE, na.rm = TRUE)
cronbach.alpha(stroop_cronbach_incong %>% dplyr::select(trial_2:trial_25), standardized = FALSE, CI = TRUE, na.rm = TRUE)
##
## Cronbach's alpha for the 'stroop_cronbach_incong %>% dplyr::select(trial_2:trial_25)' data-set
##
## Items: 24
## Sample units: 222
## alpha: 0.87
##
## Bootstrap 95% CI based on 1000 samples
## 2.5% 97.5%
## 0.631 0.931
flanker_cronbach_cong %>% View()
# cronbach.alpha(flanker_cronbach_cong %>% dplyr::select(trial_2:trial_46), standardized = TRUE, CI = TRUE, na.rm = TRUE)
# cronbach.alpha(flanker_cronbach_cong %>% dplyr::select(trial_2:trial_46), standardized = FALSE, CI = TRUE, na.rm = TRUE)
flanker_cronbach_incong %>% View()
# cronbach.alpha(flanker_cronbach_incong %>% dplyr::select(trial_2:trial_45), standardized = TRUE, CI = TRUE, na.rm = TRUE)
cronbach.alpha(flanker_cronbach_incong %>% dplyr::select(trial_2:trial_45), standardized = FALSE, CI = TRUE, na.rm = TRUE)
##
## Cronbach's alpha for the 'flanker_cronbach_incong %>% dplyr::select(trial_2:trial_45)' data-set
##
## Items: 44
## Sample units: 279
## alpha: 0.989
##
## Bootstrap 95% CI based on 1000 samples
## 2.5% 97.5%
## 0.979 0.995
gonogo_cronbach_go %>% View()
# cronbach.alpha(gonogo_cronbach_go %>% dplyr::select(trial_2:trial_84), standardized = TRUE, CI = TRUE, na.rm = TRUE)
# cronbach.alpha(gonogo_cronbach_go %>% dplyr::select(trial_2:trial_84), standardized = FALSE, CI = TRUE, na.rm = TRUE)
gonogo_cronbach_nogo %>% View()
# cronbach.alpha(gonogo_cronbach_nogo %>% dplyr::select(trial_2:trial_19), standardized = TRUE, CI = TRUE, na.rm = TRUE)
cronbach.alpha(gonogo_cronbach_nogo %>% dplyr::select(trial_2:trial_19), standardized = FALSE, CI = TRUE, na.rm = TRUE)
##
## Cronbach's alpha for the 'gonogo_cronbach_nogo %>% dplyr::select(trial_2:trial_19)' data-set
##
## Items: 18
## Sample units: 255
## alpha: 0.796
##
## Bootstrap 95% CI based on 1000 samples
## 2.5% 97.5%
## 0.30 0.92
humi_cronbach %>% View()
# cronbach.alpha(humi_cronbach %>% dplyr::select(trial_2:trial_42), standardized = TRUE, CI = TRUE, na.rm = TRUE)
cronbach.alpha(humi_cronbach %>% dplyr::select(trial_2:trial_42), standardized = FALSE, CI = TRUE, na.rm = TRUE)
##
## Cronbach's alpha for the 'humi_cronbach %>% dplyr::select(trial_2:trial_42)' data-set
##
## Items: 41
## Sample units: 276
## alpha: 0.57
##
## Bootstrap 95% CI based on 1000 samples
## 2.5% 97.5%
## 0.479 0.640
nback_cronbach %>% View()
# cronbach.alpha(nback_cronbach %>% dplyr::select(trial_2:trial_92), standardized = TRUE, CI = TRUE, na.rm = TRUE)
cronbach.alpha(nback_cronbach %>% dplyr::select(trial_2:trial_92), standardized = FALSE, CI = TRUE, na.rm = TRUE)
##
## Cronbach's alpha for the 'nback_cronbach %>% dplyr::select(trial_2:trial_92)' data-set
##
## Items: 91
## Sample units: 215
## alpha: 0.919
##
## Bootstrap 95% CI based on 1000 samples
## 2.5% 97.5%
## 0.900 0.933
card_cronbach %>% View()
# cronbach.alpha(card_cronbach %>% dplyr::select(trial_2:trial_48), standardized = TRUE, CI = TRUE, na.rm = TRUE)
cronbach.alpha(card_cronbach %>% dplyr::select(trial_2:trial_48), standardized = FALSE, CI = TRUE, na.rm = TRUE)
##
## Cronbach's alpha for the 'card_cronbach %>% dplyr::select(trial_2:trial_48)' data-set
##
## Items: 47
## Sample units: 220
## alpha: 0.915
##
## Bootstrap 95% CI based on 1000 samples
## 2.5% 97.5%
## 0.889 0.931