library(haven)
library(cluster) #for the main cluster analysis
library(SHT)
## Warning: package 'SHT' was built under R version 4.2.3
## **------------------------------------------------------**
## ** MMMMMMMMMMMMMMMMMMMMM MMMMMMMMMMMM MMMMMMMMMMMMMMMMMMM
## ** MMMMMMMMMMMP MM M MMMMM MM M MMMMMMMMMM
## ** MMMMMMMMMMM mmmmm..M M MMMMM MM MMMM MMMMMMMMMMMMM
## ** MMMMMMMMMMM..... YM M MM MMMM MMMMMMMMMMMMM
## ** MMMMMMMMMMMMMMMMM. M M MMMMM MM MMMM MMMMMMMMMMMMM
## ** MMMMMMMMMMM. .MMM M M MMMMM MM MMMM MMMMMMMMMMMMM
## ** MMMMMMMMMMMb. .dM M MMMMM MM MMMM MMMMMMMMMMMMM
## ** MMMMMMMMMMMMMMMMMMMMM MMMMMMMMMMMM MMMMMMMMMMMMMMMMMMM
## **
## ** Statistical Hypothesis Testing Toolbox
## **
## ** Version : 0.1.8 (2024)
## ** Authors : Kyoungjae Lee, Lizhen Lin, Kisung You
## ** Maintainer : Kisung You (kisungyou@outlook.com)
## **
## ** Please share any bugs or suggestions to the maintainer.
## **------------------------------------------------------**
library(factoextra) #fancy data bits
## Warning: package 'factoextra' was built under R version 4.2.3
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.2.3
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
library(mvoutlier)
## Warning: package 'mvoutlier' was built under R version 4.2.3
## Loading required package: sgeostat
library(psych)
## Warning: package 'psych' was built under R version 4.2.3
##
## Attaching package: 'psych'
## The following objects are masked from 'package:ggplot2':
##
## %+%, alpha
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.2.3
## Warning: package 'tibble' was built under R version 4.2.3
## Warning: package 'tidyr' was built under R version 4.2.3
## Warning: package 'purrr' was built under R version 4.2.3
## Warning: package 'dplyr' was built under R version 4.2.3
## Warning: package 'stringr' was built under R version 4.2.3
## Warning: package 'lubridate' was built under R version 4.2.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.1 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ lubridate 1.9.2 ✔ tibble 3.2.1
## ✔ purrr 1.0.1 ✔ tidyr 1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ psych::%+%() masks ggplot2::%+%()
## ✖ psych::alpha() masks ggplot2::alpha()
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the ]8;;http://conflicted.r-lib.org/conflicted package]8;; to force all conflicts to become errors
library(dplyr)
library(ggplot2)
library(broom)
## Warning: package 'broom' was built under R version 4.2.3
library(MASS)
## Warning: package 'MASS' was built under R version 4.2.3
##
## Attaching package: 'MASS'
##
## The following object is masked from 'package:dplyr':
##
## select
library(reshape2)
## Warning: package 'reshape2' was built under R version 4.2.3
##
## Attaching package: 'reshape2'
##
## The following object is masked from 'package:tidyr':
##
## smiths
library(corrplot)
## Warning: package 'corrplot' was built under R version 4.2.3
## corrplot 0.92 loaded
library(weights)
## Warning: package 'weights' was built under R version 4.2.3
## Loading required package: Hmisc
## Warning: package 'Hmisc' was built under R version 4.2.3
##
## Attaching package: 'Hmisc'
##
## The following objects are masked from 'package:dplyr':
##
## src, summarize
##
## The following object is masked from 'package:psych':
##
## describe
##
## The following objects are masked from 'package:base':
##
## format.pval, units
library(pls)
## Warning: package 'pls' was built under R version 4.2.3
##
## Attaching package: 'pls'
##
## The following object is masked from 'package:corrplot':
##
## corrplot
##
## The following object is masked from 'package:stats':
##
## loadings
library(ppcor)
## Warning: package 'ppcor' was built under R version 4.2.3
library(Hmisc)
library(knitr) # For kable
library(tools) # For toTitleCase
library(kableExtra)
## Warning: package 'kableExtra' was built under R version 4.2.3
##
## Attaching package: 'kableExtra'
##
## The following object is masked from 'package:dplyr':
##
## group_rows
conflicted::conflicts_prefer(dplyr::select(),
dplyr::filter(),
dplyr::summarize())
## [conflicted] Will prefer dplyr::select over any other package.
## [conflicted] Will prefer dplyr::filter over any other package.
## [conflicted] Will prefer dplyr::summarize over any other package.
conflicted::conflicts_prefer(corrplot::corrplot)
## [conflicted] Will prefer corrplot::corrplot over any other package.
squaredDATA <- read.csv("C:/Users/John Majoubi/Documents/All_Jan2_Updated.csv",
stringsAsFactors=TRUE,
na.strings = c('NA', 'na', 'Missing', '_')) |>
mutate(ID = 1:n(), .before=1)
str(squaredDATA)
## 'data.frame': 354 obs. of 238 variables:
## $ ID : int 1 2 3 4 5 6 7 8 9 10 ...
## $ Index : int 82 1 21 356 212 96 15 259 28 264 ...
## $ StartDate : Factor w/ 346 levels " ","1/26/2023 16:03",..: 173 112 129 70 267 203 134 301 73 303 ...
## $ EndDate : Factor w/ 351 levels " ","1/29/2023 3:02",..: 176 115 134 70 270 207 128 306 73 311 ...
## $ IPAddress : Factor w/ 347 levels "","104.13.61.174",..: 43 321 314 228 86 27 117 136 169 171 ...
## $ Progress : int 100 100 100 100 100 100 100 100 100 100 ...
## $ Duration__in_seconds : int 6170 1033 1994 1165 1653 1139 2455 1963 1234 2619 ...
## $ Finished : int 1 1 1 1 1 1 1 1 1 1 ...
## $ LocationLatitude : num 37.7 37.5 37.7 37.8 37.7 ...
## $ LocationLongitude : num -122 -122 -122 -122 -122 ...
## $ Consent : int 1 1 1 1 1 1 1 1 1 1 ...
## $ SFSUID : Factor w/ 354 levels "","000492","014740",..: 2 3 4 5 6 7 8 9 10 11 ...
## $ Name : Factor w/ 354 levels "","Aaliyah Castrence",..: 12 299 310 249 43 353 200 264 292 142 ...
## $ email : Factor w/ 354 levels ""," acarpenter@sfsu.edu",..: 38 296 298 239 48 349 218 273 290 99 ...
## $ Understand_English : int 7 7 6 7 7 6 5 6 6 6 ...
## $ Speak_English : int 7 7 6 7 6 6 5 6 6 6 ...
## $ EngPro : num 7 7 6 7 6.5 6 5 6 6 6 ...
## $ Read_English : int 7 7 6 7 7 6 5 6 6 5 ...
## $ Write_English : int 7 7 6 7 6 6 5 6 6 4 ...
## $ L2 : int 1 2 1 2 1 2 1 1 1 1 ...
## $ L2_name : Factor w/ 55 levels "","Arabic","Burmese",..: 41 1 42 1 49 1 42 9 40 42 ...
## $ Understand2 : int 7 NA 1 NA 7 NA 6 2 4 6 ...
## $ Speak_2 : int 6 NA 1 NA 5 NA 6 1 2 6 ...
## $ NonEngPro : num 6.5 NA 1 NA 6 NA 6 1.5 3 6 ...
## $ P2 : num 6.5 NA 1 NA 6 NA 5 1.5 3 6 ...
## $ P1 : num 7 NA 6 NA 6.5 NA 6 6 6 6 ...
## $ P2P1ratio : num 0.929 NA 0.167 NA 0.923 ...
## $ Read2 : int 7 NA 1 NA 4 NA 6 1 3 6 ...
## $ Write2 : int 5 NA 1 NA 2 NA 5 1 3 6 ...
## $ L3 : int 2 2 2 NA 1 NA 2 2 1 2 ...
## $ L3_name : Factor w/ 25 levels "","American Sign Language (ASL)",..: 1 1 1 1 23 1 1 1 15 1 ...
## $ Understand_3 : int NA NA NA NA 2 NA NA NA 3 NA ...
## $ Speak_3 : int NA NA NA NA 1 NA NA NA 3 NA ...
## $ Read_3 : int NA NA NA NA 3 NA NA NA 3 NA ...
## $ Write_3 : int NA NA NA NA 1 NA NA NA 3 NA ...
## $ NumUsedNow : int 2 1 1 1 1 1 2 1 2 2 ...
## $ NumUsedChild : int 2 1 1 1 1 1 2 2 3 1 ...
## $ Live : int 1 NA 1 NA 2 NA 2 1 2 2 ...
## $ Family : int 2 NA 1 NA 2 NA 1 1 2 2 ...
## $ Friends : int 2 NA 1 NA 1 NA 2 1 1 2 ...
## $ Work : int 2 NA 1 NA 2 NA 1 NA NA 2 ...
## $ School : int 2 NA 1 NA 1 NA 1 1 1 2 ...
## $ Community : int 2 NA 1 NA 1 NA 2 2 1 2 ...
## $ Media : int 2 NA 2 NA 2 NA 2 3 3 2 ...
## $ Entropy : num 1.86 NA 1.14 NA 1.57 ...
## $ NonEnglishL2 : Factor w/ 55 levels "","Arabic","Burmese",..: 41 1 42 1 49 1 42 9 40 42 ...
## $ EnglishAoA : int 0 0 0 NA 0 NA 9 0 3 15 ...
## $ NonEnglishAoA : int 0 NA 14 NA 0 NA 0 0 0 0 ...
## $ L2_AoA : int 0 NA 14 NA 0 NA 9 0 3 15 ...
## $ YearsL2 : int 19 NA 5 NA 19 NA 18 20 NA 15 ...
## $ BalanceUse : num 40 NA 10 NA 20 NA 47 5 11 50 ...
## $ PercentMost : num 60 NA 90 NA 80 NA 53 95 89 50 ...
## $ PercentSecond : num 40 0 10 NA 20 NA 47 5 5 50 ...
## $ PercentThird : num 0 0 0 NA 0 NA 0 0 6 0 ...
## $ SwitchPerDay : int 2 1 1 NA 2 NA 3 1 1 6 ...
## $ SwitchPerSentence : int 4 1 1 NA 2 NA 3 2 2 4 ...
## $ Groups3 : int 0 1 1 1 0 1 0 2 1 0 ...
## $ SexBirth_ : Factor w/ 11 levels "","Doctors do not have the power to assign a sex. If we're going to produce scientific study, we should",..: 4 4 5 5 5 7 5 5 1 7 ...
## $ SexIdentify : Factor w/ 24 levels "","Androgynous",..: 5 5 6 2 6 13 6 6 1 13 ...
## $ Age : int 19 25 19 20 19 20 27 20 NA 30 ...
## $ CountryBorn_ : Factor w/ 39 levels "","Australia",..: 33 37 37 37 37 37 10 37 1 10 ...
## $ CountryReside : Factor w/ 23 levels "","CA","california",..: 13 21 21 21 21 21 21 21 1 21 ...
## $ MomEd : int 7 4 8 5 7 8 5 1 NA 2 ...
## $ DadEd : int 5 5 7 7 7 7 6 5 NA 2 ...
## $ Child_SES : int 4 3 4 2 3 4 3 2 NA 3 ...
## $ NowSES : int 4 3 3 1 3 3 2 2 NA 2 ...
## $ BSC1 : int 4 3 3 3 4 2 4 4 2 4 ...
## $ BSC2 : int 3 4 3 4 3 2 4 3 5 3 ...
## $ BSC3 : int 5 3 3 2 2 4 3 5 2 3 ...
## $ BSC4 : int 3 2 2 4 2 2 2 4 1 2 ...
## $ BSC5 : int 2 4 2 5 3 2 2 3 2 2 ...
## $ BSC6 : int 3 2 2 3 4 4 4 4 4 2 ...
## $ BSC7 : int 4 2 4 5 5 3 4 3 5 4 ...
## $ BSC8 : int 3 4 2 1 3 3 3 3 1 3 ...
## $ BSC9 : int 4 2 4 3 3 4 4 2 3 3 ...
## $ BSC10 : int 5 1 4 3 2 4 5 3 4 3 ...
## $ BSC11 : int 5 5 3 5 4 3 4 3 1 4 ...
## $ BSC12 : int 4 1 3 2 4 1 2 2 4 3 ...
## $ BSC13 : int 4 1 1 1 2 2 2 2 2 3 ...
## $ SE1 : int 3 2 3 3 3 3 3 2 1 3 ...
## $ SE2 : int 3 3 3 3 2 3 2 3 4 2 ...
## $ SE3 : int 3 3 3 3 3 3 3 3 2 3 ...
## $ SE4 : int 3 2 3 3 2 3 2 2 1 3 ...
## $ SE5 : int 2 3 3 3 2 2 2 3 3 2 ...
## $ SE6 : int 3 4 3 3 2 3 2 3 4 2 ...
## $ SE7 : int 3 2 3 3 4 2 3 3 1 3 ...
## $ SE8 : int 3 4 3 3 4 4 3 3 1 2 ...
## $ SE9 : int 2 3 1 2 1 2 2 3 4 2 ...
## $ SE10 : int 2 2 2 3 3 3 3 2 1 3 ...
## $ MH1 : int 2 1 3 3 2 2 3 2 2 1 ...
## $ MH2 : int 4 2 3 3 4 2 3 4 2 3 ...
## $ MH3 : int 2 3 3 4 2 2 2 4 2 2 ...
## $ MH4 : int 2 3 2 3 2 1 2 2 2 1 ...
## $ MH5 : int 2 3 3 4 4 1 3 4 2 2 ...
## $ MH6 : int 2 3 2 2 4 3 3 4 2 2 ...
## $ MH7 : int 1 2 2 2 3 1 2 2 2 1 ...
## $ MH8 : int 3 2 3 2 3 2 3 2 2 2 ...
## $ MH9 : int 2 3 4 3 3 2 3 3 2 2 ...
## $ MH10 : int 3 3 3 2 4 2 2 3 2 1 ...
## [list output truncated]
data.frame(names(squaredDATA))
## names.squaredDATA.
## 1 ID
## 2 Index
## 3 StartDate
## 4 EndDate
## 5 IPAddress
## 6 Progress
## 7 Duration__in_seconds
## 8 Finished
## 9 LocationLatitude
## 10 LocationLongitude
## 11 Consent
## 12 SFSUID
## 13 Name
## 14 email
## 15 Understand_English
## 16 Speak_English
## 17 EngPro
## 18 Read_English
## 19 Write_English
## 20 L2
## 21 L2_name
## 22 Understand2
## 23 Speak_2
## 24 NonEngPro
## 25 P2
## 26 P1
## 27 P2P1ratio
## 28 Read2
## 29 Write2
## 30 L3
## 31 L3_name
## 32 Understand_3
## 33 Speak_3
## 34 Read_3
## 35 Write_3
## 36 NumUsedNow
## 37 NumUsedChild
## 38 Live
## 39 Family
## 40 Friends
## 41 Work
## 42 School
## 43 Community
## 44 Media
## 45 Entropy
## 46 NonEnglishL2
## 47 EnglishAoA
## 48 NonEnglishAoA
## 49 L2_AoA
## 50 YearsL2
## 51 BalanceUse
## 52 PercentMost
## 53 PercentSecond
## 54 PercentThird
## 55 SwitchPerDay
## 56 SwitchPerSentence
## 57 Groups3
## 58 SexBirth_
## 59 SexIdentify
## 60 Age
## 61 CountryBorn_
## 62 CountryReside
## 63 MomEd
## 64 DadEd
## 65 Child_SES
## 66 NowSES
## 67 BSC1
## 68 BSC2
## 69 BSC3
## 70 BSC4
## 71 BSC5
## 72 BSC6
## 73 BSC7
## 74 BSC8
## 75 BSC9
## 76 BSC10
## 77 BSC11
## 78 BSC12
## 79 BSC13
## 80 SE1
## 81 SE2
## 82 SE3
## 83 SE4
## 84 SE5
## 85 SE6
## 86 SE7
## 87 SE8
## 88 SE9
## 89 SE10
## 90 MH1
## 91 MH2
## 92 MH3
## 93 MH4
## 94 MH5
## 95 MH6
## 96 MH7
## 97 MH8
## 98 MH9
## 99 MH10
## 100 MH11
## 101 MH12
## 102 SWL1
## 103 SWL2
## 104 SWL3
## 105 SWL4
## 106 SWL5
## 107 Hap1
## 108 Hap2
## 109 Hap3
## 110 Hap4
## 111 SD1
## 112 SD2
## 113 SD3
## 114 SD4
## 115 SD5
## 116 SD6
## 117 SD7
## 118 SD8
## 119 SD9
## 120 SD10
## 121 SD11
## 122 SD12
## 123 SD13
## 124 SD14
## 125 SD15
## 126 SD16
## 127 Premed1
## 128 Premed2
## 129 Premed3
## 130 Premed4
## 131 Premed5
## 132 Premed6
## 133 Premed7
## 134 Premed8
## 135 Premed9
## 136 Premed10
## 137 Premed11
## 138 Urg1
## 139 Urg2
## 140 Urg3
## 141 Urg4
## 142 Urg5
## 143 Urg6
## 144 Urg7
## 145 Urg8
## 146 Urg9
## 147 Urg10
## 148 Urg11
## 149 Urg12
## 150 Per1
## 151 Per2
## 152 Per3
## 153 Per4
## 154 Per5
## 155 Per6
## 156 Per7
## 157 Per8
## 158 Per9
## 159 Per10
## 160 Raven1
## 161 Raven2
## 162 Raven3
## 163 Raven4
## 164 Raven5
## 165 Raven6
## 166 Raven7
## 167 Raven8
## 168 Raven9
## 169 Raven10
## 170 Raven11
## 171 Raven12
## 172 RavenSum
## 173 ACS1
## 174 ACS2
## 175 ACS3
## 176 ACS4
## 177 ACS5
## 178 ACS6
## 179 ACS7
## 180 ACS8
## 181 ACS9
## 182 ACS10
## 183 ASC11
## 184 ASC12
## 185 ACS13
## 186 ACS14
## 187 ACS15
## 188 ACS16
## 189 ACS17
## 190 ACS18
## 191 ACS19
## 192 ACS20
## 193 PaidAttention
## 194 AnsweredHonestly
## 195 BSCmean
## 196 PremedMean
## 197 UrgencyMeanR
## 198 PerseveranceMean
## 199 FocusingMean
## 200 ShiftingMean
## 201 ACSmean
## 202 SelfEsteemMean
## 203 MentalHealthMean
## 204 SatisLifeMean
## 205 HappinessMean
## 206 SocialDesire
## 207 Flanker.SQ
## 208 Stroop.SQ
## 209 Simon.SQ
## 210 NeutralMeanRT
## 211 NeutralSD
## 212 NeutralPC
## 213 Anti1MeanRT
## 214 Anti1SD
## 215 Anti1PC
## 216 Anti2MeanRT
## 217 Anti2SD
## 218 Anti2PC
## 219 AntiMeanRTall
## 220 PureMean
## 221 PureSD
## 222 PurePC
## 223 RepeatMean
## 224 RepeatSD
## 225 RepeatPC
## 226 SwitchMean
## 227 SwitchSD
## 228 SwitchPC
## 229 SwitchCostRT
## 230 SwitchCostPC
## 231 MixingCostRT
## 232 MixingCostPC
## 233 X
## 234 MINT.Score
## 235 Credits.Earned
## 236 GPA
## 237 Reversed_AntisaccadeMeanRTAll
## 238 Reversed_SwitchCost
colnames(squaredDATA)
## [1] "ID" "Index"
## [3] "StartDate" "EndDate"
## [5] "IPAddress" "Progress"
## [7] "Duration__in_seconds" "Finished"
## [9] "LocationLatitude" "LocationLongitude"
## [11] "Consent" "SFSUID"
## [13] "Name" "email"
## [15] "Understand_English" "Speak_English"
## [17] "EngPro" "Read_English"
## [19] "Write_English" "L2"
## [21] "L2_name" "Understand2"
## [23] "Speak_2" "NonEngPro"
## [25] "P2" "P1"
## [27] "P2P1ratio" "Read2"
## [29] "Write2" "L3"
## [31] "L3_name" "Understand_3"
## [33] "Speak_3" "Read_3"
## [35] "Write_3" "NumUsedNow"
## [37] "NumUsedChild" "Live"
## [39] "Family" "Friends"
## [41] "Work" "School"
## [43] "Community" "Media"
## [45] "Entropy" "NonEnglishL2"
## [47] "EnglishAoA" "NonEnglishAoA"
## [49] "L2_AoA" "YearsL2"
## [51] "BalanceUse" "PercentMost"
## [53] "PercentSecond" "PercentThird"
## [55] "SwitchPerDay" "SwitchPerSentence"
## [57] "Groups3" "SexBirth_"
## [59] "SexIdentify" "Age"
## [61] "CountryBorn_" "CountryReside"
## [63] "MomEd" "DadEd"
## [65] "Child_SES" "NowSES"
## [67] "BSC1" "BSC2"
## [69] "BSC3" "BSC4"
## [71] "BSC5" "BSC6"
## [73] "BSC7" "BSC8"
## [75] "BSC9" "BSC10"
## [77] "BSC11" "BSC12"
## [79] "BSC13" "SE1"
## [81] "SE2" "SE3"
## [83] "SE4" "SE5"
## [85] "SE6" "SE7"
## [87] "SE8" "SE9"
## [89] "SE10" "MH1"
## [91] "MH2" "MH3"
## [93] "MH4" "MH5"
## [95] "MH6" "MH7"
## [97] "MH8" "MH9"
## [99] "MH10" "MH11"
## [101] "MH12" "SWL1"
## [103] "SWL2" "SWL3"
## [105] "SWL4" "SWL5"
## [107] "Hap1" "Hap2"
## [109] "Hap3" "Hap4"
## [111] "SD1" "SD2"
## [113] "SD3" "SD4"
## [115] "SD5" "SD6"
## [117] "SD7" "SD8"
## [119] "SD9" "SD10"
## [121] "SD11" "SD12"
## [123] "SD13" "SD14"
## [125] "SD15" "SD16"
## [127] "Premed1" "Premed2"
## [129] "Premed3" "Premed4"
## [131] "Premed5" "Premed6"
## [133] "Premed7" "Premed8"
## [135] "Premed9" "Premed10"
## [137] "Premed11" "Urg1"
## [139] "Urg2" "Urg3"
## [141] "Urg4" "Urg5"
## [143] "Urg6" "Urg7"
## [145] "Urg8" "Urg9"
## [147] "Urg10" "Urg11"
## [149] "Urg12" "Per1"
## [151] "Per2" "Per3"
## [153] "Per4" "Per5"
## [155] "Per6" "Per7"
## [157] "Per8" "Per9"
## [159] "Per10" "Raven1"
## [161] "Raven2" "Raven3"
## [163] "Raven4" "Raven5"
## [165] "Raven6" "Raven7"
## [167] "Raven8" "Raven9"
## [169] "Raven10" "Raven11"
## [171] "Raven12" "RavenSum"
## [173] "ACS1" "ACS2"
## [175] "ACS3" "ACS4"
## [177] "ACS5" "ACS6"
## [179] "ACS7" "ACS8"
## [181] "ACS9" "ACS10"
## [183] "ASC11" "ASC12"
## [185] "ACS13" "ACS14"
## [187] "ACS15" "ACS16"
## [189] "ACS17" "ACS18"
## [191] "ACS19" "ACS20"
## [193] "PaidAttention" "AnsweredHonestly"
## [195] "BSCmean" "PremedMean"
## [197] "UrgencyMeanR" "PerseveranceMean"
## [199] "FocusingMean" "ShiftingMean"
## [201] "ACSmean" "SelfEsteemMean"
## [203] "MentalHealthMean" "SatisLifeMean"
## [205] "HappinessMean" "SocialDesire"
## [207] "Flanker.SQ" "Stroop.SQ"
## [209] "Simon.SQ" "NeutralMeanRT"
## [211] "NeutralSD" "NeutralPC"
## [213] "Anti1MeanRT" "Anti1SD"
## [215] "Anti1PC" "Anti2MeanRT"
## [217] "Anti2SD" "Anti2PC"
## [219] "AntiMeanRTall" "PureMean"
## [221] "PureSD" "PurePC"
## [223] "RepeatMean" "RepeatSD"
## [225] "RepeatPC" "SwitchMean"
## [227] "SwitchSD" "SwitchPC"
## [229] "SwitchCostRT" "SwitchCostPC"
## [231] "MixingCostRT" "MixingCostPC"
## [233] "X" "MINT.Score"
## [235] "Credits.Earned" "GPA"
## [237] "Reversed_AntisaccadeMeanRTAll" "Reversed_SwitchCost"
cor(squaredDATA[, c("BSCmean", "Simon.SQ", "Stroop.SQ", "Flanker.SQ", "GPA", "ACSmean","MentalHealthMean", "HappinessMean", "MixingCostRT", "SelfEsteemMean", "MINT.Score")], use = "pairwise.complete.obs")
## BSCmean Simon.SQ Stroop.SQ Flanker.SQ GPA
## BSCmean 1.00000000 -0.12440809 -0.166755658 -0.11524194 0.14548764
## Simon.SQ -0.12440809 1.00000000 0.419810031 0.47694404 -0.00970841
## Stroop.SQ -0.16675566 0.41981003 1.000000000 0.43307845 0.02932498
## Flanker.SQ -0.11524194 0.47694404 0.433078449 1.00000000 0.03072052
## GPA 0.14548764 -0.00970841 0.029324979 0.03072052 1.00000000
## ACSmean 0.47418182 0.02417897 -0.009682916 0.04375950 -0.04660031
## MentalHealthMean 0.31506494 -0.01223862 -0.169800943 -0.08663265 -0.06465287
## HappinessMean 0.27516659 -0.06563404 -0.179157152 -0.14915280 -0.02832159
## MixingCostRT 0.06553407 -0.33587352 -0.251242147 -0.09563729 0.01636578
## SelfEsteemMean 0.43673358 -0.08591820 -0.210023335 -0.15215140 -0.05645322
## MINT.Score -0.08584071 0.22028895 0.085721134 0.15276914 -0.10443064
## ACSmean MentalHealthMean HappinessMean MixingCostRT
## BSCmean 0.474181820 0.31506494 0.27516659 0.06553407
## Simon.SQ 0.024178968 -0.01223862 -0.06563404 -0.33587352
## Stroop.SQ -0.009682916 -0.16980094 -0.17915715 -0.25124215
## Flanker.SQ 0.043759499 -0.08663265 -0.14915280 -0.09563729
## GPA -0.046600311 -0.06465287 -0.02832159 0.01636578
## ACSmean 1.000000000 0.30848464 0.26012805 0.06492538
## MentalHealthMean 0.308484641 1.00000000 0.48770093 -0.07060651
## HappinessMean 0.260128055 0.48770093 1.00000000 -0.02373489
## MixingCostRT 0.064925382 -0.07060651 -0.02373489 1.00000000
## SelfEsteemMean 0.358760268 0.64324363 0.62171872 -0.03152300
## MINT.Score 0.083293689 0.07735511 -0.00703043 -0.06367980
## SelfEsteemMean MINT.Score
## BSCmean 0.43673358 -0.08584071
## Simon.SQ -0.08591820 0.22028895
## Stroop.SQ -0.21002333 0.08572113
## Flanker.SQ -0.15215140 0.15276914
## GPA -0.05645322 -0.10443064
## ACSmean 0.35876027 0.08329369
## MentalHealthMean 0.64324363 0.07735511
## HappinessMean 0.62171872 -0.00703043
## MixingCostRT -0.03152300 -0.06367980
## SelfEsteemMean 1.00000000 0.06080998
## MINT.Score 0.06080998 1.00000000
squaredDATA |>
select(any_of(c("Simon.SQ", "Stroop.SQ","MentalHealthMean", "Flanker.SQ", "GPA",
"HappinessMean", "MixingCostRT", "SwitchCostRT", "AntiMeanRTall",
"RavenSum", "SelfEsteemMean","PremedMean","UrgencyMeanR",
"FocusingMean", "ShiftingMean", "BSCmean", "PerseveranceMean","MINT.Score",
"MomEd", "DadEd", "SES_Mean", "Credits.Earned", "SocialDesire"))) |>
cor(use = "pairwise.complete.obs")
## Simon.SQ Stroop.SQ MentalHealthMean Flanker.SQ
## Simon.SQ 1.00000000 0.41981003 -0.012238618 0.476944043
## Stroop.SQ 0.41981003 1.00000000 -0.169800943 0.433078449
## MentalHealthMean -0.01223862 -0.16980094 1.000000000 -0.086632655
## Flanker.SQ 0.47694404 0.43307845 -0.086632655 1.000000000
## GPA -0.00970841 0.02932498 -0.064652874 0.030720518
## HappinessMean -0.06563404 -0.17915715 0.487700928 -0.149152804
## MixingCostRT -0.33587352 -0.25124215 -0.070606512 -0.095637295
## SwitchCostRT -0.28261074 -0.33878483 -0.009461691 -0.265962661
## AntiMeanRTall -0.48756914 -0.26868840 0.013996322 -0.269717033
## RavenSum 0.27015122 0.24934149 -0.011660009 0.264152367
## SelfEsteemMean -0.08591820 -0.21002333 0.643243632 -0.152151402
## PremedMean 0.06335631 0.03620343 0.066586118 -0.037078039
## UrgencyMeanR -0.01780793 -0.11939286 0.372601595 -0.009525258
## FocusingMean 0.03438376 0.04646587 0.289753314 0.079401237
## ShiftingMean -0.01026971 -0.06724613 0.256609850 -0.002925288
## BSCmean -0.12440809 -0.16675566 0.315064940 -0.115241941
## PerseveranceMean -0.04479829 -0.10041319 0.226386569 -0.091761074
## MINT.Score 0.22028895 0.08572113 0.077355108 0.152769143
## MomEd 0.03483463 0.05736484 0.083927020 0.010413881
## DadEd 0.14837889 0.12848210 0.068594262 0.121371994
## Credits.Earned -0.01633796 0.05380076 0.048385489 -0.003446535
## SocialDesire 0.01378017 -0.09536171 0.152562785 -0.057186710
## GPA HappinessMean MixingCostRT SwitchCostRT
## Simon.SQ -0.009708410 -0.06563404 -0.3358735168 -0.282610743
## Stroop.SQ 0.029324979 -0.17915715 -0.2512421471 -0.338784829
## MentalHealthMean -0.064652874 0.48770093 -0.0706065117 -0.009461691
## Flanker.SQ 0.030720518 -0.14915280 -0.0956372946 -0.265962661
## GPA 1.000000000 -0.02832159 0.0163657760 0.047208298
## HappinessMean -0.028321588 1.00000000 -0.0237348941 0.064904006
## MixingCostRT 0.016365776 -0.02373489 1.0000000000 0.099497849
## SwitchCostRT 0.047208298 0.06490401 0.0994978489 1.000000000
## AntiMeanRTall 0.105064346 0.07111975 0.1091279424 0.220474089
## RavenSum 0.079562336 -0.02852686 -0.1814557270 -0.095202155
## SelfEsteemMean -0.056453221 0.62171872 -0.0315229967 0.061854769
## PremedMean -0.004421176 0.02870655 0.0661495783 -0.023842742
## UrgencyMeanR 0.007871287 0.32650005 -0.0223290155 -0.052505237
## FocusingMean -0.048357195 0.16970137 0.0999873172 -0.041059528
## ShiftingMean -0.024893747 0.27754042 0.0209100533 0.005089870
## BSCmean 0.145487643 0.27516659 0.0655340658 0.080408882
## PerseveranceMean 0.121505893 0.24510702 0.0955610861 0.169003924
## MINT.Score -0.104430640 -0.00703043 -0.0636798036 0.022565907
## MomEd -0.001352732 -0.04732300 -0.0785795246 -0.014518684
## DadEd 0.082451141 -0.04814046 -0.0215696446 0.038836103
## Credits.Earned -0.020935281 0.06949746 0.0784522745 0.006252753
## SocialDesire -0.017180664 0.17838450 0.0009885639 -0.037868611
## AntiMeanRTall RavenSum SelfEsteemMean PremedMean
## Simon.SQ -0.48756914 0.27015122 -0.08591820 0.063356309
## Stroop.SQ -0.26868840 0.24934149 -0.21002333 0.036203428
## MentalHealthMean 0.01399632 -0.01166001 0.64324363 0.066586118
## Flanker.SQ -0.26971703 0.26415237 -0.15215140 -0.037078039
## GPA 0.10506435 0.07956234 -0.05645322 -0.004421176
## HappinessMean 0.07111975 -0.02852686 0.62171872 0.028706547
## MixingCostRT 0.10912794 -0.18145573 -0.03152300 0.066149578
## SwitchCostRT 0.22047409 -0.09520216 0.06185477 -0.023842742
## AntiMeanRTall 1.00000000 -0.14002210 0.05932954 -0.020951429
## RavenSum -0.14002210 1.00000000 -0.06304418 -0.029347644
## SelfEsteemMean 0.05932954 -0.06304418 1.00000000 0.075600513
## PremedMean -0.02095143 -0.02934764 0.07560051 1.000000000
## UrgencyMeanR -0.04571378 0.05456799 0.42884755 0.239162703
## FocusingMean -0.13343069 -0.02471988 0.27757740 0.096584351
## ShiftingMean -0.21777784 0.00107587 0.35761917 0.133452706
## BSCmean 0.05250122 -0.04140484 0.43673358 0.286565237
## PerseveranceMean 0.09301185 -0.06842390 0.36220544 0.275259684
## MINT.Score -0.23692461 0.23311256 0.06080998 0.072539824
## MomEd 0.01565099 0.17587661 0.01076127 -0.006490156
## DadEd -0.09352464 0.28903081 -0.04500007 -0.050914326
## Credits.Earned -0.02135097 0.01155039 0.04762743 0.003866070
## SocialDesire -0.08005954 -0.09303428 0.22663350 0.225110791
## UrgencyMeanR FocusingMean ShiftingMean BSCmean
## Simon.SQ -0.017807929 0.03438376 -0.010269706 -0.12440809
## Stroop.SQ -0.119392858 0.04646587 -0.067246133 -0.16675566
## MentalHealthMean 0.372601595 0.28975331 0.256609850 0.31506494
## Flanker.SQ -0.009525258 0.07940124 -0.002925288 -0.11524194
## GPA 0.007871287 -0.04835719 -0.024893747 0.14548764
## HappinessMean 0.326500050 0.16970137 0.277540424 0.27516659
## MixingCostRT -0.022329016 0.09998732 0.020910053 0.06553407
## SwitchCostRT -0.052505237 -0.04105953 0.005089870 0.08040888
## AntiMeanRTall -0.045713778 -0.13343069 -0.217777843 0.05250122
## RavenSum 0.054567994 -0.02471988 0.001075870 -0.04140484
## SelfEsteemMean 0.428847546 0.27757740 0.357619175 0.43673358
## PremedMean 0.239162703 0.09658435 0.133452706 0.28656524
## UrgencyMeanR 1.000000000 0.39909411 0.281758755 0.51998896
## FocusingMean 0.399094109 1.00000000 0.490555903 0.41920052
## ShiftingMean 0.281758755 0.49055590 1.000000000 0.40338223
## BSCmean 0.519988964 0.41920052 0.403382235 1.00000000
## PerseveranceMean 0.219500761 0.29734158 0.330409109 0.50539260
## MINT.Score 0.057767840 0.06296220 0.108803750 -0.08584071
## MomEd -0.025404532 0.01050574 -0.020022010 -0.06694669
## DadEd -0.033891979 0.06255646 -0.028322744 -0.09341147
## Credits.Earned -0.030349552 0.12269954 0.188177846 0.03727777
## SocialDesire 0.379700034 0.23215881 0.172363714 0.37708828
## PerseveranceMean MINT.Score MomEd DadEd
## Simon.SQ -0.04479829 0.22028895 0.034834632 0.14837889
## Stroop.SQ -0.10041319 0.08572113 0.057364842 0.12848210
## MentalHealthMean 0.22638657 0.07735511 0.083927020 0.06859426
## Flanker.SQ -0.09176107 0.15276914 0.010413881 0.12137199
## GPA 0.12150589 -0.10443064 -0.001352732 0.08245114
## HappinessMean 0.24510702 -0.00703043 -0.047322995 -0.04814046
## MixingCostRT 0.09556109 -0.06367980 -0.078579525 -0.02156964
## SwitchCostRT 0.16900392 0.02256591 -0.014518684 0.03883610
## AntiMeanRTall 0.09301185 -0.23692461 0.015650992 -0.09352464
## RavenSum -0.06842390 0.23311256 0.175876609 0.28903081
## SelfEsteemMean 0.36220544 0.06080998 0.010761267 -0.04500007
## PremedMean 0.27525968 0.07253982 -0.006490156 -0.05091433
## UrgencyMeanR 0.21950076 0.05776784 -0.025404532 -0.03389198
## FocusingMean 0.29734158 0.06296220 0.010505737 0.06255646
## ShiftingMean 0.33040911 0.10880375 -0.020022010 -0.02832274
## BSCmean 0.50539260 -0.08584071 -0.066946694 -0.09341147
## PerseveranceMean 1.00000000 -0.04065213 -0.045227651 -0.01414401
## MINT.Score -0.04065213 1.00000000 0.307399915 0.28468604
## MomEd -0.04522765 0.30739991 1.000000000 0.61831028
## DadEd -0.01414401 0.28468604 0.618310284 1.00000000
## Credits.Earned 0.07302706 0.11142023 -0.005318247 -0.09684247
## SocialDesire 0.28049295 -0.21774581 -0.112409249 -0.10406379
## Credits.Earned SocialDesire
## Simon.SQ -0.016337956 0.0137801651
## Stroop.SQ 0.053800760 -0.0953617140
## MentalHealthMean 0.048385489 0.1525627847
## Flanker.SQ -0.003446535 -0.0571867102
## GPA -0.020935281 -0.0171806638
## HappinessMean 0.069497463 0.1783845005
## MixingCostRT 0.078452274 0.0009885639
## SwitchCostRT 0.006252753 -0.0378686115
## AntiMeanRTall -0.021350973 -0.0800595449
## RavenSum 0.011550391 -0.0930342767
## SelfEsteemMean 0.047627426 0.2266335033
## PremedMean 0.003866070 0.2251107908
## UrgencyMeanR -0.030349552 0.3797000336
## FocusingMean 0.122699544 0.2321588121
## ShiftingMean 0.188177846 0.1723637136
## BSCmean 0.037277766 0.3770882755
## PerseveranceMean 0.073027055 0.2804929498
## MINT.Score 0.111420231 -0.2177458135
## MomEd -0.005318247 -0.1124092488
## DadEd -0.096842469 -0.1040637941
## Credits.Earned 1.000000000 -0.0672640882
## SocialDesire -0.067264088 1.0000000000
# Assuming squaredDATA is your dataset and it's already loaded into your R environment
# Run the linear regression model with the specified predictors
model <- lm(MentalHealthMean ~ BSCmean + ACSmean + PerseveranceMean + PremedMean + UrgencyMeanR,
data = squaredDATA)
# Summary of the model to interpret the results
summary(model)
##
## Call:
## lm(formula = MentalHealthMean ~ BSCmean + ACSmean + PerseveranceMean +
## PremedMean + UrgencyMeanR, data = squaredDATA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.53419 -0.27240 0.02558 0.32219 1.25212
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.40912 0.23116 1.770 0.0776 .
## BSCmean 0.06617 0.05661 1.169 0.2432
## ACSmean 0.20038 0.08056 2.487 0.0133 *
## PerseveranceMean 0.09432 0.05868 1.607 0.1089
## PremedMean -0.07632 0.05923 -1.289 0.1984
## UrgencyMeanR 0.25468 0.05442 4.680 4.12e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.4423 on 347 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.1867, Adjusted R-squared: 0.175
## F-statistic: 15.93 on 5 and 347 DF, p-value: 3.914e-14
# Standardize the variables
squaredDATA_standardized <- squaredDATA %>%
mutate(across(c(GPA, Anti2PC, NeutralPC, MixingCostPC, RepeatPC, PerseveranceMean, BSCmean), scale))
# Run the linear regression model on standardized data
model_standardized <- lm(GPA ~ Anti2PC + NeutralPC + MixingCostPC + RepeatPC +
PerseveranceMean + BSCmean, data = squaredDATA_standardized)
# Summary of the model to get standardized beta coefficients
summary(model_standardized)
##
## Call:
## lm(formula = GPA ~ Anti2PC + NeutralPC + MixingCostPC + RepeatPC +
## PerseveranceMean + BSCmean, data = squaredDATA_standardized)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.3701 -0.6030 0.1700 0.5768 1.2767
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.240771 0.072174 3.336 0.00116 **
## Anti2PC 0.075275 0.078573 0.958 0.34014
## NeutralPC -0.009125 0.074612 -0.122 0.90288
## MixingCostPC 0.110955 0.079821 1.390 0.16730
## RepeatPC 0.098170 0.082953 1.183 0.23916
## PerseveranceMean 0.078497 0.082518 0.951 0.34353
## BSCmean 0.128123 0.083381 1.537 0.12724
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.7737 on 111 degrees of freedom
## (236 observations deleted due to missingness)
## Multiple R-squared: 0.1034, Adjusted R-squared: 0.05497
## F-statistic: 2.134 on 6 and 111 DF, p-value: 0.05492
# Full model with all predictors
full_model <- lm(MentalHealthMean ~ BSCmean + ACSmean + PerseveranceMean + PremedMean + UrgencyMeanR, data = squaredDATA)
# Stepwise regression starting with the full model (backward elimination)
stepwise_backward <- stepAIC(full_model, direction = "backward")
## Start: AIC=-569.91
## MentalHealthMean ~ BSCmean + ACSmean + PerseveranceMean + PremedMean +
## UrgencyMeanR
##
## Df Sum of Sq RSS AIC
## - BSCmean 1 0.2674 68.165 -570.52
## - PremedMean 1 0.3249 68.222 -570.22
## <none> 67.897 -569.91
## - PerseveranceMean 1 0.5055 68.403 -569.29
## - ACSmean 1 1.2107 69.108 -565.67
## - UrgencyMeanR 1 4.2860 72.183 -550.30
##
## Step: AIC=-570.52
## MentalHealthMean ~ ACSmean + PerseveranceMean + PremedMean +
## UrgencyMeanR
##
## Df Sum of Sq RSS AIC
## - PremedMean 1 0.2676 68.432 -571.14
## <none> 68.165 -570.52
## - PerseveranceMean 1 0.9580 69.123 -567.60
## - ACSmean 1 1.5959 69.761 -564.35
## - UrgencyMeanR 1 6.1411 74.306 -542.07
##
## Step: AIC=-571.14
## MentalHealthMean ~ ACSmean + PerseveranceMean + UrgencyMeanR
##
## Df Sum of Sq RSS AIC
## <none> 68.432 -571.14
## - PerseveranceMean 1 0.7803 69.213 -569.14
## - ACSmean 1 1.6261 70.059 -564.85
## - UrgencyMeanR 1 5.8765 74.309 -544.06
# Stepwise regression starting with an intercept-only model (forward selection)
stepwise_forward <- stepAIC(full_model, scope = list(lower = ~1, upper = ~ BSCmean + ACSmean + PerseveranceMean + PremedMean + UrgencyMeanR), direction = "forward")
## Start: AIC=-569.91
## MentalHealthMean ~ BSCmean + ACSmean + PerseveranceMean + PremedMean +
## UrgencyMeanR
# Print the results
cat("Backward Elimination Results:\n")
## Backward Elimination Results:
print(stepwise_backward)
##
## Call:
## lm(formula = MentalHealthMean ~ ACSmean + PerseveranceMean +
## UrgencyMeanR, data = squaredDATA)
##
## Coefficients:
## (Intercept) ACSmean PerseveranceMean UrgencyMeanR
## 0.2503 0.2252 0.1056 0.2690
cat("\nForward Selection Results:\n")
##
## Forward Selection Results:
print(stepwise_forward)
##
## Call:
## lm(formula = MentalHealthMean ~ BSCmean + ACSmean + PerseveranceMean +
## PremedMean + UrgencyMeanR, data = squaredDATA)
##
## Coefficients:
## (Intercept) BSCmean ACSmean PerseveranceMean
## 0.40912 0.06617 0.20038 0.09432
## PremedMean UrgencyMeanR
## -0.07632 0.25468
# Assuming squaredDATA is your dataset
# Run the linear regression model
modelGPA <- lm(GPA ~ MixingCostPC + RepeatPC + PerseveranceMean + BSCmean, data = squaredDATA)
# Summary of the model to interpret results
summary(modelGPA)
##
## Call:
## lm(formula = GPA ~ MixingCostPC + RepeatPC + PerseveranceMean +
## BSCmean, data = squaredDATA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.15382 -0.28068 0.05491 0.27131 0.64850
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.40485 0.48022 5.008 2.03e-06 ***
## MixingCostPC 0.36527 0.25941 1.408 0.1618
## RepeatPC 0.62828 0.42748 1.470 0.1444
## PerseveranceMean 0.05409 0.08052 0.672 0.5030
## BSCmean 0.12525 0.06997 1.790 0.0761 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.3785 on 114 degrees of freedom
## (235 observations deleted due to missingness)
## Multiple R-squared: 0.0976, Adjusted R-squared: 0.06594
## F-statistic: 3.083 on 4 and 114 DF, p-value: 0.01883
# Step 1: Prepare the Data
# Assuming your dataset is squaredDATA and it's already loaded into your R environment
# Step 2: Create Interaction Term
squaredDATA$BSCmean_SocialDesire <- squaredDATA$BSCmean * squaredDATA$SocialDesire
# Step 3: Linear Model
model <- lm(GPA ~ BSCmean + SocialDesire + BSCmean_SocialDesire, data = squaredDATA)
# Step 4: Summary
summary(model)
##
## Call:
## lm(formula = GPA ~ BSCmean + SocialDesire + BSCmean_SocialDesire,
## data = squaredDATA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.8415 -0.2595 0.1050 0.3811 0.7443
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.59333 0.44370 5.845 1.26e-08 ***
## BSCmean 0.31564 0.14820 2.130 0.034 *
## SocialDesire 0.03788 0.04551 0.832 0.406
## BSCmean_SocialDesire -0.01690 0.01447 -1.167 0.244
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.487 on 317 degrees of freedom
## (33 observations deleted due to missingness)
## Multiple R-squared: 0.0319, Adjusted R-squared: 0.02273
## F-statistic: 3.481 on 3 and 317 DF, p-value: 0.01624
# Assuming squaredDATA is your dataframe and it's already prepared
# Step 2: Create the Interaction Term
squaredDATA$MHM_SD_Interaction <- squaredDATA$MentalHealthMean * squaredDATA$SocialDesire
# Step 3: Linear Model
model <- lm(UrgencyMeanR ~ MentalHealthMean + SocialDesire + MHM_SD_Interaction, data = squaredDATA)
# Step 4: Summary of the Model
summary(model)
##
## Call:
## lm(formula = UrgencyMeanR ~ MentalHealthMean + SocialDesire +
## MHM_SD_Interaction, data = squaredDATA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.39410 -0.29390 0.00433 0.31149 1.16064
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.531992 0.286919 5.339 1.68e-07 ***
## MentalHealthMean 0.281206 0.153363 1.834 0.0676 .
## SocialDesire 0.043308 0.029637 1.461 0.1448
## MHM_SD_Interaction 0.006855 0.015411 0.445 0.6567
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.4556 on 349 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.246, Adjusted R-squared: 0.2395
## F-statistic: 37.95 on 3 and 349 DF, p-value: < 2.2e-16
squaredDATA <- squaredDATA %>%
mutate(UrgencyMeanR_SocialDesire_Interaction = UrgencyMeanR * SocialDesire)
# Step 2: Fit the Linear Model
model <- lm(MentalHealthMean ~ UrgencyMeanR + SocialDesire + UrgencyMeanR_SocialDesire_Interaction, data = squaredDATA)
# Step 3: Check the summary of the model to interpret results
summary(model)
##
## Call:
## lm(formula = MentalHealthMean ~ UrgencyMeanR + SocialDesire +
## UrgencyMeanR_SocialDesire_Interaction, data = squaredDATA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.48484 -0.28431 0.00997 0.33030 1.22052
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.25315 0.35915 3.489 0.000546 ***
## UrgencyMeanR 0.19627 0.14551 1.349 0.178270
## SocialDesire -0.03652 0.03696 -0.988 0.323894
## UrgencyMeanR_SocialDesire_Interaction 0.01526 0.01423 1.072 0.284588
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.4531 on 349 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.1418, Adjusted R-squared: 0.1344
## F-statistic: 19.22 on 3 and 349 DF, p-value: 1.474e-11
# Step 2: Create the interaction term
squaredDATA$interaction_term <- squaredDATA$RavenSum * squaredDATA$Credits.Earned
# Step 3: Fit the linear regression model
model <- lm(GPA ~ RavenSum + Credits.Earned + interaction_term, data = squaredDATA)
# Step 4: Summary of the model to interpret results
summary(model)
##
## Call:
## lm(formula = GPA ~ RavenSum + Credits.Earned + interaction_term,
## data = squaredDATA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.8163 -0.2903 0.1161 0.3982 0.7134
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.9534749 0.2560919 11.533 <2e-16 ***
## RavenSum 0.0527257 0.0267926 1.968 0.0499 *
## Credits.Earned 0.0044136 0.0032615 1.353 0.1769
## interaction_term -0.0005033 0.0003401 -1.480 0.1399
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.4916 on 317 degrees of freedom
## (33 observations deleted due to missingness)
## Multiple R-squared: 0.01363, Adjusted R-squared: 0.004294
## F-statistic: 1.46 on 3 and 317 DF, p-value: 0.2254
# Fit a simple linear regression model with only RavenSum predicting GPA
simple_model <- lm(GPA ~ RavenSum, data = squaredDATA)
# Summary of the model to interpret results
summary(simple_model)
##
## Call:
## lm(formula = GPA ~ RavenSum, data = squaredDATA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.7709 -0.2863 0.1204 0.3991 0.6330
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.26303 0.11544 28.267 <2e-16 ***
## RavenSum 0.01732 0.01215 1.426 0.155
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.4919 on 319 degrees of freedom
## (33 observations deleted due to missingness)
## Multiple R-squared: 0.00633, Adjusted R-squared: 0.003215
## F-statistic: 2.032 on 1 and 319 DF, p-value: 0.155
# Step 1: Create the Moderator Variable
squaredDATA$SES_Mean <- rowMeans(squaredDATA[, c("MomEd", "DadEd", "Child_SES", "NowSES")], na.rm = TRUE)
# Step 2: Create the Interaction Term
squaredDATA$BSCmean_SES_Mean_Interaction <- squaredDATA$BSCmean * squaredDATA$SES_Mean
# Step 3: Fit the Linear Regression Model
moderated_model <- lm(GPA ~ BSCmean + SES_Mean + BSCmean_SES_Mean_Interaction, data = squaredDATA)
# Step 4: Summary of the model to interpret results
summary(moderated_model)
##
## Call:
## lm(formula = GPA ~ BSCmean + SES_Mean + BSCmean_SES_Mean_Interaction,
## data = squaredDATA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.8815 -0.2552 0.1005 0.3931 0.6853
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.76284 0.56514 4.889 1.62e-06 ***
## BSCmean 0.18840 0.17752 1.061 0.289
## SES_Mean 0.06616 0.13475 0.491 0.624
## BSCmean_SES_Mean_Interaction -0.01565 0.04259 -0.367 0.714
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.4907 on 313 degrees of freedom
## (37 observations deleted due to missingness)
## Multiple R-squared: 0.02303, Adjusted R-squared: 0.01367
## F-statistic: 2.459 on 3 and 313 DF, p-value: 0.06281
“MixingCostRT”, “AntiMeanRTall”, “Stroop.SQ”, “Flanker.SQ”,“Simon.SQ”, “MentalHealthMean”,are out for now
# Select only the variables of interest
variables_of_interest <- squaredDATA[, c( "PerseveranceMean","PremedMean", "UrgencyMeanR","ShiftingMean", "RavenSum", "FocusingMean", "SelfEsteemMean", "MomEd", "GPA")]
# Calculate the correlation matrix for these variables
correlation_matrix <- cor(variables_of_interest, use="complete.obs") # 'use' argument deals with missing values
# Display the correlation matrix
print(correlation_matrix)
## PerseveranceMean PremedMean UrgencyMeanR ShiftingMean
## PerseveranceMean 1.00000000 0.271322077 0.239854518 0.343191119
## PremedMean 0.27132208 1.000000000 0.238809036 0.114130955
## UrgencyMeanR 0.23985452 0.238809036 1.000000000 0.279626096
## ShiftingMean 0.34319112 0.114130955 0.279626096 1.000000000
## RavenSum -0.06656827 -0.034145745 0.034325455 -0.004838134
## FocusingMean 0.32225420 0.098106453 0.395252374 0.497417829
## SelfEsteemMean 0.38970911 0.101298637 0.419404985 0.376002994
## MomEd -0.02589212 0.014397372 -0.009616836 -0.008769391
## GPA 0.12473391 -0.004418268 0.011263881 -0.022800443
## RavenSum FocusingMean SelfEsteemMean MomEd
## PerseveranceMean -0.066568269 0.322254203 0.38970911 -0.025892118
## PremedMean -0.034145745 0.098106453 0.10129864 0.014397372
## UrgencyMeanR 0.034325455 0.395252374 0.41940499 -0.009616836
## ShiftingMean -0.004838134 0.497417829 0.37600299 -0.008769391
## RavenSum 1.000000000 -0.027243732 -0.09409481 0.161531554
## FocusingMean -0.027243732 1.000000000 0.27754401 0.007356557
## SelfEsteemMean -0.094094813 0.277544008 1.00000000 0.022078545
## MomEd 0.161531554 0.007356557 0.02207854 1.000000000
## GPA 0.084480826 -0.047502664 -0.04871467 -0.001352732
## GPA
## PerseveranceMean 0.124733907
## PremedMean -0.004418268
## UrgencyMeanR 0.011263881
## ShiftingMean -0.022800443
## RavenSum 0.084480826
## FocusingMean -0.047502664
## SelfEsteemMean -0.048714673
## MomEd -0.001352732
## GPA 1.000000000
“BSCmean”,“PremedMean”, “UrgencyMeanR”,“ShiftingMean”, “RavenSum”, “MentalHealthMean”, “ACSmean”, “FocusingMean”, “PerseveranceMean”,“RavenSum”, “MixingCostRT”, “AntiMeanRTall”, “Stroop.SQ”, “Flanker.SQ”,“Simon.SQ”
variables_of_interest_names = c("MixingCostRT","SwitchCostPC","SwitchCostRT","MixingCostPC","RepeatPC","NeutralPC","NeutralMeanRT","Anti2PC","GPA", "BSCmean","PremedMean", "UrgencyMeanR","ShiftingMean", "RavenSum", "MentalHealthMean", "ACSmean", "FocusingMean", "PerseveranceMean")
weighted_correlation <- wtd.cor(select(squaredDATA,
all_of(variables_of_interest_names)),
weight = pull(squaredDATA))
## Warning in summary.lm(lm(stdz(y, weight = weight) ~ stdz(x, weight = weight), :
## essentially perfect fit: summary may be unreliable
## Warning in summary.lm(lm(stdz(y, weight = weight) ~ stdz(x, weight = weight), :
## essentially perfect fit: summary may be unreliable
## Warning in summary.lm(lm(stdz(y, weight = weight) ~ stdz(x, weight = weight), :
## essentially perfect fit: summary may be unreliable
## Warning in summary.lm(lm(stdz(y, weight = weight) ~ stdz(x, weight = weight), :
## essentially perfect fit: summary may be unreliable
## Warning in summary.lm(lm(stdz(y, weight = weight) ~ stdz(x, weight = weight), :
## essentially perfect fit: summary may be unreliable
## Warning in summary.lm(lm(stdz(y, weight = weight) ~ stdz(x, weight = weight), :
## essentially perfect fit: summary may be unreliable
## Warning in summary.lm(lm(stdz(y, weight = weight) ~ stdz(x, weight = weight), :
## essentially perfect fit: summary may be unreliable
## Warning in summary.lm(lm(stdz(y, weight = weight) ~ stdz(x, weight = weight), :
## essentially perfect fit: summary may be unreliable
## Warning in summary.lm(lm(stdz(y, weight = weight) ~ stdz(x, weight = weight), :
## essentially perfect fit: summary may be unreliable
## Warning in summary.lm(lm(stdz(y, weight = weight) ~ stdz(x, weight = weight), :
## essentially perfect fit: summary may be unreliable
## Warning in summary.lm(lm(stdz(y, weight = weight) ~ stdz(x, weight = weight), :
## essentially perfect fit: summary may be unreliable
## Warning in summary.lm(lm(stdz(y, weight = weight) ~ stdz(x, weight = weight), :
## essentially perfect fit: summary may be unreliable
## Warning in summary.lm(lm(stdz(y, weight = weight) ~ stdz(x, weight = weight), :
## essentially perfect fit: summary may be unreliable
## Warning in summary.lm(lm(stdz(y, weight = weight) ~ stdz(x, weight = weight), :
## essentially perfect fit: summary may be unreliable
## Warning in summary.lm(lm(stdz(y, weight = weight) ~ stdz(x, weight = weight), :
## essentially perfect fit: summary may be unreliable
## Warning in summary.lm(lm(stdz(y, weight = weight) ~ stdz(x, weight = weight), :
## essentially perfect fit: summary may be unreliable
# correlation matrix
weighted_correlation$correlation
## MixingCostRT SwitchCostPC SwitchCostRT MixingCostPC
## MixingCostRT 1.000000000 -0.13950841 0.1767170141 -0.125959361
## SwitchCostPC -0.139508406 1.00000000 -0.2475826431 -0.232401408
## SwitchCostRT 0.176717014 -0.24758264 1.0000000000 0.118259364
## MixingCostPC -0.125959361 -0.23240141 0.1182593635 1.000000000
## RepeatPC -0.091803948 -0.21422731 0.0124599839 0.475243673
## NeutralPC -0.059993893 -0.04124491 -0.0632078127 0.197658410
## NeutralMeanRT -0.132569007 -0.11520230 0.3077228617 0.108109719
## Anti2PC 0.009367436 0.15519773 0.0365541041 0.223800012
## GPA -0.001289517 -0.09304343 0.0460899385 0.198001666
## BSCmean 0.127899725 -0.01540841 0.0914614925 -0.086319100
## PremedMean 0.043819065 0.08077505 -0.0742213214 -0.119094536
## UrgencyMeanR 0.005815829 0.05661869 -0.0612442150 0.008217905
## ShiftingMean 0.055659394 0.07467802 -0.0257485777 -0.085903212
## RavenSum -0.136710980 0.01199909 -0.0869049117 0.082186105
## MentalHealthMean -0.062705585 0.17309680 -0.0003027796 -0.091280682
## ACSmean 0.097607675 0.09915963 -0.0475130772 -0.113898225
## FocusingMean 0.124537093 0.10833649 -0.0562101870 -0.121490094
## PerseveranceMean 0.160199863 -0.03604356 0.1736759198 -0.137918275
## RepeatPC NeutralPC NeutralMeanRT Anti2PC
## MixingCostRT -0.09180395 -0.05999389 -0.132569007 0.009367436
## SwitchCostPC -0.21422731 -0.04124491 -0.115202296 0.155197726
## SwitchCostRT 0.01245998 -0.06320781 0.307722862 0.036554104
## MixingCostPC 0.47524367 0.19765841 0.108109719 0.223800012
## RepeatPC 1.00000000 0.42218739 -0.041523685 0.275755892
## NeutralPC 0.42218739 1.00000000 -0.110930907 0.271235093
## NeutralMeanRT -0.04152369 -0.11093091 1.000000000 0.099008833
## Anti2PC 0.27575589 0.27123509 0.099008833 1.000000000
## GPA 0.23438086 0.13581948 0.118213533 0.137876853
## BSCmean -0.10924270 -0.08234132 0.054004805 -0.060920989
## PremedMean -0.09212740 -0.11734916 -0.078246878 -0.055643564
## UrgencyMeanR -0.07468223 -0.03680620 -0.138927867 0.043979665
## ShiftingMean -0.01331358 -0.07566566 -0.215142023 -0.142579179
## RavenSum 0.20511974 0.05482952 -0.040973197 0.293801291
## MentalHealthMean -0.04707478 -0.20329546 -0.004332666 -0.139400541
## ACSmean -0.06956673 -0.14346247 -0.208285078 -0.178029120
## FocusingMean -0.11450842 -0.17110638 -0.164378587 -0.165801627
## PerseveranceMean -0.14181985 0.01851406 0.047948567 -0.217653088
## GPA BSCmean PremedMean UrgencyMeanR ShiftingMean
## MixingCostRT -0.001289517 0.12789972 0.04381907 0.005815829 0.05565939
## SwitchCostPC -0.093043432 -0.01540841 0.08077505 0.056618688 0.07467802
## SwitchCostRT 0.046089939 0.09146149 -0.07422132 -0.061244215 -0.02574858
## MixingCostPC 0.198001666 -0.08631910 -0.11909454 0.008217905 -0.08590321
## RepeatPC 0.234380865 -0.10924270 -0.09212740 -0.074682227 -0.01331358
## NeutralPC 0.135819475 -0.08234132 -0.11734916 -0.036806198 -0.07566566
## NeutralMeanRT 0.118213533 0.05400480 -0.07824688 -0.138927867 -0.21514202
## Anti2PC 0.137876853 -0.06092099 -0.05564356 0.043979665 -0.14257918
## GPA 1.000000000 0.14430286 -0.02450813 -0.003535110 -0.05347160
## BSCmean 0.144302862 1.00000000 0.28871542 0.493986961 0.38953983
## PremedMean -0.024508133 0.28871542 1.00000000 0.205122526 0.12423243
## UrgencyMeanR -0.003535110 0.49398696 0.20512253 1.000000000 0.26120025
## ShiftingMean -0.053471596 0.38953983 0.12423243 0.261200251 1.00000000
## RavenSum 0.098418670 0.00106989 -0.02849462 0.079741354 -0.01915837
## MentalHealthMean -0.085663668 0.29182604 0.06243054 0.350914747 0.25070368
## ACSmean -0.087738887 0.45422683 0.15213341 0.353639951 0.86803852
## FocusingMean -0.093300926 0.39851147 0.12831387 0.368090719 0.49129954
## PerseveranceMean 0.112330676 0.49042020 0.24627349 0.193618161 0.31608746
## RavenSum MentalHealthMean ACSmean FocusingMean
## MixingCostRT -0.136710980 -0.0627055846 0.09760767 0.124537093
## SwitchCostPC 0.011999092 0.1730967964 0.09915963 0.108336492
## SwitchCostRT -0.086904912 -0.0003027796 -0.04751308 -0.056210187
## MixingCostPC 0.082186105 -0.0912806822 -0.11389823 -0.121490094
## RepeatPC 0.205119744 -0.0470747833 -0.06956673 -0.114508421
## NeutralPC 0.054829518 -0.2032954610 -0.14346247 -0.171106376
## NeutralMeanRT -0.040973197 -0.0043326657 -0.20828508 -0.164378587
## Anti2PC 0.293801291 -0.1394005408 -0.17802912 -0.165801627
## GPA 0.098418670 -0.0856636677 -0.08773889 -0.093300926
## BSCmean 0.001069890 0.2918260420 0.45422683 0.398511474
## PremedMean -0.028494621 0.0624305415 0.15213341 0.128313875
## UrgencyMeanR 0.079741354 0.3509147474 0.35363995 0.368090719
## ShiftingMean -0.019158371 0.2507036812 0.86803852 0.491299541
## RavenSum 1.000000000 -0.0308712471 -0.01541637 -0.005609653
## MentalHealthMean -0.030871247 1.0000000000 0.30954293 0.295586564
## ACSmean -0.015416372 0.3095429297 1.00000000 0.851420462
## FocusingMean -0.005609653 0.2955865638 0.85142046 1.000000000
## PerseveranceMean -0.054077347 0.2089773628 0.36736932 0.313078126
## PerseveranceMean
## MixingCostRT 0.16019986
## SwitchCostPC -0.03604356
## SwitchCostRT 0.17367592
## MixingCostPC -0.13791828
## RepeatPC -0.14181985
## NeutralPC 0.01851406
## NeutralMeanRT 0.04794857
## Anti2PC -0.21765309
## GPA 0.11233068
## BSCmean 0.49042020
## PremedMean 0.24627349
## UrgencyMeanR 0.19361816
## ShiftingMean 0.31608746
## RavenSum -0.05407735
## MentalHealthMean 0.20897736
## ACSmean 0.36736932
## FocusingMean 0.31307813
## PerseveranceMean 1.00000000
corrplot(weighted_correlation$correlation)
# p-values
round(weighted_correlation$p.value, 4)
## MixingCostRT SwitchCostPC SwitchCostRT MixingCostPC RepeatPC
## MixingCostRT 0.0000 0.0506 0.0130 0.0778 0.3027
## SwitchCostPC 0.0506 0.0000 0.0005 0.0010 0.0152
## SwitchCostRT 0.0130 0.0005 0.0000 0.0979 0.8890
## MixingCostPC 0.0778 0.0010 0.0979 0.0000 0.0000
## RepeatPC 0.3027 0.0152 0.8890 0.0000 0.0000
## NeutralPC 0.4994 0.6426 0.4767 0.0247 0.0000
## NeutralMeanRT 0.1342 0.1936 0.0004 0.2226 0.6430
## Anti2PC 0.9161 0.0791 0.6809 0.0108 0.0017
## GPA 0.9864 0.2167 0.5413 0.0081 0.0110
## BSCmean 0.0733 0.8298 0.2012 0.2278 0.2196
## PremedMean 0.5409 0.2592 0.2999 0.0955 0.3010
## UrgencyMeanR 0.9354 0.4294 0.3926 0.9088 0.4021
## ShiftingMean 0.4372 0.2970 0.7195 0.2300 0.8814
## RavenSum 0.0554 0.8671 0.2246 0.2509 0.0202
## MentalHealthMean 0.3814 0.0150 0.9966 0.2021 0.5977
## ACSmean 0.1724 0.1656 0.5073 0.1110 0.4352
## FocusingMean 0.0812 0.1297 0.4327 0.0890 0.1981
## PerseveranceMean 0.0245 0.6151 0.0147 0.0533 0.1103
## NeutralPC NeutralMeanRT Anti2PC GPA BSCmean PremedMean
## MixingCostRT 0.4994 0.1342 0.9161 0.9864 0.0733 0.5409
## SwitchCostPC 0.6426 0.1936 0.0791 0.2167 0.8298 0.2592
## SwitchCostRT 0.4767 0.0004 0.6809 0.5413 0.2012 0.2999
## MixingCostPC 0.0247 0.2226 0.0108 0.0081 0.2278 0.0955
## RepeatPC 0.0000 0.6430 0.0017 0.0110 0.2196 0.3010
## NeutralPC 0.0000 0.1903 0.0011 0.1264 0.3317 0.1658
## NeutralMeanRT 0.1903 0.0000 0.2428 0.1839 0.5248 0.3564
## Anti2PC 0.0011 0.2428 0.0000 0.1207 0.4730 0.5122
## GPA 0.1264 0.1839 0.1207 0.0000 0.0101 0.6638
## BSCmean 0.3317 0.5248 0.4730 0.0101 0.0000 0.0000
## PremedMean 0.1658 0.3564 0.5122 0.6638 0.0000 0.0000
## UrgencyMeanR 0.6648 0.1004 0.6046 0.9500 0.0000 0.0001
## ShiftingMean 0.3725 0.0104 0.0917 0.3426 0.0000 0.0203
## RavenSum 0.5184 0.6295 0.0004 0.0802 0.9841 0.5958
## MentalHealthMean 0.0156 0.9593 0.0992 0.1280 0.0000 0.2447
## ACSmean 0.0897 0.0132 0.0347 0.1190 0.0000 0.0044
## FocusingMean 0.0425 0.0514 0.0494 0.0973 0.0000 0.0165
## PerseveranceMean 0.8275 0.5723 0.0095 0.0457 0.0000 0.0000
## UrgencyMeanR ShiftingMean RavenSum MentalHealthMean ACSmean
## MixingCostRT 0.9354 0.4372 0.0554 0.3814 0.1724
## SwitchCostPC 0.4294 0.2970 0.8671 0.0150 0.1656
## SwitchCostRT 0.3926 0.7195 0.2246 0.9966 0.5073
## MixingCostPC 0.9088 0.2300 0.2509 0.2021 0.1110
## RepeatPC 0.4021 0.8814 0.0202 0.5977 0.4352
## NeutralPC 0.6648 0.3725 0.5184 0.0156 0.0897
## NeutralMeanRT 0.1004 0.0104 0.6295 0.9593 0.0132
## Anti2PC 0.6046 0.0917 0.0004 0.0992 0.0347
## GPA 0.9500 0.3426 0.0802 0.1280 0.1190
## BSCmean 0.0000 0.0000 0.9841 0.0000 0.0000
## PremedMean 0.0001 0.0203 0.5958 0.2447 0.0044
## UrgencyMeanR 0.0000 0.0000 0.1371 0.0000 0.0000
## ShiftingMean 0.0000 0.0000 0.7213 0.0000 0.0000
## RavenSum 0.1371 0.7213 0.0000 0.5654 0.7741
## MentalHealthMean 0.0000 0.0000 0.5654 0.0000 0.0000
## ACSmean 0.0000 0.0000 0.7741 0.0000 0.0000
## FocusingMean 0.0000 0.0000 0.9168 0.0000 0.0000
## PerseveranceMean 0.0003 0.0000 0.3138 0.0001 0.0000
## FocusingMean PerseveranceMean
## MixingCostRT 0.0812 0.0245
## SwitchCostPC 0.1297 0.6151
## SwitchCostRT 0.4327 0.0147
## MixingCostPC 0.0890 0.0533
## RepeatPC 0.1981 0.1103
## NeutralPC 0.0425 0.8275
## NeutralMeanRT 0.0514 0.5723
## Anti2PC 0.0494 0.0095
## GPA 0.0973 0.0457
## BSCmean 0.0000 0.0000
## PremedMean 0.0165 0.0000
## UrgencyMeanR 0.0000 0.0003
## ShiftingMean 0.0000 0.0000
## RavenSum 0.9168 0.3138
## MentalHealthMean 0.0000 0.0001
## ACSmean 0.0000 0.0000
## FocusingMean 0.0000 0.0000
## PerseveranceMean 0.0000 0.0000
detect_outliers_iqr = function(data, multiplier = 1.5) {
# returns logical vector indicating outlier rows in data, based on
# [multiplier]*IQR in every column
data |>
data.frame() |>
mutate(across(where(is.numeric),
~(. < quantile(., 0.25, na.rm=TRUE) - multiplier * IQR(., na.rm=TRUE)) |
(. > quantile(., 0.75, na.rm=TRUE) + multiplier * IQR(., na.rm=TRUE)))) |>
rowSums() > 0
}
#FANCY cORRELATION TABLE
# Load necessary libraries
library(Hmisc) # For rcorr - correlation and significance levels
library(tools) # For toTitleCase - to format row names
# Ensure the apply_if function is correctly defined
apply_if <- function(mat, p, f) {
p[is.na(p)] <- FALSE
mat[p] <- f(mat[p])
return(mat) # Explicitly return the modified mat
}
# Define the apaCorr function
apaCorr <- function(data, corrtype = "pearson",
remove_outliers = FALSE, multiplier = 1.5) {
# Ensure data is a matrix for rcorr
if(!is.matrix(data)) {
data <- as.matrix(data)
}
# Compute correlation and p-values
matCorr <- rcorr(data, type = corrtype)
if(remove_outliers) {
# remove outliers pairwise using IQR criterion
for(i in 1:(ncol(data)-1)) {
for(j in (i+1):ncol(data)) {
outliers = detect_outliers_iqr(data[,c(i,j)], multiplier)
data_clean = data[!outliers,]
corr_temp = rcorr(data_clean[,i], data_clean[,j], type = corrtype)
for(k in 1:length(matCorr)) {
matCorr[[k]][i, j] = corr_temp[[k]][1, 2]
matCorr[[k]][j, i] = corr_temp[[k]][1, 2]
}
}
}
}
# Initial round and assign stars for significance
stars <- apply_if(round(matCorr$r, 2), matCorr$P < 0.05, function(x) paste0(x, "*"))
stars <- apply_if(stars, matCorr$P < 0.01, function(x) paste0(x, "**"))
stars <- apply_if(stars, matCorr$P < 0.001, function(x) paste0(x, "***"))
# Adjust upper and lower triangles for readability
diag(stars) <- "-" # Adjust diagonal
stars[upper.tri(stars)] <- "" # Clear upper triangle
# Prepare row and column names
n <- ncol(stars)
# colnames(stars) <- paste0("Var", 1:n) # Rename columns for clarity
# row.names(stars) <- paste0(1:n, ". ", toTitleCase(gsub("_", " ", row.names(stars))))
# col.names(stars) <- paste0(1:n, ". ", toTitleCase(gsub("_", " ", row.names(stars))))
rownames(stars) <- paste0(toTitleCase(gsub("_", " ", row.names(stars))))
colnames(stars) <- paste0(toTitleCase(gsub("_", " ", row.names(stars))))
sample_sizes = matCorr$n
diag(sample_sizes) <- "-" # Adjust diagonal
sample_sizes[upper.tri(sample_sizes)] <- "" # Clear upper triangle
dimnames(sample_sizes) = dimnames(stars)
return(list(corr_matrix = stars,
pairwise_n = sample_sizes)) # Return the formatted matrix
}
# Assuming squaredDATA is loaded and contains the specified variables
# Select variables from squaredDATA for correlation analysis
selected_data <- squaredDATA %>%
select(Simon.SQ, Stroop.SQ, MentalHealthMean, Flanker.SQ, GPA,
HappinessMean, MixingCostPC, SwitchCostPC, RepeatPC, NeutralPC, AntiMeanRTall,
RavenSum, SelfEsteemMean, PremedMean, UrgencyMeanR,
FocusingMean, ShiftingMean, BSCmean, PerseveranceMean, MINT.Score,
MomEd, DadEd, #SES_Mean,
Credits.Earned, SocialDesire)
# Generate the APA style correlation matrix
apaCorrelationResults <- apaCorr(selected_data, corrtype = "pearson", remove_outliers=TRUE)
# Print the correlation table in APA style
kbl(apaCorrelationResults$corr_matrix,
format = "html",
caption = "APA Style Correlation Table with Significance Levels\n\n\n\n\n") |>
kable_styling('striped') |>
row_spec(0, angle=-45, align='left')
| Simon.SQ | Stroop.SQ | MentalHealthMean | Flanker.SQ | GPA | HappinessMean | MixingCostPC | SwitchCostPC | RepeatPC | NeutralPC | AntiMeanRTall | RavenSum | SelfEsteemMean | PremedMean | UrgencyMeanR | FocusingMean | ShiftingMean | BSCmean | PerseveranceMean | MINT.Score | MomEd | DadEd | Credits.Earned | SocialDesire | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Simon.SQ |
|
|||||||||||||||||||||||
| Stroop.SQ | 0.39****** |
|
||||||||||||||||||||||
| MentalHealthMean | 0 | -0.17* |
|
|||||||||||||||||||||
| Flanker.SQ | 0.48****** | 0.43****** | -0.08 |
|
||||||||||||||||||||
| GPA | -0.03 | 0.04 | -0.09 | 0.08 |
|
|||||||||||||||||||
| HappinessMean | -0.04 | -0.18*** | 0.49****** | -0.15* | -0.04 |
|
||||||||||||||||||
| MixingCostPC | 0.04 | 0.08 | -0.08 | 0.01 | 0.01 | -0.13 |
|
|||||||||||||||||
| SwitchCostPC | 0.01 | 0.03 | 0.04 | 0.05 | -0.04 | 0.07 | -0.44****** |
|
||||||||||||||||
| RepeatPC | 0 | 0.11 | -0.04 | 0.15 | 0.01 | -0.16 | 0.37****** | -0.27*** |
|
|||||||||||||||
| NeutralPC | 0.03 | 0.19* | 0.02 | 0.16 | 0.06 | 0.05 | -0.16 | 0.02 | 0.14 |
|
||||||||||||||
| AntiMeanRTall | -0.42****** | -0.3****** | 0.07 | -0.28****** | 0.03 | 0.1 | 0.04 | -0.08 | 0.07 | 0.12 |
|
|||||||||||||
| RavenSum | 0.29****** | 0.27****** | -0.06 | 0.29****** | 0.13* | -0.04 | -0.03 | -0.03 | 0.2* | 0.11 | -0.12 |
|
||||||||||||
| SelfEsteemMean | -0.07 | -0.22****** | 0.62****** | -0.16* | -0.05 | 0.64****** | -0.16* | 0.08 | -0.06 | 0 | 0.08 | -0.13* |
|
|||||||||||
| PremedMean | 0.07 | 0.03 | 0.06 | -0.02 | -0.02 | 0.02 | -0.1 | -0.03 | -0.09 | -0.04 | -0.06 | -0.04 | 0.08 |
|
||||||||||
| UrgencyMeanR | 0.01 | -0.15* | 0.37****** | -0.02 | 0.02 | 0.34****** | -0.05 | 0.04 | -0.04 | -0.21* | -0.02 | 0.02 | 0.42****** | 0.22****** |
|
|||||||||
| FocusingMean | 0.05 | 0.04 | 0.28****** | 0.09 | -0.05 | 0.14*** | -0.09 | 0.09 | 0.02 | -0.15 | -0.12 | -0.02 | 0.25****** | 0.11* | 0.38****** |
|
||||||||
| ShiftingMean | -0.02 | -0.11 | 0.22****** | -0.02 | -0.03 | 0.23****** | -0.07 | 0.08 | -0.03 | -0.15 | -0.11 | -0.07 | 0.32****** | 0.12* | 0.27****** | 0.45****** |
|
|||||||
| BSCmean | -0.05 | -0.17*** | 0.29****** | -0.12 | 0.17*** | 0.26****** | -0.06 | -0.02 | 0.06 | -0.15 | 0.03 | -0.08 | 0.43****** | 0.29****** | 0.49****** | 0.4****** | 0.35****** |
|
||||||
| PerseveranceMean | -0.01 | -0.09 | 0.23****** | -0.08 | 0.1 | 0.23****** | -0.14 | -0.02 | -0.03 | 0.07 | 0.08 | -0.11* | 0.37****** | 0.28****** | 0.2****** | 0.27****** | 0.27****** | 0.49****** |
|
|||||
| MINT.Score | 0.19*** | 0.19* | -0.02 | 0.2*** | -0.15* | -0.05 | -0.03 | -0.1 | 0.07 | 0.05 | -0.16 | 0.2*** | -0.05 | 0.02 | 0.03 | 0.04 | 0.01 | -0.14* | -0.12 |
|
||||
| MomEd | 0.04 | 0.06 | 0.05 | 0.01 | -0.04 | -0.05 | -0.04 | 0.04 | 0.02 | 0.02 | -0.05 | 0.15*** | 0.02 | 0 | -0.02 | 0.01 | -0.02 | -0.06 | -0.03 | 0.2*** |
|
|||
| DadEd | 0.15* | 0.14* | 0.05 | 0.12 | 0.07 | -0.05 | -0.09 | 0.18* | -0.11 | -0.01 | -0.15* | 0.3****** | -0.04 | -0.06 | -0.03 | 0.07 | -0.02 | -0.08 | 0 | 0.23****** | 0.62****** |
|
||
| Credits.Earned | -0.03 | 0.05 | 0.07 | 0 | -0.11 | 0.07 | 0 | 0.11 | -0.06 | -0.05 | 0.04 | 0 | 0.05 | 0.02 | 0 | 0.12* | 0.18*** | 0.02 | 0.08 | 0.13 | -0.01 | -0.1 |
|
|
| SocialDesire | 0.02 | -0.12 | 0.16*** | -0.06 | -0.04 | 0.18****** | 0.05 | 0.06 | 0.09 | -0.08 | -0.07 | -0.08 | 0.23****** | 0.22****** | 0.36****** | 0.23****** | 0.15*** | 0.37****** | 0.27****** | -0.17* | -0.11* | -0.1 | -0.07 |
|
# Print the correlation table in APA style
kbl(apaCorrelationResults$pairwise_n,
format = "html",
caption = "Pairwise sample sizes for correlation table") |>
kable_styling('striped') |>
row_spec(0, angle=-45, align='left')
| Simon.SQ | Stroop.SQ | MentalHealthMean | Flanker.SQ | GPA | HappinessMean | MixingCostPC | SwitchCostPC | RepeatPC | NeutralPC | AntiMeanRTall | RavenSum | SelfEsteemMean | PremedMean | UrgencyMeanR | FocusingMean | ShiftingMean | BSCmean | PerseveranceMean | MINT.Score | MomEd | DadEd | Credits.Earned | SocialDesire | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Simon.SQ |
|
|||||||||||||||||||||||
| Stroop.SQ | 231 |
|
||||||||||||||||||||||
| MentalHealthMean | 231 | 231 |
|
|||||||||||||||||||||
| Flanker.SQ | 232 | 232 | 233 |
|
||||||||||||||||||||
| GPA | 208 | 209 | 312 | 210 |
|
|||||||||||||||||||
| HappinessMean | 234 | 234 | 350 | 236 | 314 |
|
||||||||||||||||||
| MixingCostPC | 159 | 159 | 170 | 159 | 157 | 172 |
|
|||||||||||||||||
| SwitchCostPC | 175 | 175 | 188 | 175 | 172 | 190 | 165 |
|
||||||||||||||||
| RepeatPC | 116 | 117 | 122 | 116 | 113 | 124 | 109 | 121 |
|
|||||||||||||||
| NeutralPC | 126 | 127 | 133 | 127 | 122 | 135 | 107 | 120 | 117 |
|
||||||||||||||
| AntiMeanRTall | 183 | 182 | 197 | 183 | 177 | 198 | 163 | 181 | 116 | 126 |
|
|||||||||||||
| RavenSum | 230 | 230 | 341 | 232 | 306 | 343 | 169 | 187 | 122 | 133 | 194 |
|
||||||||||||
| SelfEsteemMean | 233 | 233 | 349 | 235 | 313 | 352 | 171 | 189 | 123 | 134 | 197 | 342 |
|
|||||||||||
| PremedMean | 233 | 233 | 349 | 235 | 313 | 352 | 171 | 189 | 123 | 134 | 197 | 342 | 351 |
|
||||||||||
| UrgencyMeanR | 231 | 231 | 346 | 233 | 311 | 349 | 170 | 189 | 122 | 134 | 196 | 339 | 348 | 348 |
|
|||||||||
| FocusingMean | 232 | 232 | 348 | 234 | 312 | 351 | 171 | 188 | 124 | 134 | 196 | 341 | 350 | 350 | 347 |
|
||||||||
| ShiftingMean | 224 | 224 | 340 | 226 | 303 | 342 | 167 | 183 | 120 | 130 | 192 | 332 | 341 | 341 | 338 | 341 |
|
|||||||
| BSCmean | 233 | 233 | 349 | 235 | 313 | 352 | 172 | 189 | 124 | 134 | 197 | 342 | 351 | 351 | 348 | 351 | 342 |
|
||||||
| PerseveranceMean | 233 | 233 | 348 | 235 | 312 | 351 | 172 | 190 | 124 | 135 | 198 | 341 | 350 | 350 | 347 | 349 | 340 | 350 |
|
|||||
| MINT.Score | 185 | 185 | 217 | 185 | 205 | 218 | 132 | 147 | 102 | 108 | 153 | 215 | 217 | 218 | 217 | 216 | 211 | 217 | 216 |
|
||||
| MomEd | 230 | 230 | 346 | 232 | 310 | 349 | 169 | 187 | 122 | 133 | 195 | 340 | 348 | 348 | 345 | 347 | 338 | 348 | 347 | 215 |
|
|||
| DadEd | 229 | 229 | 345 | 231 | 310 | 348 | 169 | 186 | 121 | 132 | 194 | 339 | 347 | 347 | 344 | 346 | 337 | 347 | 346 | 214 | 348 |
|
||
| Credits.Earned | 211 | 212 | 320 | 213 | 314 | 322 | 157 | 173 | 113 | 123 | 179 | 314 | 321 | 321 | 318 | 320 | 311 | 321 | 320 | 206 | 318 | 318 |
|
|
| SocialDesire | 234 | 234 | 350 | 236 | 314 | 353 | 172 | 190 | 124 | 135 | 198 | 343 | 352 | 352 | 349 | 351 | 342 | 352 | 351 | 218 | 349 | 348 | 322 |
|
# Fit a simple linear regression model with GPA_Weighted predicted by MixingCostRT
model <- lm(GPA ~ ACSmean, weights = Credits.Earned, data = squaredDATA)
# Summary of the model to interpret results
summary(model)
##
## Call:
## lm(formula = GPA ~ ACSmean, data = squaredDATA, weights = Credits.Earned)
##
## Weighted Residuals:
## Min 1Q Median 3Q Max
## -14.6028 -2.1314 0.8683 2.7970 6.4378
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.51092 0.17624 19.921 <2e-16 ***
## ACSmean -0.03771 0.07042 -0.536 0.593
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.805 on 319 degrees of freedom
## (33 observations deleted due to missingness)
## Multiple R-squared: 0.0008982, Adjusted R-squared: -0.002234
## F-statistic: 0.2868 on 1 and 319 DF, p-value: 0.5927
StroopRavenReg <- lm(RavenSum ~ Stroop.SQ, weights = Credits.Earned, data = squaredDATA)
# Summary of the model to interpret results
summary(StroopRavenReg)
##
## Call:
## lm(formula = RavenSum ~ Stroop.SQ, data = squaredDATA, weights = Credits.Earned)
##
## Weighted Residuals:
## Min 1Q Median 3Q Max
## -72.979 -9.777 3.242 11.310 33.093
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 7.91378 0.38468 20.572 < 2e-16 ***
## Stroop.SQ 0.04638 0.01054 4.402 1.7e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 17.09 on 211 degrees of freedom
## (141 observations deleted due to missingness)
## Multiple R-squared: 0.08412, Adjusted R-squared: 0.07978
## F-statistic: 19.38 on 1 and 211 DF, p-value: 1.702e-05
List of Cluster variables
Stroop.SQ,“Flanker.SQ” “Simon.SQ”“MixingCostRT”“AntiMeanRTall” “SwitchMean”, “ACSmean” “ShiftingMean”“BSCmean”“FocusingMean” “UrgencyMeanR” “PremedMean”“RavenSum”
# clusterVars= c("Stroop.SQ","Flanker.SQ", "Simon.SQ","MixingCostRT","AntiMeanRTall", "SwitchMean", "ACSmean", "ShiftingMean","BSCmean","FocusingMean", "UrgencyMeanR","PerseveranceMean", "PremedMean","RavenSum")
clusterVars= c("Stroop.SQ","Flanker.SQ", "Simon.SQ", "RavenSum",
"ACSmean","BSCmean", "UrgencyMeanR",
"PerseveranceMean", "PremedMean", "Reversed_AntisaccadeMeanRTAll","Reversed_SwitchCost")
# "Reversed_AntisaccadeMeanRTAll", "Reversed_SwitchCost")
regressionVars = c('GPA', 'MentalHealthMean', 'SatisLifeMean',
'HappinessMean', 'ACSmean', 'BSCmean')
CleanedSquaredData = squaredDATA |>
select(all_of(union(clusterVars, regressionVars))) |>
filter(Flanker.SQ > 0) |>
# mutate(across(c(AntiMeanRTall, SwitchMean), ~-.)) |> # reverse code
drop_na() |>
scale() |>
as.data.frame() |>
mutate(ID = 1:n(), .before=1)
set.seed(123)
outliers = aq.plot(select(CleanedSquaredData, -ID), alpha=0.0001)$outliers
## Projection to the first and second robust principal components.
## Proportion of total variation (explained variance): 0.2659259
table(outliers)
## outliers
## FALSE TRUE
## 132 7
# Subset CleanedSquaredData by removing outliers
CleanedSquaredData = CleanedSquaredData |>
filter(!outliers) |>
mutate(across(-ID, ~scale(.) |> as.numeric()))
#Standard Dev of Attention Control Tests
CleanedSquaredData = CleanedSquaredData |>
rowwise()|>
mutate(SD_AttentionControl= sd(c(Simon.SQ, Stroop.SQ, Flanker.SQ,
Reversed_AntisaccadeMeanRTAll, Reversed_SwitchCost))) |>
ungroup()
CleanedSquaredData |>
select(any_of(c("Simon.SQ", "Stroop.SQ","MentalHealthMean", "Flanker.SQ", "GPA",
"HappinessMean", "MixingCostRT", "SwitchCostRT", "AntiMeanRTall",
"RavenSum", "SelfEsteemMean","PremedMean","UrgencyMeanR",
"FocusingMean", "ShiftingMean", "BSCmean", "PerseveranceMean","MINT.Score",
"MomEd", "DadEd", "SES_Mean", "Credits.Earned","SD_AttentionControl"))) |>
cor(use = "pairwise.complete.obs")
## Simon.SQ Stroop.SQ MentalHealthMean Flanker.SQ
## Simon.SQ 1.000000000 0.46660900 0.081824577 0.541602472
## Stroop.SQ 0.466608996 1.00000000 -0.123882213 0.553490576
## MentalHealthMean 0.081824577 -0.12388221 1.000000000 0.008654385
## Flanker.SQ 0.541602472 0.55349058 0.008654385 1.000000000
## GPA -0.003324433 0.07016934 -0.111166201 0.073205792
## HappinessMean 0.074473301 -0.12848748 0.545563373 -0.080291964
## RavenSum 0.334706051 0.31123100 0.001802854 0.391668175
## PremedMean 0.164455082 0.01921330 0.134706704 0.080582960
## UrgencyMeanR 0.095495097 -0.03296800 0.344047208 0.072086211
## BSCmean -0.065738604 -0.18319435 0.299966904 -0.157698428
## PerseveranceMean -0.057929336 -0.16006574 0.179412964 -0.166332532
## SD_AttentionControl -0.126617965 -0.32950555 -0.011568567 -0.251084040
## GPA HappinessMean RavenSum PremedMean
## Simon.SQ -0.003324433 0.07447330 0.334706051 0.164455082
## Stroop.SQ 0.070169343 -0.12848748 0.311230996 0.019213298
## MentalHealthMean -0.111166201 0.54556337 0.001802854 0.134706704
## Flanker.SQ 0.073205792 -0.08029196 0.391668175 0.080582960
## GPA 1.000000000 -0.04165017 0.060282155 0.078777010
## HappinessMean -0.041650172 1.00000000 0.060106981 0.064485964
## RavenSum 0.060282155 0.06010698 1.000000000 0.001035834
## PremedMean 0.078777010 0.06448596 0.001035834 1.000000000
## UrgencyMeanR 0.154457893 0.37888367 0.126111751 0.242060552
## BSCmean 0.205859824 0.33512840 -0.046252461 0.198491215
## PerseveranceMean 0.251360782 0.25577950 -0.154174844 0.330371966
## SD_AttentionControl 0.100643502 0.06129653 -0.041916366 -0.137935254
## UrgencyMeanR BSCmean PerseveranceMean
## Simon.SQ 0.09549510 -0.06573860 -0.05792934
## Stroop.SQ -0.03296800 -0.18319435 -0.16006574
## MentalHealthMean 0.34404721 0.29996690 0.17941296
## Flanker.SQ 0.07208621 -0.15769843 -0.16633253
## GPA 0.15445789 0.20585982 0.25136078
## HappinessMean 0.37888367 0.33512840 0.25577950
## RavenSum 0.12611175 -0.04625246 -0.15417484
## PremedMean 0.24206055 0.19849121 0.33037197
## UrgencyMeanR 1.00000000 0.59198863 0.26921194
## BSCmean 0.59198863 1.00000000 0.57187166
## PerseveranceMean 0.26921194 0.57187166 1.00000000
## SD_AttentionControl 0.01418373 0.08049405 0.14150789
## SD_AttentionControl
## Simon.SQ -0.12661797
## Stroop.SQ -0.32950555
## MentalHealthMean -0.01156857
## Flanker.SQ -0.25108404
## GPA 0.10064350
## HappinessMean 0.06129653
## RavenSum -0.04191637
## PremedMean -0.13793525
## UrgencyMeanR 0.01418373
## BSCmean 0.08049405
## PerseveranceMean 0.14150789
## SD_AttentionControl 1.00000000
# SquaredClusterData = as.data.frame(scale(na.omit(squaredDATA[,clusterVars])))
# rownames(SquaredClusterData) = NULL
# SquaredClusterData = as.data.frame(scale(SquaredClusterData[c(-93, -219,-234,-83),]))
# rownames(SquaredClusterData) = NULL
# table(aq.plot(SquaredClusterData)$outliers)
ReducedClusterData = CleanedSquaredData |>
transmute(AttentionControl =(Stroop.SQ+Flanker.SQ+Simon.SQ)/3,
SelfControl = (BSCmean+ACSmean)/2) |>
scale() |>
as.data.frame()
ReducedClusterData2 = CleanedSquaredData |>
transmute(AttentionControl2 =(Stroop.SQ+Flanker.SQ+Simon.SQ+RavenSum)/4,
SelfControl2 = (BSCmean+ACSmean+PremedMean+UrgencyMeanR+PerseveranceMean)/5) |>
scale() |>
as.data.frame()
set.seed(123)
#requesting the elbow method
fviz_nbclust(ReducedClusterData, kmeans, method = "wss")
The Elbow method suggests 3-4 clusters
Sil
set.seed(123)
#requesting the elbow method
fviz_nbclust(ReducedClusterData, kmeans, method = "sil")
silhouete suggests 3 clusters.
set.seed(123)
#creating the clusters
Final_3cluster = kmeans(ReducedClusterData, 3, nstart = 25)
#printing the clusters
print(Final_3cluster)
## K-means clustering with 3 clusters of sizes 25, 50, 57
##
## Cluster means:
## AttentionControl SelfControl
## 1 0.4596967 1.40018626
## 2 0.7863654 -0.61636799
## 3 -0.8914156 -0.07344311
##
## Clustering vector:
## [1] 1 3 2 3 2 2 2 2 3 2 3 3 1 1 3 2 3 2 3 3 3 2 3 3 2 1 3 2 2 3 3 2 3 1 2 3 2
## [38] 2 3 2 3 2 3 2 3 1 1 1 3 2 1 3 3 3 3 2 2 3 3 1 2 1 3 3 2 2 1 3 2 1 3 3 2 3
## [75] 3 1 2 3 2 2 1 1 2 3 2 2 3 3 3 2 2 2 2 2 3 3 2 2 1 2 2 1 1 1 2 1 3 3 2 1 3
## [112] 3 3 3 3 3 2 3 3 2 3 3 3 2 3 2 1 3 2 1 1 2
##
## Within cluster sum of squares by cluster:
## [1] 26.41938 35.78349 49.98617
## (between_SS / total_SS = 57.2 %)
##
## Available components:
##
## [1] "cluster" "centers" "totss" "withinss" "tot.withinss"
## [6] "betweenss" "size" "iter" "ifault"
3 clusters accounts for 61.3 percent of the variance
Basic scatterplot with cluster labeling
plot(ReducedClusterData, col = Final_3cluster$cluster)
barplot(Final_3cluster$centers, beside = T)
Add cluster assignments to CleanedSquaredData
CleanedSquaredData = CleanedSquaredData |>
mutate(Cluster = as.factor(Final_3cluster$cluster))
Boxplots of attention control and self control by cluster
ClusterDataForPlotting = ReducedClusterData |>
mutate(Cluster = as.factor(Final_3cluster$cluster)) |>
pivot_longer(c(AttentionControl, SelfControl),
names_to = 'Metric',
values_to = 'Value')
ggplot(ClusterDataForPlotting, aes(x=Cluster, y=Value, fill=Metric)) +
geom_boxplot()
ggplot(ClusterDataForPlotting, aes(x=Value, color=Cluster)) +
facet_grid(Cluster ~ Metric) +
geom_density() +
guides(color='none')
GPALM = lm(GPA ~ Cluster, data = CleanedSquaredData)
summary(GPALM)
##
## Call:
## lm(formula = GPA ~ Cluster, data = CleanedSquaredData)
##
## Residuals:
## Min 1Q Median 3Q Max
## -4.4501 -0.5524 0.3011 0.7448 1.2261
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.2880 0.1992 1.446 0.1505
## Cluster2 -0.2801 0.2439 -1.148 0.2529
## Cluster3 -0.4213 0.2389 -1.764 0.0801 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.9958 on 129 degrees of freedom
## Multiple R-squared: 0.02359, Adjusted R-squared: 0.008448
## F-statistic: 1.558 on 2 and 129 DF, p-value: 0.2145
MentalHealthLM = lm(MentalHealthMean ~ Cluster, data = CleanedSquaredData)
summary(MentalHealthLM)
##
## Call:
## lm(formula = MentalHealthMean ~ Cluster, data = CleanedSquaredData)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.23693 -0.45007 0.05374 0.64523 1.98874
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.5245 0.1936 2.709 0.00766 **
## Cluster2 -0.7792 0.2371 -3.286 0.00131 **
## Cluster3 -0.5310 0.2322 -2.287 0.02383 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.968 on 129 degrees of freedom
## Multiple R-squared: 0.07729, Adjusted R-squared: 0.06298
## F-statistic: 5.402 on 2 and 129 DF, p-value: 0.005583
HappinessLM = lm(HappinessMean ~ Cluster, data = CleanedSquaredData)
summary(HappinessLM)
##
## Call:
## lm(formula = HappinessMean ~ Cluster, data = CleanedSquaredData)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.2566 -0.6289 -0.2458 0.6859 2.2119
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.5282 0.1930 2.737 0.007072 **
## Cluster2 -0.8088 0.2363 -3.422 0.000832 ***
## Cluster3 -0.5136 0.2314 -2.219 0.028210 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.9648 on 129 degrees of freedom
## Multiple R-squared: 0.08339, Adjusted R-squared: 0.06918
## F-statistic: 5.868 on 2 and 129 DF, p-value: 0.003639
ACSLM = lm(ACSmean ~ Cluster, data = CleanedSquaredData)
summary(ACSLM)
##
## Call:
## lm(formula = ACSmean ~ Cluster, data = CleanedSquaredData)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.68694 -0.47592 -0.05718 0.48607 2.76114
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.2783 0.1539 8.304 1.18e-13 ***
## Cluster2 -1.7880 0.1885 -9.484 < 2e-16 ***
## Cluster3 -1.3919 0.1846 -7.538 7.44e-12 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.7697 on 129 degrees of freedom
## Multiple R-squared: 0.4166, Adjusted R-squared: 0.4076
## F-statistic: 46.06 on 2 and 129 DF, p-value: 8.019e-16
SatisfactionLM = lm(SatisLifeMean ~ Cluster, data = CleanedSquaredData)
summary(SatisfactionLM)
##
## Call:
## lm(formula = SatisLifeMean ~ Cluster, data = CleanedSquaredData)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.35209 -0.63924 -0.01639 0.59540 2.31931
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.4263 0.1970 2.164 0.0323 *
## Cluster2 -0.5761 0.2413 -2.388 0.0184 *
## Cluster3 -0.4819 0.2363 -2.039 0.0434 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.985 on 129 degrees of freedom
## Multiple R-squared: 0.0446, Adjusted R-squared: 0.02978
## F-statistic: 3.011 on 2 and 129 DF, p-value: 0.05273
ggplot(ReducedClusterData, aes(x = AttentionControl, y = SelfControl, color = factor(Final_3cluster$cluster))) +
geom_point(alpha = 0.5, size = 2.5) +
theme_minimal() +
labs(title = "Cluster Analysis of Attention and Self Control",
x = "Attention Control",
y = "Self Control",
color = "Cluster") +
scale_color_manual(values = c("blue", "red", "green"))
fviz_cluster(Final_3cluster, data = ReducedClusterData,
ellipse.type = "norm", # Add normal confidence ellipses around clusters
geom = "point", # Use point geometry
palette = c("#2E9FDF", "#00AFBB", "#E7B800"), # Customize colors
ggtheme = theme_minimal()) +
labs(title = "Enhanced Cluster Visualization with factoextra",
subtitle = "K-means clustering of Attention and Self Control")
ReducedClusterData$Cluster <- as.factor(Final_3cluster$cluster)
# Calculate the mean and standard error for 'AttentionControl' and 'SelfControl' for each cluster
cluster_summary <- ReducedClusterData %>%
group_by(Cluster) %>%
summarise(
Mean_AttentionControl = mean(AttentionControl, na.rm = TRUE),
SE_AttentionControl = sd(AttentionControl, na.rm = TRUE) / sqrt(n()),
Mean_SelfControl = mean(SelfControl, na.rm = TRUE),
SE_SelfControl = sd(SelfControl, na.rm = TRUE) / sqrt(n()),
.groups = 'drop')
# long_summary <- cluster_summary %>%
# pivot_longer(
# cols = c(AttentionControl_Mean, SelfControl_Mean),
# names_to = "Measure",
# values_to = "Mean"
# ) %>%
# pivot_longer(
# cols = c(AttentionControl_SE, SelfControl_SE),
# names_to = "Measure_SE",
# values_to = "SE"
# )
#PLS
plsData = squaredDATA |>
mutate(AttentionIntelligence = (Simon.SQ+Flanker.SQ+Stroop.SQ+RavenSum)/4) |>
select(AttentionIntelligence, ASC11, ASC12,
any_of(paste0('ACS', 1:16)), ACS19,
starts_with('BSC'), -contains('mean')) |>
drop_na() |>
scale() |>
as.data.frame()
set.seed(123)
outliers = aq.plot(plsData , alpha=0.000001)$outliers
## Projection to the first and second robust principal components.
## Proportion of total variation (explained variance): 0.1535463
table(outliers)
## outliers
## FALSE TRUE
## 216 15
# Subset CleanedSquaredData by removing outliers
plsData = plsData |>
filter(!outliers) |>
mutate(across(-AttentionIntelligence, ~scale(.) |> as.numeric()))
#the regression equation using the cross-validation, NIPALS, and jackknifing:
pls_mod1 = plsr(AttentionIntelligence ~ ., data = plsData,
method = "oscorespls", validation = "CV", jackknife = T)
summary(pls_mod1)
## Data: X dimension: 216 30
## Y dimension: 216 1
## Fit method: oscorespls
## Number of components considered: 30
##
## VALIDATION: RMSEP
## Cross-validated using 10 random segments.
## (Intercept) 1 comps 2 comps 3 comps 4 comps 5 comps 6 comps
## CV 0.9806 1.0024 1.013 1.040 1.047 1.054 1.053
## adjCV 0.9806 0.9992 1.010 1.033 1.039 1.045 1.045
## 7 comps 8 comps 9 comps 10 comps 11 comps 12 comps 13 comps
## CV 1.054 1.053 1.053 1.053 1.053 1.053 1.053
## adjCV 1.045 1.045 1.044 1.044 1.044 1.044 1.044
## 14 comps 15 comps 16 comps 17 comps 18 comps 19 comps 20 comps
## CV 1.053 1.053 1.053 1.053 1.053 1.053 1.053
## adjCV 1.044 1.044 1.044 1.044 1.044 1.044 1.044
## 21 comps 22 comps 23 comps 24 comps 25 comps 26 comps 27 comps
## CV 1.053 1.053 1.053 1.053 1.053 1.053 1.053
## adjCV 1.044 1.044 1.044 1.044 1.044 1.044 1.044
## 28 comps 29 comps 30 comps
## CV 1.053 1.053 1.053
## adjCV 1.044 1.044 1.044
##
## TRAINING: % variance explained
## 1 comps 2 comps 3 comps 4 comps 5 comps 6 comps
## X 10.834 27.41 32.38 35.69 38.36 42.42
## AttentionIntelligence 9.405 12.35 15.30 16.02 16.25 16.30
## 7 comps 8 comps 9 comps 10 comps 11 comps 12 comps
## X 47.33 50.73 54.17 57.32 60.02 62.57
## AttentionIntelligence 16.31 16.31 16.31 16.31 16.31 16.31
## 13 comps 14 comps 15 comps 16 comps 17 comps
## X 65.21 67.61 69.50 71.62 73.98
## AttentionIntelligence 16.31 16.31 16.31 16.31 16.31
## 18 comps 19 comps 20 comps 21 comps 22 comps
## X 76.85 79.38 81.42 83.28 85.94
## AttentionIntelligence 16.31 16.31 16.31 16.31 16.31
## 23 comps 24 comps 25 comps 26 comps 27 comps
## X 87.97 90.03 91.53 92.88 95.15
## AttentionIntelligence 16.31 16.31 16.31 16.31 16.31
## 28 comps 29 comps 30 comps
## X 96.73 98.35 100.00
## AttentionIntelligence 16.31 16.31 16.31
par(mfcol=c(1,1))
plot(RMSEP(pls_mod1), legendpos = "topright")
set.seed(120349)
pcr_mod1 = pcr(AttentionIntelligence ~ ., data = plsData,
validation = "LOO", jackknife = T)
summary(pcr_mod1)
## Data: X dimension: 216 30
## Y dimension: 216 1
## Fit method: svdpc
## Number of components considered: 30
##
## VALIDATION: RMSEP
## Cross-validated using 216 leave-one-out segments.
## (Intercept) 1 comps 2 comps 3 comps 4 comps 5 comps 6 comps
## CV 0.9806 0.9844 0.9668 0.9724 0.9766 0.9773 0.9789
## adjCV 0.9806 0.9844 0.9668 0.9724 0.9766 0.9772 0.9788
## 7 comps 8 comps 9 comps 10 comps 11 comps 12 comps 13 comps
## CV 0.9820 0.9803 0.9812 0.9893 0.9928 0.9930 0.9959
## adjCV 0.9825 0.9802 0.9812 0.9892 0.9927 0.9929 0.9958
## 14 comps 15 comps 16 comps 17 comps 18 comps 19 comps 20 comps
## CV 0.9976 1.001 0.9997 0.9882 0.9893 0.9935 1.001
## adjCV 0.9972 1.001 0.9996 0.9879 0.9889 0.9932 1.000
## 21 comps 22 comps 23 comps 24 comps 25 comps 26 comps 27 comps
## CV 1.008 1.014 1.016 1.017 1.025 1.03 1.035
## adjCV 1.008 1.014 1.015 1.016 1.025 1.03 1.035
## 28 comps 29 comps 30 comps
## CV 1.044 1.038 1.04
## adjCV 1.044 1.038 1.04
##
## TRAINING: % variance explained
## 1 comps 2 comps 3 comps 4 comps 5 comps 6 comps
## X 21.9248 29.827 36.936 42.167 46.813 51.050
## AttentionIntelligence 0.2527 4.409 4.427 4.503 5.352 5.661
## 7 comps 8 comps 9 comps 10 comps 11 comps 12 comps
## X 54.898 58.703 62.055 65.371 68.39 71.155
## AttentionIntelligence 5.723 6.721 6.775 7.082 7.21 7.741
## 13 comps 14 comps 15 comps 16 comps 17 comps
## X 73.791 76.219 78.620 80.869 82.86
## AttentionIntelligence 8.058 8.535 8.574 9.842 12.03
## 18 comps 19 comps 20 comps 21 comps 22 comps
## X 84.72 86.55 88.31 89.94 91.48
## AttentionIntelligence 12.54 12.86 12.99 12.99 13.40
## 23 comps 24 comps 25 comps 26 comps 27 comps
## X 92.82 94.12 95.38 96.45 97.46
## AttentionIntelligence 13.91 14.14 14.15 14.36 14.39
## 28 comps 29 comps 30 comps
## X 98.4 99.23 100.00
## AttentionIntelligence 14.4 15.97 16.31
plot(RMSEP(pcr_mod1), legendpos = "topright")
pcr_loadings = pcr_mod1$loadings
pcr_loadings = pcr_loadings |> as.numeric() |>
matrix(nrow=nrow(pcr_loadings)) |>as.data.frame() |>
mutate(Variable = names(select(plsData, -AttentionIntelligence)), .before=1) |>
select(1:3) |>
rename(PC1 =2, PC2 =3) |>
pivot_longer(c(PC1, PC2),
names_to = 'Component',
values_to = 'Loading') |>
mutate(Variable = as.factor(Variable))
ggplot(pcr_loadings, aes(y=fct_rev(Variable), x=Loading)) +
facet_wrap(~Component) +
geom_col() +
labs(y='Variable')
PC1:
The variables BSC10, BSC11, BSC12, and BSC13 show the strongest positive loadings on PC1. Several ACS variables (ACS10, ACS13, ACS14, ACS15, and ACS16) also have strong positive loadings, but they appear slightly less influential than the BSC variables based on the length of the bars. PC2:
Unlike PC1, the ACS variables (ACS10, ACS13, ACS14, ACS15, and ACS16) seem to dominate PC2 with the strongest positive loadings. The BSC variables (BSC10, BSC11, BSC12, and BSC13) still show strong loadings on PC2 but are less pronounced compared to their influence on PC1. Based on these observations, we can infer a general distinction:
PC1 seems to be more strongly associated with the BSC variables, implying that PC1 might represent variation in data related to self-control attributes. PC2 appears to be more strongly influenced by the ACS variables, suggesting that PC2 captures variance related to the attention and distractibility attributes. It’s important to note that without additional context on what the ACS and BSC variables represent, these interpretations are purely based on their statistical contributions to the principal components. In practical terms, the meaning of PC1 and PC2 would depend on the actual variables they’re composed of and the nature of the data being analyzed.
For a more precise and contextually relevant interpretation, it would be essential to know the specific domain or subject matter these variables pertain to, as PCA is often used to reduce the dimensionality of the dataset and uncover underlying patterns that may not be immediately obvious.
The distinctions between PC1 and PC2 in terms of the variables’ loadings suggest that each principal component is capturing different aspects or dimensions of the variability within the dataset:
PC1 might represent an underlying factor more associated with BSC variables, with the strongest and medium-strong loadings indicating that these variables contribute significantly to the variance in PC1. These could be factors that these BSC variables have in common. PC2 might capture variance more associated with ACS variables, as indicated by their strong loadings on this component, whereas BSC variables contribute less to the variance in PC2 compared to PC1.
# ggplot(long_summary, aes(x = Cluster, y = Mean, fill = Measure)) +
# geom_bar(stat = "identity", position = position_dodge(width = 0.7)) +
# geom_errorbar(
# aes(ymin = Mean - SE, ymax = Mean + SE),
# width = 0.2,
# position = position_dodge(width = 0.7)
# ) +
# scale_fill_manual(values = c("AttentionControl" = "steelblue", "SelfControl" = "coral")) +
# labs(title = "Attention Control and Self Control by Cluster",
# x = "Cluster",
# y = "Mean",
# fill = "Measure") +
# theme_minimal() +
# theme(legend.position = "bottom")
#
# ```
# ```{r}
# attention_self_control_plot <- ggplot(long_summary, aes(x = Cluster, y = Mean, fill = Measure)) +
# geom_bar(stat = "identity", position = position_dodge(width = 0.7)) +
# geom_errorbar(
# aes(ymin = Mean - SE, ymax = Mean + SE),
# width = 0.2,
# position = position_dodge(width = 0.7)
# ) +
# scale_fill_manual(values = c("AttentionControl" = "pink", "SelfControl" = "blue")) +
# labs(title = "Attention Control and Self Control by Cluster",
# x = "Cluster",
# y = "Mean",
# fill = "Measure") +
# theme_minimal() +theme(legend.position = "bottom")
# print(attention_self_control_plot)
# ```
#
# ```{r}
# dailyscale.clus <- cbind(Final_3cluster$cluster, ReducedClusterData[, 1:2])
# colnames(dailyscale.clus) <- c("cluster", "AttentionControl", "SelfControl")
# ```
#
# ```{r}
# longdata <- as.data.frame(dailyscale.clus) %>%
# pivot_longer(c("AttentionControl", "SelfControl"), names_to = "variable", values_to = "value")
#
# ```
# ```{r}
# summarized.results <- longdata %>%
# group_by(cluster, variable) %>%
# summarise(
# mean = mean(value, na.rm = TRUE),
# se = sd(value, na.rm = TRUE) / sqrt(n()),
# .groups = 'drop'
# )
# ```
#
# ```{r}
# ggplot(summarized.results, aes(x = variable, y = mean, fill = variable)) +
# geom_bar(stat = 'identity', position = 'dodge') +
# geom_errorbar(
# aes(ymin = mean - se, ymax = mean + se),
# width = 0.2,
# position = position_dodge(0.9)
# ) +
# scale_fill_brewer(palette = "Set1") + # This adds color to the bars
# facet_wrap(~cluster) + # Facets the plot by cluster
# theme_minimal() + # Use a minimal theme for aesthetics
# labs(title = "Cluster Analysis of Attention Control and Self Control",
# x = "Variable",
# y = "Mean Value",
# fill = "Variable")
# ```
# ```{r}
# variables <- c("BSCmean", "Simon.SQ", "Stroop.SQ", "Flanker.SQ", "GPA", "ACSmean", "MentalHealthMean", "HappinessMean")
# correlation_results <- list()
#
# ```
# ```{r}
# for(i in 1:max(Final_3cluster$cluster)) {
# # Subset data for the cluster
# cluster_data <- filter(CleanedSquaredData, Cluster == i) %>%
# select(all_of(variables))
#
# # Perform Pearson correlation
# correlation_results[[paste("Cluster", i, sep = " ")]] <- cor(cluster_data, use = "pairwise.complete.obs")
# }
#
# # Display the results
# correlation_results
# ```
#
# ```{r}
# variables <- c("GPA", "ACSmean", "MentalHealthMean", "HappinessMean", "SatisLifeMean")
#
# ```
#
# ```{r}
# long_data <- CleanedSquaredData %>%
# select(Cluster, all_of(variables)) %>%
# pivot_longer(
# cols = -Cluster,
# names_to = "Variable",
# values_to = "Score"
# )
# ```
#
# ```{r}
# # Create a boxplot for each variable with clusters as the x-axis
# ggplot(long_data, aes(x = Cluster, y = Score, fill = Cluster)) +
# geom_boxplot() +
# facet_wrap(~Variable, scales = "free") +
# theme_minimal() +
# theme(legend.position = "none") +
# labs(title = "Comparison of Cluster Scores Across Variables",
# x = "Cluster",
# y = "Score")
# names(squaredDATA)[180:230]
tests_of_interest = factor(c('Flanker.SQ',
'Stroop.SQ',
'Simon.SQ',
'Anti2PC',
'MixingCostPC'),
levels = c('Flanker.SQ',
'Stroop.SQ',
'Simon.SQ',
'Anti2PC',
'MixingCostPC'))
compute_change_across_tests = function(x, y) {
# computes estimated change in standardized test score over the (five) tests
# using linear regression.
mod = lm(y ~ x)
coef(mod)[2] * (length(x) - 1)
}
test_scores_by_student = squaredDATA |>
drop_na(all_of(tests_of_interest)) |>
mutate(across(all_of(tests_of_interest), scale)) |>
pivot_longer(cols = all_of(tests_of_interest),
names_to = 'test_name',
values_to = 'test_score') |>
mutate(test_name = factor(test_name, levels=levels(tests_of_interest))) |>
relocate(test_name, test_score, .after=ID) |>
arrange(ID, test_name) |>
mutate(test_number = as.integer(test_name), .after=ID)
score_change_by_student = test_scores_by_student |>
group_by(ID) |>
summarize(score_change_across_tests = compute_change_across_tests(test_number, test_score))
test_scores_by_student |>
left_join(score_change_by_student) |>
group_by(ID) |>
filter(cur_group_id() <= 16) |>
ungroup() |>
mutate(ID_and_change = str_c('Subj. ',
ID, ' (change=',
round(score_change_across_tests, 3),
')') |>
fct_reorder(ID))|>
ggplot(aes(x = test_name, y = test_score)) +
facet_wrap(~ID_and_change) +
geom_point() +
geom_smooth(aes(x = test_number), method='lm', se=FALSE, color='red') +
theme_bw() +
theme(axis.text.x = element_text(angle=30, hjust=1, vjust=1)) +
labs(x = 'Test',
y = 'Standardized Score on Test',
title = 'Change in Test Performance for 16 Individuals',
caption = '"Change" is measured in terms of standardized score as estimated by the line of best fit')
## Joining with `by = join_by(ID)`
## `geom_smooth()` using formula = 'y ~ x'
test_scores_by_student |>
left_join(score_change_by_student) |>
group_by(ID) |>
filter(cur_group_id() <= 16) |>
ungroup() |>
mutate(ID_and_change = str_c('Subj. ',
ID, ' (change=',
round(score_change_across_tests, 3),
')') |>
fct_reorder(ID))|>
ggplot(aes(x = test_name, y = test_score, group=ID)) +
facet_wrap(~ID_and_change) +
geom_point() +
geom_line(color='blue3') +
theme_bw() +
theme(axis.text.x = element_text(angle=30, hjust=1, vjust=1)) +
labs(x = 'Test',
y = 'Standardized Score on Test',
title = 'Change in Test Performance for 16 Individuals',
caption = '"Change" is measured in terms of standardized score as estimated by the line of best fit')
## Joining with `by = join_by(ID)`
test_scores_by_student |>
left_join(score_change_by_student) |>
group_by(ID) |>
filter(cur_group_id() <= 16) |>
ungroup() |>
mutate(ID_and_change = str_c('Subj. ',
ID, ' (change=',
round(score_change_across_tests, 3),
')') |>
fct_reorder(ID))|>
ggplot(aes(x = test_name, y = test_score, group=ID)) +
facet_wrap(~ID_and_change) +
geom_smooth(method='lm', se=FALSE,
color='red', alpha=0.6, linewidth=0.5) +
geom_line(color='blue3') +
geom_point() +
theme_bw() +
theme(axis.text.x = element_text(angle=30, hjust=1, vjust=1)) +
labs(x = 'Test',
y = 'Standardized Score on Test',
title = 'Change in Test Performance for 16 Individuals',
caption = '"Change" is measured in terms of standardized score as estimated by the line of best fit')
## Joining with `by = join_by(ID)`
## `geom_smooth()` using formula = 'y ~ x'
squaredDATA = squaredDATA |>
left_join(score_change_by_student) |>
relocate(score_change_across_tests, .after = ID)
## Joining with `by = join_by(ID)`
## Repeat correlation analysis done earlier
## Unweighted for now
new_correlation <- wtd.cor(select(squaredDATA,
all_of(variables_of_interest_names),
score_change_across_tests))
## Warning in summary.lm(lm(stdz(y, weight = weight) ~ stdz(x, weight = weight), :
## essentially perfect fit: summary may be unreliable
## Warning in summary.lm(lm(stdz(y, weight = weight) ~ stdz(x, weight = weight), :
## essentially perfect fit: summary may be unreliable
## Warning in summary.lm(lm(stdz(y, weight = weight) ~ stdz(x, weight = weight), :
## essentially perfect fit: summary may be unreliable
## Warning in summary.lm(lm(stdz(y, weight = weight) ~ stdz(x, weight = weight), :
## essentially perfect fit: summary may be unreliable
## Warning in summary.lm(lm(stdz(y, weight = weight) ~ stdz(x, weight = weight), :
## essentially perfect fit: summary may be unreliable
## Warning in summary.lm(lm(stdz(y, weight = weight) ~ stdz(x, weight = weight), :
## essentially perfect fit: summary may be unreliable
## Warning in summary.lm(lm(stdz(y, weight = weight) ~ stdz(x, weight = weight), :
## essentially perfect fit: summary may be unreliable
## Warning in summary.lm(lm(stdz(y, weight = weight) ~ stdz(x, weight = weight), :
## essentially perfect fit: summary may be unreliable
## Warning in summary.lm(lm(stdz(y, weight = weight) ~ stdz(x, weight = weight), :
## essentially perfect fit: summary may be unreliable
## Warning in summary.lm(lm(stdz(y, weight = weight) ~ stdz(x, weight = weight), :
## essentially perfect fit: summary may be unreliable
## Warning in summary.lm(lm(stdz(y, weight = weight) ~ stdz(x, weight = weight), :
## essentially perfect fit: summary may be unreliable
#weight = pull(squaredDATA, Credits.Earned))
# correlation matrix
new_correlation$correlation
## MixingCostRT SwitchCostPC SwitchCostRT MixingCostPC
## MixingCostRT 1.00000000 -0.058253908 0.0994978489 -0.111589432
## SwitchCostPC -0.05825391 1.000000000 -0.2285796683 -0.222670424
## SwitchCostRT 0.09949785 -0.228579668 1.0000000000 0.114682988
## MixingCostPC -0.11158943 -0.222670424 0.1146829885 1.000000000
## RepeatPC -0.06042824 -0.161029640 -0.0050900960 0.421438428
## NeutralPC -0.02806085 0.017714279 -0.1243814462 0.159819703
## NeutralMeanRT -0.09525223 -0.098436693 0.2479445477 0.049176885
## Anti2PC 0.02883454 0.196120751 0.0002082687 0.193306155
## GPA 0.01636578 -0.050884565 0.0472082983 0.129983842
## BSCmean 0.06553407 0.021328077 0.0804088820 -0.100868722
## PremedMean 0.06614958 0.027571135 -0.0238427422 -0.109025829
## UrgencyMeanR -0.02232902 0.064722203 -0.0525052367 0.009523036
## ShiftingMean 0.02091005 0.043075178 0.0050898698 -0.057897145
## RavenSum -0.18145573 0.058205198 -0.0952021552 0.084899236
## MentalHealthMean -0.07060651 0.152698515 -0.0094616910 -0.081628943
## ACSmean 0.06492538 0.095756440 -0.0209332104 -0.082613382
## FocusingMean 0.09998732 0.129146303 -0.0410595277 -0.092742878
## PerseveranceMean 0.09556109 -0.003209739 0.1690039241 -0.111258936
## score_change_across_tests 0.02974833 -0.101948458 0.2819479304 0.640277266
## RepeatPC NeutralPC NeutralMeanRT Anti2PC
## MixingCostRT -0.060428236 -0.02806085 -0.09525223 0.0288345399
## SwitchCostPC -0.161029640 0.01771428 -0.09843669 0.1961207509
## SwitchCostRT -0.005090096 -0.12438145 0.24794455 0.0002082687
## MixingCostPC 0.421438428 0.15981970 0.04917689 0.1933061555
## RepeatPC 1.000000000 0.37669919 -0.05321689 0.2257703633
## NeutralPC 0.376699193 1.00000000 -0.10407734 0.2111924306
## NeutralMeanRT -0.053216887 -0.10407734 1.00000000 0.1117753798
## Anti2PC 0.225770363 0.21119243 0.11177538 1.0000000000
## GPA 0.182602039 0.08401923 0.05208590 0.0990156447
## BSCmean -0.116429503 -0.07672139 0.04569110 -0.0584879354
## PremedMean -0.072718467 -0.10749755 -0.05721162 -0.0687196171
## UrgencyMeanR -0.091186264 -0.05004134 -0.08713402 0.0281584668
## ShiftingMean -0.021056119 -0.07726241 -0.18514433 -0.1329845620
## RavenSum 0.151563115 0.03713738 -0.05047525 0.2396202145
## MentalHealthMean -0.025977500 -0.15899208 0.01843170 -0.0693760612
## ACSmean -0.063407895 -0.11781893 -0.17930852 -0.1531985914
## FocusingMean -0.095911759 -0.12318815 -0.13988204 -0.1283914060
## PerseveranceMean -0.121796080 0.00285322 0.05374313 -0.1972271224
## score_change_across_tests 0.154409923 -0.04292263 0.19365882 0.2610477392
## GPA BSCmean PremedMean UrgencyMeanR
## MixingCostRT 0.016365776 0.06553407 0.066149578 -0.022329016
## SwitchCostPC -0.050884565 0.02132808 0.027571135 0.064722203
## SwitchCostRT 0.047208298 0.08040888 -0.023842742 -0.052505237
## MixingCostPC 0.129983842 -0.10086872 -0.109025829 0.009523036
## RepeatPC 0.182602039 -0.11642950 -0.072718467 -0.091186264
## NeutralPC 0.084019230 -0.07672139 -0.107497547 -0.050041342
## NeutralMeanRT 0.052085899 0.04569110 -0.057211624 -0.087134024
## Anti2PC 0.099015645 -0.05848794 -0.068719617 0.028158467
## GPA 1.000000000 0.14548764 -0.004421176 0.007871287
## BSCmean 0.145487643 1.00000000 0.286565237 0.519988964
## PremedMean -0.004421176 0.28656524 1.000000000 0.239162703
## UrgencyMeanR 0.007871287 0.51998896 0.239162703 1.000000000
## ShiftingMean -0.024893747 0.40338223 0.133452706 0.281758755
## RavenSum 0.079562336 -0.04140484 -0.029347644 0.054567994
## MentalHealthMean -0.064652874 0.31506494 0.066586118 0.372601595
## ACSmean -0.046600311 0.47418182 0.139734796 0.383933490
## FocusingMean -0.048357195 0.41920052 0.096584351 0.399094109
## PerseveranceMean 0.121505893 0.50539260 0.275259684 0.219500761
## score_change_across_tests 0.068509830 0.13787182 -0.131794208 0.018410563
## ShiftingMean RavenSum MentalHealthMean ACSmean
## MixingCostRT 0.02091005 -0.18145573 -0.070606512 0.06492538
## SwitchCostPC 0.04307518 0.05820520 0.152698515 0.09575644
## SwitchCostRT 0.00508987 -0.09520216 -0.009461691 -0.02093321
## MixingCostPC -0.05789714 0.08489924 -0.081628943 -0.08261338
## RepeatPC -0.02105612 0.15156312 -0.025977500 -0.06340790
## NeutralPC -0.07726241 0.03713738 -0.158992082 -0.11781893
## NeutralMeanRT -0.18514433 -0.05047525 0.018431704 -0.17930852
## Anti2PC -0.13298456 0.23962021 -0.069376061 -0.15319859
## GPA -0.02489375 0.07956234 -0.064652874 -0.04660031
## BSCmean 0.40338223 -0.04140484 0.315064940 0.47418182
## PremedMean 0.13345271 -0.02934764 0.066586118 0.13973480
## UrgencyMeanR 0.28175876 0.05456799 0.372601595 0.38393349
## ShiftingMean 1.00000000 0.00107587 0.256609850 0.86530409
## RavenSum 0.00107587 1.00000000 -0.011660009 -0.01979394
## MentalHealthMean 0.25660985 -0.01166001 1.000000000 0.30848464
## ACSmean 0.86530409 -0.01979394 0.308484641 1.00000000
## FocusingMean 0.49055590 -0.02471988 0.289753314 0.85344254
## PerseveranceMean 0.33040911 -0.06842390 0.226386569 0.36815773
## score_change_across_tests 0.06777139 -0.18389905 0.045063519 -0.02756443
## FocusingMean PerseveranceMean
## MixingCostRT 0.09998732 0.095561086
## SwitchCostPC 0.12914630 -0.003209739
## SwitchCostRT -0.04105953 0.169003924
## MixingCostPC -0.09274288 -0.111258936
## RepeatPC -0.09591176 -0.121796080
## NeutralPC -0.12318815 0.002853220
## NeutralMeanRT -0.13988204 0.053743127
## Anti2PC -0.12839141 -0.197227122
## GPA -0.04835719 0.121505893
## BSCmean 0.41920052 0.505392599
## PremedMean 0.09658435 0.275259684
## UrgencyMeanR 0.39909411 0.219500761
## ShiftingMean 0.49055590 0.330409109
## RavenSum -0.02471988 -0.068423903
## MentalHealthMean 0.28975331 0.226386569
## ACSmean 0.85344254 0.368157726
## FocusingMean 1.00000000 0.297341585
## PerseveranceMean 0.29734158 1.000000000
## score_change_across_tests -0.11345547 0.017847859
## score_change_across_tests
## MixingCostRT 0.02974833
## SwitchCostPC -0.10194846
## SwitchCostRT 0.28194793
## MixingCostPC 0.64027727
## RepeatPC 0.15440992
## NeutralPC -0.04292263
## NeutralMeanRT 0.19365882
## Anti2PC 0.26104774
## GPA 0.06850983
## BSCmean 0.13787182
## PremedMean -0.13179421
## UrgencyMeanR 0.01841056
## ShiftingMean 0.06777139
## RavenSum -0.18389905
## MentalHealthMean 0.04506352
## ACSmean -0.02756443
## FocusingMean -0.11345547
## PerseveranceMean 0.01784786
## score_change_across_tests 1.00000000
corrplot(new_correlation$correlation)
# p-values
round(new_correlation$p.value, 4)
## MixingCostRT SwitchCostPC SwitchCostRT MixingCostPC
## MixingCostRT 0.0000 0.4126 0.1610 0.1157
## SwitchCostPC 0.4126 0.0000 0.0011 0.0015
## SwitchCostRT 0.1610 0.0011 0.0000 0.1059
## MixingCostPC 0.1157 0.0015 0.1059 0.0000
## RepeatPC 0.4946 0.0672 0.9542 0.0000
## NeutralPC 0.7504 0.8408 0.1569 0.0682
## NeutralMeanRT 0.2792 0.2633 0.0043 0.5770
## Anti2PC 0.7437 0.0248 0.9981 0.0270
## GPA 0.8269 0.4963 0.5280 0.0812
## BSCmean 0.3565 0.7644 0.2577 0.1553
## PremedMean 0.3520 0.6984 0.7375 0.1243
## UrgencyMeanR 0.7536 0.3625 0.4603 0.8935
## ShiftingMean 0.7688 0.5448 0.9430 0.4154
## RavenSum 0.0101 0.4130 0.1799 0.2320
## MentalHealthMean 0.3205 0.0309 0.8942 0.2505
## ACSmean 0.3610 0.1774 0.7686 0.2448
## FocusingMean 0.1589 0.0684 0.5638 0.1915
## PerseveranceMean 0.1783 0.9640 0.0167 0.1168
## score_change_across_tests 0.7439 0.2618 0.0016 0.0000
## RepeatPC NeutralPC NeutralMeanRT Anti2PC GPA
## MixingCostRT 0.4946 0.7504 0.2792 0.7437 0.8269
## SwitchCostPC 0.0672 0.8408 0.2633 0.0248 0.4963
## SwitchCostRT 0.9542 0.1569 0.0043 0.9981 0.5280
## MixingCostPC 0.0000 0.0682 0.5770 0.0270 0.0812
## RepeatPC 0.0000 0.0000 0.5492 0.0101 0.0468
## NeutralPC 0.0000 0.0000 0.2161 0.0113 0.3419
## NeutralMeanRT 0.5492 0.2161 0.0000 0.1838 0.5562
## Anti2PC 0.0101 0.0113 0.1838 0.0000 0.2624
## GPA 0.0468 0.3419 0.5562 0.2624 0.0000
## BSCmean 0.1871 0.3624 0.5879 0.4878 0.0090
## PremedMean 0.4110 0.2013 0.4973 0.4148 0.9371
## UrgencyMeanR 0.3022 0.5528 0.3008 0.7385 0.8883
## ShiftingMean 0.8120 0.3590 0.0268 0.1133 0.6568
## RavenSum 0.0852 0.6597 0.5494 0.0039 0.1550
## MentalHealthMean 0.7692 0.0579 0.8270 0.4103 0.2481
## ACSmean 0.4736 0.1611 0.0321 0.0677 0.4053
## FocusingMean 0.2777 0.1427 0.0957 0.1265 0.3879
## PerseveranceMean 0.1675 0.9730 0.5238 0.0182 0.0295
## score_change_across_tests 0.0908 0.6374 0.0319 0.0035 0.4749
## BSCmean PremedMean UrgencyMeanR ShiftingMean RavenSum
## MixingCostRT 0.3565 0.3520 0.7536 0.7688 0.0101
## SwitchCostPC 0.7644 0.6984 0.3625 0.5448 0.4130
## SwitchCostRT 0.2577 0.7375 0.4603 0.9430 0.1799
## MixingCostPC 0.1553 0.1243 0.8935 0.4154 0.2320
## RepeatPC 0.1871 0.4110 0.3022 0.8120 0.0852
## NeutralPC 0.3624 0.2013 0.5528 0.3590 0.6597
## NeutralMeanRT 0.5879 0.4973 0.3008 0.0268 0.5494
## Anti2PC 0.4878 0.4148 0.7385 0.1133 0.0039
## GPA 0.0090 0.9371 0.8883 0.6568 0.1550
## BSCmean 0.0000 0.0000 0.0000 0.0000 0.4380
## PremedMean 0.0000 0.0000 0.0000 0.0121 0.5826
## UrgencyMeanR 0.0000 0.0000 0.0000 0.0000 0.3066
## ShiftingMean 0.0000 0.0121 0.0000 0.0000 0.9839
## RavenSum 0.4380 0.5826 0.3066 0.9839 0.0000
## MentalHealthMean 0.0000 0.2120 0.0000 0.0000 0.8272
## ACSmean 0.0000 0.0086 0.0000 0.0000 0.7109
## FocusingMean 0.0000 0.0699 0.0000 0.0000 0.6435
## PerseveranceMean 0.0000 0.0000 0.0000 0.0000 0.1997
## score_change_across_tests 0.1283 0.1462 0.8398 0.4564 0.0417
## MentalHealthMean ACSmean FocusingMean
## MixingCostRT 0.3205 0.3610 0.1589
## SwitchCostPC 0.0309 0.1774 0.0684
## SwitchCostRT 0.8942 0.7686 0.5638
## MixingCostPC 0.2505 0.2448 0.1915
## RepeatPC 0.7692 0.4736 0.2777
## NeutralPC 0.0579 0.1611 0.1427
## NeutralMeanRT 0.8270 0.0321 0.0957
## Anti2PC 0.4103 0.0677 0.1265
## GPA 0.2481 0.4053 0.3879
## BSCmean 0.0000 0.0000 0.0000
## PremedMean 0.2120 0.0086 0.0699
## UrgencyMeanR 0.0000 0.0000 0.0000
## ShiftingMean 0.0000 0.0000 0.0000
## RavenSum 0.8272 0.7109 0.6435
## MentalHealthMean 0.0000 0.0000 0.0000
## ACSmean 0.0000 0.0000 0.0000
## FocusingMean 0.0000 0.0000 0.0000
## PerseveranceMean 0.0000 0.0000 0.0000
## score_change_across_tests 0.6207 0.7622 0.2115
## PerseveranceMean score_change_across_tests
## MixingCostRT 0.1783 0.7439
## SwitchCostPC 0.9640 0.2618
## SwitchCostRT 0.0167 0.0016
## MixingCostPC 0.1168 0.0000
## RepeatPC 0.1675 0.0908
## NeutralPC 0.9730 0.6374
## NeutralMeanRT 0.5238 0.0319
## Anti2PC 0.0182 0.0035
## GPA 0.0295 0.4749
## BSCmean 0.0000 0.1283
## PremedMean 0.0000 0.1462
## UrgencyMeanR 0.0000 0.8398
## ShiftingMean 0.0000 0.4564
## RavenSum 0.1997 0.0417
## MentalHealthMean 0.0000 0.6207
## ACSmean 0.0000 0.7622
## FocusingMean 0.0000 0.2115
## PerseveranceMean 0.0000 0.8447
## score_change_across_tests 0.8447 0.0000
GPA_score_change_lm = lm(score_change_across_tests ~ GPA,
data = squaredDATA)
MentalHealth_score_change_lm = lm(MentalHealthMean ~ score_change_across_tests,
data = squaredDATA)
Happiness_score_change_lm = lm(HappinessMean ~ score_change_across_tests,
data = squaredDATA)
ACS_score_change_lm = lm(ACSmean ~ score_change_across_tests,
data = squaredDATA)
Satisfaction_score_change_lm = lm(SatisLifeMean ~ score_change_across_tests,
data = squaredDATA)
FlankerSQ_score_change_lm = lm(score_change_across_tests ~ Flanker.SQ,
data = squaredDATA)
StroopSQ_score_change_lm = lm(Stroop.SQ ~ score_change_across_tests,
data = squaredDATA)
SimonSQ_score_change_lm = lm(Simon.SQ ~ score_change_across_tests,
data = squaredDATA)
BSCmean_score_change_lm = lm(BSCmean ~ score_change_across_tests,
data = squaredDATA)
Perseverance_score_change_lm = lm(score_change_across_tests ~ PerseveranceMean,
data = squaredDATA)
Antisaccade_score_change_lm = lm(AntiMeanRTall ~ score_change_across_tests,
data = squaredDATA)
SwitchCost_score_change_lm = lm(SwitchMean ~ score_change_across_tests,
data = squaredDATA)
GPAWeighted_score_change_lm = lm(GPA ~ score_change_across_tests,
weights = Credits.Earned,
data = squaredDATA)
Ravens_score_change_lm = lm(score_change_across_tests ~ RavenSum,
data = squaredDATA)
summary(GPA_score_change_lm)
##
## Call:
## lm(formula = score_change_across_tests ~ GPA, data = squaredDATA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.2059 -0.9801 -0.1364 0.8444 4.5817
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.8704 1.1807 -0.737 0.463
## GPA 0.2357 0.3288 0.717 0.475
##
## Residual standard error: 1.3 on 109 degrees of freedom
## (243 observations deleted due to missingness)
## Multiple R-squared: 0.004694, Adjusted R-squared: -0.004438
## F-statistic: 0.514 on 1 and 109 DF, p-value: 0.4749
summary(MentalHealth_score_change_lm)
##
## Call:
## lm(formula = MentalHealthMean ~ score_change_across_tests, data = squaredDATA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.45658 -0.28296 -0.00264 0.35312 0.99915
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.79404 0.05002 35.868 <2e-16 ***
## score_change_across_tests 0.01870 0.03768 0.496 0.621
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.5547 on 121 degrees of freedom
## (231 observations deleted due to missingness)
## Multiple R-squared: 0.002031, Adjusted R-squared: -0.006217
## F-statistic: 0.2462 on 1 and 121 DF, p-value: 0.6207
summary(Happiness_score_change_lm)
##
## Call:
## lm(formula = HappinessMean ~ score_change_across_tests, data = squaredDATA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.7799 -0.9843 -0.0486 0.9318 2.4532
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.52439 0.10313 43.871 <2e-16 ***
## score_change_across_tests -0.02492 0.07768 -0.321 0.749
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.144 on 121 degrees of freedom
## (231 observations deleted due to missingness)
## Multiple R-squared: 0.0008495, Adjusted R-squared: -0.007408
## F-statistic: 0.1029 on 1 and 121 DF, p-value: 0.749
summary(ACS_score_change_lm)
##
## Call:
## lm(formula = ACSmean ~ score_change_across_tests, data = squaredDATA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.80271 -0.24623 -0.00654 0.20333 1.49222
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.401070 0.032625 73.596 <2e-16 ***
## score_change_across_tests -0.007454 0.024576 -0.303 0.762
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.3618 on 121 degrees of freedom
## (231 observations deleted due to missingness)
## Multiple R-squared: 0.0007598, Adjusted R-squared: -0.007498
## F-statistic: 0.09201 on 1 and 121 DF, p-value: 0.7622
summary(Satisfaction_score_change_lm)
##
## Call:
## lm(formula = SatisLifeMean ~ score_change_across_tests, data = squaredDATA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.2194 -0.9991 0.0751 1.0059 2.7764
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.26504 0.12201 34.957 <2e-16 ***
## score_change_across_tests -0.05457 0.09191 -0.594 0.554
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.353 on 121 degrees of freedom
## (231 observations deleted due to missingness)
## Multiple R-squared: 0.002905, Adjusted R-squared: -0.005335
## F-statistic: 0.3526 on 1 and 121 DF, p-value: 0.5538
summary(FlankerSQ_score_change_lm)
##
## Call:
## lm(formula = score_change_across_tests ~ Flanker.SQ, data = squaredDATA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.5836 -0.4567 -0.1536 0.3372 3.5511
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.070189 0.144125 7.425 1.73e-11 ***
## Flanker.SQ -0.050784 0.005303 -9.577 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.009 on 121 degrees of freedom
## (231 observations deleted due to missingness)
## Multiple R-squared: 0.4312, Adjusted R-squared: 0.4265
## F-statistic: 91.72 on 1 and 121 DF, p-value: < 2.2e-16
summary(StroopSQ_score_change_lm)
##
## Call:
## lm(formula = Stroop.SQ ~ score_change_across_tests, data = squaredDATA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -32.232 -4.963 1.824 6.988 37.214
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 32.7805 1.0045 32.634 < 2e-16 ***
## score_change_across_tests -4.5239 0.7566 -5.979 2.34e-08 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 11.14 on 121 degrees of freedom
## (231 observations deleted due to missingness)
## Multiple R-squared: 0.2281, Adjusted R-squared: 0.2217
## F-statistic: 35.75 on 1 and 121 DF, p-value: 2.336e-08
summary(SimonSQ_score_change_lm)
##
## Call:
## lm(formula = Simon.SQ ~ score_change_across_tests, data = squaredDATA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -28.1653 -6.6578 -0.1296 6.9162 18.7881
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 62.5691 0.8760 71.424 < 2e-16 ***
## score_change_across_tests -2.9998 0.6599 -4.546 1.31e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 9.716 on 121 degrees of freedom
## (231 observations deleted due to missingness)
## Multiple R-squared: 0.1459, Adjusted R-squared: 0.1388
## F-statistic: 20.67 on 1 and 121 DF, p-value: 1.306e-05
summary(BSCmean_score_change_lm)
##
## Call:
## lm(formula = BSCmean ~ score_change_across_tests, data = squaredDATA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.18915 -0.43339 -0.04452 0.36335 1.71496
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.10757 0.05130 60.577 <2e-16 ***
## score_change_across_tests 0.05917 0.03864 1.531 0.128
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.5689 on 121 degrees of freedom
## (231 observations deleted due to missingness)
## Multiple R-squared: 0.01901, Adjusted R-squared: 0.0109
## F-statistic: 2.345 on 1 and 121 DF, p-value: 0.1283
summary(Perseverance_score_change_lm)
##
## Call:
## lm(formula = score_change_across_tests ~ PerseveranceMean, data = squaredDATA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.3492 -0.9489 -0.1934 0.8060 4.5728
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.13810 0.71357 -0.194 0.847
## PerseveranceMean 0.04785 0.24371 0.196 0.845
##
## Residual standard error: 1.338 on 121 degrees of freedom
## (231 observations deleted due to missingness)
## Multiple R-squared: 0.0003185, Adjusted R-squared: -0.007943
## F-statistic: 0.03856 on 1 and 121 DF, p-value: 0.8447
summary(Antisaccade_score_change_lm)
##
## Call:
## lm(formula = AntiMeanRTall ~ score_change_across_tests, data = squaredDATA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -355.14 -135.42 -26.29 95.10 831.12
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 632.66 17.05 37.100 < 2e-16 ***
## score_change_across_tests 42.00 12.87 3.263 0.00144 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 188.3 on 120 degrees of freedom
## (232 observations deleted due to missingness)
## Multiple R-squared: 0.0815, Adjusted R-squared: 0.07385
## F-statistic: 10.65 on 1 and 120 DF, p-value: 0.001436
summary(SwitchCost_score_change_lm)
##
## Call:
## lm(formula = SwitchMean ~ score_change_across_tests, data = squaredDATA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -473.38 -216.65 -12.49 176.86 901.07
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1014.27 24.28 41.782 < 2e-16 ***
## score_change_across_tests 65.86 18.14 3.631 0.000417 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 267 on 119 degrees of freedom
## (233 observations deleted due to missingness)
## Multiple R-squared: 0.09976, Adjusted R-squared: 0.09219
## F-statistic: 13.19 on 1 and 119 DF, p-value: 0.0004172
summary(GPAWeighted_score_change_lm)
##
## Call:
## lm(formula = GPA ~ score_change_across_tests, data = squaredDATA,
## weights = Credits.Earned)
##
## Weighted Residuals:
## Min 1Q Median 3Q Max
## -10.519 -1.986 1.021 2.397 5.150
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.54518 0.03478 101.934 <2e-16 ***
## score_change_across_tests 0.03548 0.02473 1.435 0.154
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.226 on 109 degrees of freedom
## (243 observations deleted due to missingness)
## Multiple R-squared: 0.01854, Adjusted R-squared: 0.009531
## F-statistic: 2.058 on 1 and 109 DF, p-value: 0.1542
summary(Ravens_score_change_lm)
##
## Call:
## lm(formula = score_change_across_tests ~ RavenSum, data = squaredDATA)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.4436 -0.9752 -0.1846 0.7901 4.4880
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.04424 0.52109 2.004 0.0473 *
## RavenSum -0.11387 0.05533 -2.058 0.0417 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.316 on 121 degrees of freedom
## (231 observations deleted due to missingness)
## Multiple R-squared: 0.03382, Adjusted R-squared: 0.02583
## F-statistic: 4.235 on 1 and 121 DF, p-value: 0.04174
# Self-report tests
# Output with Benjamini-Hochberg adjusted p-values
rbind(tidy(GPA_score_change_lm),
tidy(MentalHealth_score_change_lm),
tidy(Happiness_score_change_lm),
tidy(ACS_score_change_lm),
tidy(Satisfaction_score_change_lm),
tidy(BSCmean_score_change_lm)) |>
filter(term != '(Intercept)') |>
rename(predictor = term,
raw.p.value = p.value) |>
mutate(response = c('GPA', 'Mental Health', 'Happiness', 'ACS',
'Satisfaction', 'BSC Mean'), .before=1) |>
select(-std.error, -statistic) |>
mutate(adjusted.p.value = p.adjust(raw.p.value, method='BH'))
## # A tibble: 6 × 5
## response predictor estimate raw.p.value adjusted.p.value
## <chr> <chr> <dbl> <dbl> <dbl>
## 1 GPA GPA 0.236 0.475 0.762
## 2 Mental Health score_change_across_tests 0.0187 0.621 0.762
## 3 Happiness score_change_across_tests -0.0249 0.749 0.762
## 4 ACS score_change_across_tests -0.00745 0.762 0.762
## 5 Satisfaction score_change_across_tests -0.0546 0.554 0.762
## 6 BSC Mean score_change_across_tests 0.0592 0.128 0.762
# Computerized tests
# Output with Benjamini-Hochberg adjusted p-values
rbind(tidy(FlankerSQ_score_change_lm),
tidy(StroopSQ_score_change_lm),
tidy(SimonSQ_score_change_lm)) |>
filter(term != '(Intercept)') |>
rename(predictor = term,
raw.p.value = p.value) |>
mutate(response = c('Flanker Sq', 'Stroop Sq', 'Simon SQ'), .before=1) |>
select(-std.error, -statistic) |>
mutate(adjusted.p.value = p.adjust(raw.p.value, method='BH'))
## # A tibble: 3 × 5
## response predictor estimate raw.p.value adjusted.p.value
## <chr> <chr> <dbl> <dbl> <dbl>
## 1 Flanker Sq Flanker.SQ -0.0508 1.64e-16 4.91e-16
## 2 Stroop Sq score_change_across_tests -4.52 2.34e- 8 3.50e- 8
## 3 Simon SQ score_change_across_tests -3.00 1.31e- 5 1.31e- 5
score_change_by_student <- test_scores_by_student %>%
group_by(ID) %>%
summarize(score_change_across_tests = compute_change_across_tests(test_number, test_score))
# Assuming ID is the linking variable
squaredDATA <- squaredDATA %>%
left_join(score_change_by_student, by = "ID")
# Check if the column now exists
if("score_change_across_tests" %in% names(squaredDATA)) {
print("Column exists, proceed to correlation.")
} else {
print("Column does not exist, check previous steps.")
}
## [1] "Column does not exist, check previous steps."
# # Proceed with these steps only if the column has been confirmed to exist
# data_for_correlation <- squaredDATA %>%
# select(score_change_across_tests, GPA,BSCmean, HappinessMean, Stroop.SQ, AntiMeanRTall, MentalHealthMean)
#
# # Compute the correlation matrix
# correlation_matrix <- cor(data_for_correlation, use = "complete.obs")
#
# # Print the correlation matrix
# print(correlation_matrix)