The Cortisol Data
Loading and Describing the Data
Overview
This script shares The Cortisol Data, an N = 34, T = 9 time points data set we have used to illustrate a variety of growth modeling and mixture modeling methods.
The data are shared with intent that others may find them useful for learning about growth modeling or developing new methods for analysis of change.
New publications based on these data require citation and acknowledgement of the full set of papers that have used the data, and …
articulate developmental change: Matching theory to method.
International Journal of Behavioral Development, 31(4), 303-316.
https://doi.org/10.1177/0165025407077751
Ram, N., & Grimm, K. (2009). Growth mixture modeling: A method for
identifying differences in longitudinal change among unobserved groups.
International Journal of Behavioral Development, 33(6), 565-576.
https://doi.org/10.1177/0165025409343765
Ram, N., Grimm, K., Gatzke-Kopp, L. & Molenaar, P.C.M. (2011).
Longitudinal mixture models and the identification of archetypes:
Action-adventure, mystery, science fiction, fantasy, or romance? In B.
Laursen, T. Little, & N. Card (Eds.) Handbook of Developmental Research
Methods (pp. 481-500). New York: Guilford.
Grimm, K.J., Steele, J.S., Ram, N., & Nesselroade, J.R. (2013).
Exploratory latent growth models in the structural equation modeling
framework. Structural Equation Modeling, 20(4), 568-591.
https://doi.org/10.1080/10705511.2013.824775
Outline
This script covers …
Loading the Cortisol Data
Reshaping the Cortisol Data
Describing The Cortisol Data
Packages
Loading libraries used in this script.
Reading in the data
Loading the public data
#set filepath for data file
filepath <- "https://raw.githubusercontent.com/The-Change-Lab/collaborations/main/TheCortisolData/TheCortisolData.csv"
#read in the .csv file using the url() function
cortisol_wide <- read.csv(file=url(filepath), header=TRUE)Looking at the top few rows of the wide data.
## id cort_0 cort_1 cort_2 cort_3 cort_4 cort_5 cort_6 cort_7 cort_8
## 1 1 4.2 4.1 9.7 14.0 19.0 18.0 20.0 23.0 24.0
## 2 2 5.5 5.6 14.0 16.0 19.0 17.0 18.0 20.0 19.0
## 3 3 4.0 3.8 7.5 12.0 14.0 13.0 9.1 8.2 7.9
## 4 4 6.1 5.6 14.0 20.0 26.0 23.0 26.0 25.0 26.0
## 5 5 4.6 4.4 7.2 12.3 15.8 16.1 17.0 17.8 19.1
## 6 6 6.8 9.5 14.2 19.6 19.0 13.9 13.4 12.5 11.7
Reshaping the data
Two main data schema are used to accommodate repeated measures data - “Wide Format” and “Long Format”. Different functions work with different kinds of data input. We already have the wide format data. We make a set of long format data.
Reshape from wide to long
#reshaping wide to long
cortisol_long <- reshape(data=cortisol_wide,
timevar=c("time"),
idvar="id",
varying=c("cort_0","cort_1","cort_2","cort_3",
"cort_4","cort_5","cort_6","cort_7","cort_8"),
direction="long", sep="_")
#sorting for easy viewing
#order by id and time
cortisol_long <- cortisol_long[order(cortisol_long$id,cortisol_long$time), ]To match the scaling of time used in some of the papers we add an additional time variable that runs from 0 to 1.
Looking at the top few rows of the long data.
## id time cort timescaled
## 1.0 1 0 4.2 0.000
## 1.1 1 1 4.1 0.125
## 1.2 1 2 9.7 0.250
## 1.3 1 3 14.0 0.375
## 1.4 1 4 19.0 0.500
## 1.5 1 5 18.0 0.625
## 1.6 1 6 20.0 0.750
## 1.7 1 7 23.0 0.875
## 1.8 1 8 24.0 1.000
## 2.0 2 0 5.5 0.000
## 2.1 2 1 5.6 0.125
## 2.2 2 2 14.0 0.250
## 2.3 2 3 16.0 0.375
## 2.4 2 4 19.0 0.500
## 2.5 2 5 17.0 0.625
## 2.6 2 6 18.0 0.750
## 2.7 2 7 20.0 0.875
## 2.8 2 8 19.0 1.000
Describing The Cortisol Data
Basic descriptives of the 9-occasion data.
## vars n mean sd median trimmed mad min max range skew kurtosis
## id 1 34 17.50 9.96 17.50 17.50 12.60 1 34.0 33.0 0.00 -1.31
## cort_0 2 34 5.25 2.45 5.00 4.90 2.30 2 12.0 10.0 1.18 0.92
## cort_1 3 34 5.06 2.59 4.50 4.78 2.22 2 11.3 9.3 1.02 -0.01
## cort_2 4 34 10.85 3.11 10.05 10.79 3.85 6 16.7 10.7 0.09 -1.17
## cort_3 5 34 17.36 3.69 17.35 17.39 3.48 7 24.9 17.9 -0.29 0.39
## cort_4 6 34 19.48 3.72 19.10 19.49 2.82 12 27.1 15.1 -0.04 -0.56
## cort_5 7 34 16.46 4.18 16.95 16.41 4.52 8 26.0 18.0 0.08 -0.58
## cort_6 8 34 15.03 4.57 14.65 14.90 4.15 6 26.0 20.0 0.26 -0.31
## cort_7 9 34 15.62 4.81 16.15 15.60 5.56 7 25.0 18.0 -0.02 -0.99
## cort_8 10 34 15.86 5.61 16.00 15.81 6.08 6 26.0 20.0 0.14 -1.08
## se
## id 1.71
## cort_0 0.42
## cort_1 0.44
## cort_2 0.53
## cort_3 0.63
## cort_4 0.64
## cort_5 0.72
## cort_6 0.78
## cort_7 0.82
## cort_8 0.96
#boxplot by day
cortisol_long %>%
ggplot(aes(x=factor(time), y=cort)) +
geom_boxplot(notch = TRUE) +
stat_summary(fun.y="mean", geom="point", shape=23, size=3, fill="white") +
labs(x = "Time", y = "Cortisol") +
theme_minimal()#correlations
round(cor(cortisol_wide[,c("cort_0","cort_1","cort_2","cort_3",
"cort_4","cort_5","cort_6","cort_7","cort_8")],
use="complete.obs",method="spearman"),2)## cort_0 cort_1 cort_2 cort_3 cort_4 cort_5 cort_6 cort_7 cort_8
## cort_0 1.00 0.97 0.45 0.27 0.23 0.17 0.28 0.22 0.20
## cort_1 0.97 1.00 0.48 0.27 0.18 0.14 0.23 0.19 0.16
## cort_2 0.45 0.48 1.00 0.71 0.66 0.47 0.42 0.39 0.34
## cort_3 0.27 0.27 0.71 1.00 0.71 0.37 0.16 0.10 0.14
## cort_4 0.23 0.18 0.66 0.71 1.00 0.81 0.58 0.50 0.52
## cort_5 0.17 0.14 0.47 0.37 0.81 1.00 0.88 0.84 0.82
## cort_6 0.28 0.23 0.42 0.16 0.58 0.88 1.00 0.97 0.93
## cort_7 0.22 0.19 0.39 0.10 0.50 0.84 0.97 1.00 0.94
## cort_8 0.20 0.16 0.34 0.14 0.52 0.82 0.93 0.94 1.00
#pairs plot from the psych library
pairs.panels(cortisol_wide[,c("cort_0","cort_1","cort_2","cort_3",
"cort_4","cort_5","cort_6","cort_7","cort_8"),],
cex.labels=1)Plot of sample-level change in distribution across time
#density distribution by day
cortisol_long %>%
ggplot(aes(x=cort)) +
geom_density(aes(group=factor(time), colour=factor(time),
fill=factor(time)), alpha=0.3) +
labs(x = "Cortisol", y = "Density", fill = "Time", colour="Time") +
theme_minimal()Plot of individual-level trajectories
#intraindividual change trajetories
cortisol_long %>%
ggplot(aes(x = time, y = cort, group = id)) +
geom_point(color = "black") +
geom_line(color = "black") +
labs(x = "Time", y = "Cortisol") +
ylim(0,30) +
scale_x_continuous(breaks = seq(0,8,by=1)) +
theme_minimal()Yay!