Skip to content

Commit 24afb87

Browse files
committed
2 parents f3975d0 + 9876a94 commit 24afb87

File tree

1 file changed

+86
-68
lines changed

1 file changed

+86
-68
lines changed

R/cge_analysis_script.R

+86-68
Original file line numberDiff line numberDiff line change
@@ -985,27 +985,46 @@ plot(ospanScores, symspanScores,
985985
lines(x = c(-1, 2), y = c(-1, 2)) # so line extends to edge
986986

987987
capacity_HighP1_lowN1 = (compositeSpanScores > median_compositespan)*2-1;
988+
# NOTE: This is all participants who completed the WMC task
989+
# Includes people we drop from e.g. decision-making analysis
988990

989-
sum(capacity_HighP1_lowN1 == 1, na.rm = T) # 41
990-
sum(capacity_HighP1_lowN1 == -1, na.rm = T) # 44
991+
sum(capacity_HighP1_lowN1 == 1, na.rm = T) # 41 (all participants)
992+
sum(capacity_HighP1_lowN1 == -1, na.rm = T) # 44 (all participants)
991993

992994
# Plot the distribution w/ the median value
993995
hist(compositeSpanScores, breaks = 10, xlab = 'Composite Span Score', main = 'Distribution of Spans');
994996
abline(v = median_compositespan, col = 'red', lwd = 5)
995997

996998

999+
# Limiting analysis to those people we kept for DECISION-MAKING ANALYSIS...
1000+
sum(clean_data_complexspan$compositeSpanScore > median(clean_data_complexspan$compositeSpanScore, na.rm = T), na.rm = T)
1001+
sum(clean_data_complexspan$compositeSpanScore <= median(clean_data_complexspan$compositeSpanScore, na.rm = T), na.rm = T)
1002+
# 41 with > median capacity
1003+
# 41 with <= median capacity
1004+
1005+
# Create *CLEAN DATA* capacity median split
1006+
clean_data_complexspan$capacity_HighP1_lowN1 = (clean_data_complexspan$compositeSpanScore >
1007+
median(clean_data_complexspan$compositeSpanScore, na.rm = T))*2-1;
1008+
9971009
clean_data_dm$capacity_HighP1_lowN1 = NA;
9981010

9991011
for(s in 1:number_of_clean_subjects){
10001012
subj_id = keep_participants[s];
1001-
clean_data_dm$capacity_HighP1_lowN1[clean_data_dm$subjectnumber == subj_id] = capacity_HighP1_lowN1[s];
1013+
clean_data_dm$capacity_HighP1_lowN1[clean_data_dm$subjectnumber == subj_id] =
1014+
clean_data_complexspan$capacity_HighP1_lowN1[clean_data_complexspan$subjectnumber == subj_id];
10021015
}
10031016

10041017
clean_data_dm$complexspan_demeaned = clean_data_dm$complexspan - mean_compositespan;
10051018

1006-
plot(sort(compositeSpanScores))
1019+
# all subjects
1020+
plot(sort(compositeSpanScores), main = 'All participants')
10071021
abline(h = median_compositespan, col = 'red', lwd = 2)
10081022

1023+
# just clean subjects
1024+
plot(sort(clean_data_complexspan$compositeSpanScore), main = 'Clean participants')
1025+
abline(h = median(clean_data_complexspan$compositeSpanScore, na.rm = T), col = 'red', lwd = 2)
1026+
1027+
10091028
# Easy vs. Difficult in WMC - From thesis
10101029

10111030
rt_mean__Hcap_test = t.test(mean_rt_easy[capacity_HighP1_lowN1 == 1], mean_rt_diff[capacity_HighP1_lowN1 == 1], paired = T) #
@@ -1420,12 +1439,12 @@ m2_capacityContDiff_intxn_rfx = lmer(sqrtRT ~ 1 + all_diff_cont * capacity_HighP
14201439
summary(m2_capacityContDiff_intxn_rfx)
14211440
# SAME PATTERN If you use continuous difficulty instead of categorical difficulty
14221441

1423-
# effect of difficulty is 0.118 for HIGH CAPACITY
1424-
# effect of difficulty is 0.100 for LOW CAPACITY
1442+
# effect of difficulty is 0.127 for HIGH CAPACITY
1443+
# effect of difficulty is 0.084 for LOW CAPACITY
14251444

14261445

1427-
AIC(m2_capacityCatDiff_intxn_rfx) # AIC: -5874.978
1428-
AIC(m2_capacityContDiff_intxn_rfx) # AIC: -6026.223 (CONTINUOUS IS BETTER)
1446+
AIC(m2_capacityCatDiff_intxn_rfx) # AIC: -8514.704
1447+
AIC(m2_capacityContDiff_intxn_rfx) # AIC: -8699.212 (CONTINUOUS IS BETTER)
14291448

14301449

14311450
# Model 3: What role does high/low cognitive capacity have on CURRENT AND PREVIOUS TRIAL EFFECTS
@@ -1454,8 +1473,8 @@ m3_prev_diffCont_capacityCat_intxn_rfx = lmer(sqrtRT ~ 1 +
14541473
all_diff_cont * prev_all_diff_cont * capacity_HighP1_lowN1 +
14551474
(1 | subjectnumber), data = clean_data_dm);
14561475
summary(m3_prev_diffCont_capacityCat_intxn_rfx)
1457-
# Besides main effects of current and previous difficulty, NO INTERACTIONS between capacity and
1458-
# difficulty (current or previous).
1476+
# Besides main effects of current and previous difficulty, ONLY interaction is between
1477+
# current difficulty and capacity (steeper for higher difficulty folks)
14591478

14601479

14611480

@@ -1470,20 +1489,21 @@ AIC(m3_prev_diffCont_capacityCat_intxn_rfx) # Be careful when reporting; has few
14701489
#
14711490
# MODEL OUTPUT
14721491
# Estimate Std. Error df t value Pr(>|t|)
1473-
# (Intercept) 1.222e+00 1.333e-02 6.778e+01 91.669 < 2e-16 ***
1474-
# all_diff_cont 1.085e-01 6.697e-03 9.839e+03 16.204 < 2e-16 ***
1475-
# prev_all_diff_cont -3.647e-02 6.721e-03 9.840e+03 -5.426 5.91e-08 ***
1476-
# capacity_HighP1_lowN1 -1.606e-02 1.333e-02 6.778e+01 -1.205 0.233
1477-
# all_diff_cont:prev_all_diff_cont 6.487e-03 1.014e-02 9.834e+03 0.640 0.522
1478-
# all_diff_cont:capacity_HighP1_lowN1 8.721e-03 6.697e-03 9.839e+03 1.302 0.193
1479-
# prev_all_diff_cont:capacity_HighP1_lowN1 6.921e-03 6.721e-03 9.840e+03 1.030 0.303
1480-
# all_diff_cont:prev_all_diff_cont:capacity_HighP1_lowN1 4.349e-05 1.014e-02 9.834e+03 0.004 0.997
1492+
# Estimate Std. Error df t value Pr(>|t|)
1493+
# (Intercept) 1.211e+00 1.194e-02 9.447e+01 101.409 < 2e-16 ***
1494+
# all_diff_cont 1.051e-01 5.767e-03 1.367e+04 18.220 < 2e-16 ***
1495+
# prev_all_diff_cont -3.496e-02 5.777e-03 1.367e+04 -6.052 1.47e-09 ***
1496+
# capacity_HighP1_lowN1 -9.077e-03 1.194e-02 9.447e+01 -0.760 0.44896
1497+
# all_diff_cont:prev_all_diff_cont 6.018e-03 8.654e-03 1.367e+04 0.695 0.48683
1498+
# all_diff_cont:capacity_HighP1_lowN1 1.534e-02 5.767e-03 1.367e+04 2.659 0.00784 **
1499+
# prev_all_diff_cont:capacity_HighP1_lowN1 -2.297e-04 5.777e-03 1.367e+04 -0.040 0.96828
1500+
# all_diff_cont:prev_all_diff_cont:capacity_HighP1_lowN1 1.200e-02 8.654e-03 1.367e+04 1.387 0.16543
14811501
#
14821502
# Current difficulty = slower RTs (found previously)
14831503
# Prev. difficulty = faster RTs (found previously)
14841504
# Curr. & prev. difficulty do NOT interact to influence reaction time.
14851505
#
1486-
# Capacity = no net effect! [contrary to hypotheses]
1506+
# Capacity interacts with current difficulty. No interaction w/ prev. difficulty.
14871507
#
14881508
# in CGT, Capacity interacted with CURRENT difficulty to potentiate slowing due to difficulty
14891509
# for high capacity people, and attenuate that effect for low capacity people. NOT SO IN CGE!
@@ -1536,51 +1556,46 @@ m3_prev_diffCont_capacityCat_intxn_HIGHONLYrfx = lmer(sqrtRT ~ 1 +
15361556
data = clean_data_dm[clean_data_dm$capacity_HighP1_lowN1 == 1,]);
15371557
summary(m3_prev_diffCont_capacityCat_intxn_HIGHONLYrfx)
15381558
# Fixed effects:
1539-
# Estimate Std. Error df t value Pr(>|t|)
1540-
# (Intercept) 1.206e+00 1.750e-02 3.289e+01 68.920 < 2e-16 ***
1541-
# all_diff_cont 1.172e-01 8.756e-03 4.845e+03 13.387 < 2e-16 ***
1542-
# prev_all_diff_cont -2.957e-02 8.816e-03 4.845e+03 -3.355 0.000801 ***
1543-
# all_diff_cont:prev_all_diff_cont 6.550e-03 1.346e-02 4.843e+03 0.486 0.626637
1544-
1559+
# Estimate Std. Error df t value Pr(>|t|)
1560+
# (Intercept) 1.202e+00 1.601e-02 4.677e+01 75.062 < 2e-16 ***
1561+
# all_diff_cont 1.204e-01 7.735e-03 6.842e+03 15.566 < 2e-16 ***
1562+
# prev_all_diff_cont -3.520e-02 7.774e-03 6.842e+03 -4.528 6.06e-06 ***
1563+
# all_diff_cont:prev_all_diff_cont 1.804e-02 1.179e-02 6.840e+03 1.530 0.126
15451564
# Contrary to CGT, there *IS* a significant effect of previous difficulty for high capacity folks.
15461565

15471566
m3_prev_diffCont_capacityCat_intxn_LOWONLYrfx = lmer(sqrtRT ~ 1 +
15481567
all_diff_cont * prev_all_diff_cont +
15491568
(1 | subjectnumber), data = clean_data_dm[clean_data_dm$capacity_HighP1_lowN1 == -1,]);
15501569
summary(m3_prev_diffCont_capacityCat_intxn_LOWONLYrfx)
15511570
# Fixed effects:
1552-
# Estimate Std. Error df t value Pr(>|t|)
1553-
# (Intercept) 1.238e+00 2.005e-02 3.495e+01 61.757 < 2e-16 ***
1554-
# all_diff_cont 9.980e-02 1.018e-02 4.995e+03 9.806 < 2e-16 ***
1555-
# prev_all_diff_cont -4.340e-02 1.018e-02 4.995e+03 -4.261 2.07e-05 ***
1556-
# all_diff_cont:prev_all_diff_cont 6.464e-03 1.519e-02 4.992e+03 0.425 0.67
1571+
# Estimate Std. Error df t value Pr(>|t|)
1572+
# (Intercept) 1.220e+00 1.772e-02 4.762e+01 68.852 < 2e-16 ***
1573+
# all_diff_cont 8.977e-02 8.554e-03 6.831e+03 10.494 < 2e-16 ***
1574+
# prev_all_diff_cont -3.471e-02 8.545e-03 6.832e+03 -4.062 4.92e-05 ***
1575+
# all_diff_cont:prev_all_diff_cont -5.979e-03 1.267e-02 6.828e+03 -0.472 0.637
15571576

1558-
# The effect of previous difficulty is STRONGER in low capacity people (just not sig. so)
1577+
# The effect of previous difficulty is similar in low capacity people (just not sig. so)
15591578

15601579
# THESE FINDINGS TOTALLY PARALLEL THE COMPLEX INTERACTIVE MODEL ABOVE AND BACK UP THE OBSERVATIONS MADE THERE.
15611580

1562-
for (s in 1:number_of_clean_subjects){
1563-
subj_id = keep_participants[s];
1564-
clean_data_dm$diff_cont[subj_id] = abs(abs(clean_data_dm$choiceP[subj_id] - 0.5)*2-1); # JUST for the easy/difficult dynamic trials
1565-
clean_data_dm$all_diff_cont[subj_id] = abs(abs(clean_data_dm$all_choiceP[subj_id] - 0.5)*2-1); # for ALL trials
1566-
clean_data_dm$capacity_HighP1_lowN1[clean_data_dm$subjectnumber == subj_id] = capacity_HighP1_lowN1[s];
1567-
1568-
m3_prev_diffCont_capacityCat_intxn_HIGHONLYrfx = lmer(sqrtRT ~ 1 +
1569-
all_diff_cont * prev_all_diff_cont +
1570-
(1 | subjectnumber),
1571-
data = clean_data_dm[clean_data_dm$capacity_HighP1_lowN1 == 1,]);
1572-
summary(m3_prev_diffCont_capacityCat_intxn_HIGHONLYrfx)
1573-
1574-
m3_prev_diffCont_capacityCat_intxn_LOWONLYrfx = lmer(sqrtRT ~ 1 +
1575-
all_diff_cont * prev_all_diff_cont +
1576-
(1 | subjectnumber), data = clean_data_dm[clean_data_dm$capacity_HighP1_lowN1 == -1,]);
1577-
summary(m3_prev_diffCont_capacityCat_intxn_LOWONLYrfx)
1578-
}
1581+
# for (s in 1:number_of_clean_subjects){
1582+
# subj_id = keep_participants[s];
1583+
# # clean_data_dm$diff_cont[subj_id] = abs(abs(clean_data_dm$choiceP[subj_id] - 0.5)*2-1); # JUST for the easy/difficult dynamic trials
1584+
# # clean_data_dm$all_diff_cont[subj_id] = abs(abs(clean_data_dm$all_choiceP[subj_id] - 0.5)*2-1); # for ALL trials
1585+
# # clean_data_dm$capacity_HighP1_lowN1[clean_data_dm$subjectnumber == subj_id] = capacity_HighP1_lowN1[s];
1586+
#
1587+
# m3_prev_diffCont_capacityCat_intxn_HIGHONLYrfx = lmer(sqrtRT ~ 1 +
1588+
# all_diff_cont * prev_all_diff_cont +
1589+
# (1 | subjectnumber),
1590+
# data = clean_data_dm[clean_data_dm$capacity_HighP1_lowN1 == 1,]);
1591+
# summary(m3_prev_diffCont_capacityCat_intxn_HIGHONLYrfx)
1592+
#
1593+
# m3_prev_diffCont_capacityCat_intxn_LOWONLYrfx = lmer(sqrtRT ~ 1 +
1594+
# all_diff_cont * prev_all_diff_cont +
1595+
# (1 | subjectnumber), data = clean_data_dm[clean_data_dm$capacity_HighP1_lowN1 == -1,]);
1596+
# summary(m3_prev_diffCont_capacityCat_intxn_LOWONLYrfx)
1597+
# }
15791598

1580-
for(s in 1:number_of_clean_subjects){
1581-
subj_id = keep_participants[s];
1582-
clean_data_dm$capacity_HighP1_lowN1[clean_data_dm$subjectnumber == subj_id] = capacity_HighP1_lowN1[s];
1583-
}
15841599

15851600
# Examine best-fitting threshold values
15861601
possible_threshold_values = sort(unique(compositeSpanScores))+.000001;
@@ -1595,13 +1610,14 @@ for(ind in 1:length(possible_threshold_values)){
15951610
clean_data_dm$capacity_HighP1_lowN1_temp[clean_data_dm$complexspan > break_val] = 1;
15961611
clean_data_dm$capacity_HighP1_lowN1_temp[clean_data_dm$complexspan < break_val] = -1;
15971612

1598-
cat(sprintf('This many people are < break_val: %g\n',sum(compositeSpanScores<break_val, na.rm = T)))
1613+
cat(sprintf('This many people are < break_val: %g\n',sum(clean_data_complexspan$compositeSpanScore<break_val, na.rm = T)))
15991614

1600-
if((sum(compositeSpanScores<break_val, na.rm = T) == 1) | (sum(compositeSpanScores>break_val, na.rm = T) == 1)){
1615+
if((sum(clean_data_complexspan$compositeSpanScore<break_val, na.rm = T) == 1) | (sum(clean_data_complexspan$compositeSpanScore>break_val, na.rm = T) == 1)){
16011616
next # don't use any categorizations that create a 'group' with just 1 person
16021617
}
16031618

1604-
m3_tmp = lmer(sqrtRT ~ 1 + all_diff_cont * prev_all_diff_cont * capacity_HighP1_lowN1_temp +
1619+
m3_tmp = lmer(sqrtRT ~ 1 + all_diff_cont * capacity_HighP1_lowN1_temp +
1620+
prev_all_diff_cont * capacity_HighP1_lowN1_temp +
16051621
(1 | subjectnumber), data = clean_data_dm, REML = F);
16061622
all_aic_values[ind] = AIC(m3_tmp)
16071623
}
@@ -1612,9 +1628,9 @@ best_threshold = possible_threshold_values[which(all_aic_values == best_aic)];
16121628
cat(sprintf('The best fitting model uses a CompositeSpan threshold value of %g.\n', best_threshold))
16131629
cat(sprintf('The best AIC obtained with the CompositeSpan was %0.2f\n', best_aic))
16141630

1615-
plot(sort(compositeSpanScores), xlab = 'Participants', ylab = 'Span')
1631+
plot(sort(clean_data_complexspan$compositeSpanScore), xlab = 'Participants', ylab = 'Span')
16161632
abline(h = best_threshold, col = 'blue', lwd = 4)
1617-
abline(h = median_compositespan, col = 'red', lwd = 4, lty = 'dotted') # median value
1633+
abline(h = median(clean_data_complexspan$compositeSpanScore, na.rm = T), col = 'red', lwd = 4, lty = 'dotted') # median value
16181634
legend('topleft', legend = c('Span','Best threshold','Median span'), col = c('black','blue', 'red'), lty = 1)
16191635

16201636
plot(x = possible_threshold_values, y = all_aic_values, type = 'l', col = 'green', xlab = 'Thresholds', ylab = 'AIC values (lower better)')
@@ -1623,9 +1639,9 @@ abline(v = best_threshold, col = 'blue', lwd = 4)
16231639

16241640
# The best-fitting threshold (just slightly above the median value) is 0.6571439
16251641

1626-
break_val = best_threshold; # as of 2/25/24, this was 0.6571439
1642+
break_val = best_threshold; # as of 3/19/25, this was 0.6785724
16271643

1628-
capacity_HighP1_lowN1_Best = (compositeSpanScores[keep_participants] > break_val)*2 - 1;
1644+
capacity_HighP1_lowN1_Best = (clean_data_complexspan$compositeSpanScore > break_val)*2 - 1;
16291645

16301646
clean_data_dm$capacity_HighP1_lowN1_best[clean_data_dm$complexspan > break_val] = 1;
16311647
clean_data_dm$capacity_HighP1_lowN1_best[clean_data_dm$complexspan < break_val] = -1;
@@ -1641,19 +1657,21 @@ m3_best_nointxn = lmer(sqrtRT ~ 1 + all_diff_cont * capacity_HighP1_lowN1_best +
16411657
(1 | subjectnumber), data = clean_data_dm, REML = F);
16421658
summary(m3_best_nointxn) # THIS OUTPERFORMS THE FULLY-INTERACTIVE VERSION
16431659

1644-
# Estimate Std. Error df t value Pr(>|t|)
1645-
# (Intercept) 1.202e+00 1.233e-02 8.980e+01 97.522 < 2e-16 ***
1646-
# all_diff_cont 1.164e-01 3.839e-03 1.368e+04 30.312 < 2e-16 ***
1647-
# capacity_HighP1_lowN1_best -2.213e-02 1.233e-02 8.980e+01 -1.795 0.076 .
1648-
# prev_all_diff_cont -2.713e-02 3.844e-03 1.368e+04 -7.058 1.77e-12 ***
1649-
# all_diff_cont:capacity_HighP1_lowN1_best 2.485e-02 3.839e-03 1.368e+04 6.473 9.91e-11 ***
1650-
# capacity_HighP1_lowN1_best:prev_all_diff_cont 1.579e-02 3.844e-03 1.368e+04 4.107 4.04e-05 ***
1660+
# Estimate Std. Error df t value Pr(>|t|)
1661+
# (Intercept) 1.202e+00 1.259e-02 8.971e+01 95.441 < 2e-16 ***
1662+
# all_diff_cont 1.181e-01 3.914e-03 1.368e+04 30.185 < 2e-16 ***
1663+
# capacity_HighP1_lowN1_best -2.096e-02 1.259e-02 8.971e+01 -1.665 0.099401 .
1664+
# prev_all_diff_cont -2.643e-02 3.918e-03 1.368e+04 -6.746 1.58e-11 ***
1665+
# all_diff_cont:capacity_HighP1_lowN1_best 2.598e-02 3.914e-03 1.368e+04 6.638 3.29e-11 ***
1666+
# capacity_HighP1_lowN1_best:prev_all_diff_cont 1.515e-02 3.918e-03 1.368e+04 3.867 0.000111 ***
16511667

1668+
# AIC: -8762.2 (BEST)
16521669

1653-
m3_best_continuousWMC_nointxn = lmer(sqrtRT ~ 1 + all_diff_cont * complexspan_demeaned + prev_all_diff_cont * complexspan_demeaned +
1670+
m3_best_continuousWMC_nointxn = lmer(sqrtRT ~ 1 + all_diff_cont * complexspan_demeaned +
1671+
prev_all_diff_cont * complexspan_demeaned +
16541672
(1 | subjectnumber), data = clean_data_dm, REML = F);
16551673
summary(m3_best_continuousWMC_nointxn) # THIS OUTPERFORMS THE FULLY-INTERACTIVE VERSION
1656-
1674+
# AIC: -8740.8
16571675

16581676
m3_best_HighCap_only = lmer(sqrtRT ~ 1 + all_diff_cont * prev_all_diff_cont +
16591677
(1 | subjectnumber), data = clean_data_dm[clean_data_dm$capacity_HighP1_lowN1_best == 1,], REML = F);

0 commit comments

Comments
 (0)