Tutorial of ARSE Method using Fictitious Data

This document is intended to serve as a step-by-step guide to using the area of resilience to stress event (ARSE) method of quantifying the resilience process using the ‘arse’ R package. This guide is a companion to a paper introducing the ARSE method (Ratcliff, Mahoney-Nair, & Goldstein, 2019). The resilience process is conceptualized as the function of robustness (i.e., the degree of negative departure from the baseline of y) and rapidity (i.e., time to the return to baseline of y) in relation to the incursion of a stress event on an entity. To use this method, three things must be in place: (a) a baseline value (before the stress event) of a variable of interest ‘y’ needs to be known, (b) an incursion of a stress event needs to occur on an entity (e.g., individual, group), and (c) the variable of interest ‘y’ needs to be measured repeatedly after the incursion of a stress event. The combination of robustness and rapidity form a series of points that can be connected into an irregular polygon from which an area can be derived. It is this area, ARSE, that is indicative of how much resilience is demonstrated to a stress event where smaller values of ARSE indicate better resilience and larger values indicate poorer resilience. It should be noted that we refer to decreases as a default way of discussing departures from baseline levels, however, for variables in which higher numbers are characterized as less desirable (e.g., blood pressure), negative departures from the baseline would be increases from the baseline. The ARSE functions discussed below have an option ‘yinvert’ that accommodate cases in which higher values are not desirable. For the purposes of this tutorial, we assume that higher values are more desirable and that decreases from the baseline level are not. In addition to the real data example presented in the main text, the following presents a step-by-step guide to analyzing ARSE using a fictitious data set.

Installation of arse R Package

To install arse, use install.packages("arse") in R or RStudio. Alternatively, the development version of the arse package can be downloaded from github using devtools::install_github("nr3xe/arse"). In addition, for this tutorial you will need to install the following packages: dplyr, pracma, tidyr, ggplot, car, and Rmisc.

Load arse Package, Dependent Packages (dplyr, pracma), and the ‘stress_appraisal’ Data Set

# Required R packages that need to be loaded to use arse
library(arse)
library(dplyr)
library(pracma)
# Required R packages for this tutorial
library(tidyr)
library(ggplot2)
library(car)
library(psych)

Description of stress_appraisal Data Set Embedded in arse Package

A Fictitious data set (embedded in arse package) was used to demonstrate the calculation of ARSE. In this data set, there are 50 fictitious “subjects” split into two groups with 25 members each (i.e., ‘group’ variable). The Control condition represents subjects in which training was not given before a stress event. In the Appraisal_Training condition, subjects were given a training to help cognitively reappraise a stressful situation and think of strategies to adapt to a stressor. Before random assignment to group condition, a baseline ‘tby’ is measured on the subject’s ability to place 100 colored-pegs in a specified patterned grid in one minute. Following baseline measurement, a stress event occurs for all subjects where they are asked to dip their hand in a bath of ice cold water for one minute (or as long as they can stand). Following the stress event, the subjects are asked to perform the peg task four more times with different patterns to match. subjects perform the peg task at three minute intervals. The fourth time the subject performs the task ‘t4y’ represents the subject’s end state at the end of the fictitious experiment. In the data set, ‘t#x’ values represent time on the x-axis using x-coordinates.

# Dataframe of stress_appraisal fictitious data set showing first five rows
head(stress_appraisal, 5) 
##   subj              group tbx t1x t2x t3x t4x tby t1y t2y t3y t4y
## 1    1            Control   0   1   2   3   4  64  40  35  38  47
## 2    2 Appraisal_Training   0   1   2   3   4  59  57  64  60  57
## 3    3            Control   0   1   2   3   4  41  28  20  19  28
## 4    4 Appraisal_Training   0   1   2   3   4  62  70  75  67  61
## 5    5            Control   0   1   2   3   4  43  41  42  43  43

stress_appraisal Layout

Viewed above, the stress_appraisal data set has 12 columns and 50 rows that represent individual subjects. Each of the columns represent the following

  • subj = subject number
  • group = experimental condition
    • Control = Control group receiving no training
    • Appraisal_Training group = Experimental condition receiving training
  • tbx = x-coordinate of baseline measure of peg performance
  • t1x–t4x = x-coordinates of additional measured peg performance measure (t4x = end state x-coordinate)
  • tby = baseline measure of peg performance (0–100 scale)
  • t1y–t4y = y-coordinates of additional measured peg performance measure (t4y = end state y-coordinate)

Data Organization

To organize the data set, the baseline x-coordinate should be the first column of x-coordinates. Accordingly, the baseline y-coordinate value should be the first column of the y-coordinates. The functions within the arse package will default to the first column of y-coordinates as the baseline value.

ARSE Plot of Subject #1

To plot an example case of ARSE, the plot_arse function provides a rough picture of the pattern of resilience. To plot a single case of arse, the plot_arse function requires a vector of x-coordinates and a vector of y-coordinates. The baseline value defaults to the first column of the y-coordinates but can be specified with the ybase = argument. Below, we indicate where in our dataframe the x- and y-coordinates are located and enter them as vectors using the as.integer() prefix. The lower and upper limits of the displayed scale are specified using the ll = and ul =, respectively.

# Plot of ARSE for single subject
plot_arse(xcoord = as.integer(stress_appraisal[1,3:7]), 
          ycoord = as.integer(stress_appraisal[1, 8:12]), 
          ll=0, ul=100, xlab = "Trial Number", ylab = "Number of Pegs")

Figure A1. From the plot above, you can see that the baseline is 64 and that, in this case, resilience was not achieved since the end state is below the baseline at a value of 47.

Calculating ARSE for Subject #1

To calculate ARSE from our example case, the arse function is used. The arse function requires three arguments: data, xcoord, and ycoord. For data, indicate the dataframe that is being used, in our example this would be stress_appraisal. For xcoord, a dataframe of x-coordinates is required with the first column having the x-coordinate of the baseline value of ‘y’. For ycoord, a dataframe of y-coordinates is required with the first column having the baseline value of ‘y’. The baseline value defaults to the first column of the y-coordinates but can be specified with the ybase = argument (we strongly suggest that users rely on the default using the first column of x- and y-coordinates). The arse function only calculates the area below the baseline; any points above the baseline (i.e., growth) are set to the baseline level to only calculate the area beneath the baseline. The arse function, as well as the related ARSE functions, will provide interpolation points for x-coordinates where the line between two points crosses the baseline at a point not measured in the data (using a function analogous to the getintersectx function in the arse package (see help for more details). In the example below, the first row of the dataframe is selected with the corresponding columns for the x- and y-coordinates. To calculate ARSE, an implementation of the shoelace formula (Gauss’s area formula) for the area of irregular polygons is used with the (polyarea()) function from the pracma package.

The arse function also has two additional arguments that can be specified: yinvert and saveout. The yinvert argument can be used to calculate ARSE depending on how the range of values of ‘y’ are to be interpreted. By default, yinvert = FALSE and assumes that higher values of ‘y’ are more desirable or positive. However, if higher values of ‘y’ are not desirable and lower values are, then yinvert = TRUE will calculate ARSE assuming that values above the baseline represent resilience and values below the baseline represent growth. Lastly, the saveout argument is set to FALSE by default and will just return a vector of values for the ARSE calculation. When set to TRUE, saveout will return the original dataframe and add a column of the calculated ARSE values.

# Returns area of resilience to stress event (ARSE) for single subject
arse(data = stress_appraisal, xcoord = stress_appraisal[1, 3:7], 
     ycoord = stress_appraisal[1, 8:12])
## [1] 87.5

The Result of ARSE for Subject #1

The function returns an ARSE value of 87.5. This area was calculated by using the x- and y-coordinates that form an irregular polygon. Since resilience was not achieved in this example (i.e., the end state value did not return or exceed the baseline), an additional point is interpolated at the same x-coordinate as the end state value with a y-coordinate value at the baseline (i.e., x = 4, y = 64). Doing so completes the appropriate shape to calculate ARSE.

Calculating AoG for Subject #4

In some cases, users may want to know how much growth a subject might have experienced (see plot below).

# Plot of area of growth (AoG) for single subject
plot_arse(xcoord = as.integer(stress_appraisal[4,3:7]), 
          ycoord = as.integer(stress_appraisal[4, 8:12]), 
          ll=0, ul=100, xlab = "Trial Number", ylab = "Number of Pegs")

Figure A2. The plot shows that Subject #4 experienced growth (i.e., ‘y’ values above the baseline) after the incursion of a stress event.

To calculate areas of growth, the aog function is used. This function is exactly the same as the arse function above except that instead of setting values above the baseline to the baseline, aog sets values below the baseline to the baseline to only look at the area above the baseline.

# Returns area of growth (AoG) value for single subject
aog(data = stress_appraisal, xcoord = stress_appraisal[4, 3:7], 
    ycoord = stress_appraisal[4, 8:12])
## [1] 25.58333
# Returns area of resilience to stress event (ARSE) value for single subject
arse(data = stress_appraisal, xcoord = stress_appraisal[4, 3:7], 
     ycoord = stress_appraisal[4, 8:12])
## [1] 0.08333333

The Result of AoG and ARSE for Subject #4

The result of aog returns a value of 25.58 indicating the area of growth for Subject #4. However, since the subject had an end state value below the baseline (t4y = 61), arse can also be calculated and return a value of 0.08. In this case, more growth was achieved for the subject with a small area of resilience, indicating a good response to the stress event.

Calculating ARSET for Subject #4

In some cases, users may want to take into account both resilience and growth. There is also a function, arse_t, that calculates the area of resilience (arse) and area of growth (aog) and takes their difference (i.e., \(ARSE_T = ARSE - AoG\)) to get a total area value for resilience. In these cases, ARSE can be positive and negative depending on whether the area of resilience or area of growth is larger.

# Returns area of resilience to stress event total (ARSE_T) value for single subject
arse_t(data = stress_appraisal, xcoord = stress_appraisal[4, 3:7], 
       ycoord = stress_appraisal[4, 8:12])
## [1] -25.5

The result of ARSET for Subject #4

The result of arse_t returns a value of -25.5 which reflects the subtraction of ARSE (0.08) from AoG (25.58). A negative returned value indicates that the area of growth was larger than the area of resilience.

Calculating ARSES for Subject #1

In some cases, users may want to account for the end state being above the baseline (growth) or below the baseline (non-resilience). The arse_s function provides a scaling factor that accounts for the end state where \(ARSE_S = ARSE * (Baseline/End State)\). When the end state is below the baseline, the scaling factor will make ARSE larger and when the end state is above the baseline, the scaling factor will make ARSE smaller.

# Returns area of resilience to stress event scaled (ARSE_S) value for single subject
arse_s(data = stress_appraisal, xcoord = stress_appraisal[1, 3:7], 
       ycoord = stress_appraisal[1, 8:12])
## [1] 119.1489

The Result of ARSES for Subject #1

The result of arse_s returns a value of 119.15. Recall that the arse value for this subject was 87.5 with a baseline value of 64 and an end state value of 47. Thus, \(ARSE_S = 87.5 * (64/47)\) or \(ARSE_S = 87.5 * 1.36\) which returns a larger area (vs. the un-scaled ARSE) of 119.15.

Calculating ARSETS for Subject #4

In some cases, users may want to account for both growth and the end state value; the arse_ts function combines aspects of both arse_t and arse_s. Specifically, arse_ts is calculated as follows: for arse_t values that are >= 0, \(ARSE_T._S = ARSE_T * (Baseline/End State)\) while for arse_t values that are < 0, \(ARSE_T._S = ARSE_T * (End State/Baseline)\). The two different calculations are needed to account for scaling positive and negative values of arse_t. For instance, if arse_t is negative and the end state is above the baseline, then the end state value needs to be in the numerator so that the scaling factor can make a negative value larger (versus smaller when arse_t is zero or positive).

# Returns area of resilience to stress event total scaled (ARSE_TS) for single subject
arse_ts(data = stress_appraisal, xcoord = stress_appraisal[4, 3:7], 
        ycoord = stress_appraisal[4, 8:12])
## [1] -25.08871

The Result of ARSETS for Subject #4

The result of arse_ts returns a value of -25.09. Recall that arse_t for this subject was -25.5 with a baseline of 62 and an end state of 61. Thus, \(ARSE_T._S = -25.5 * (61/62)\) or \(ARSE_TS = -25.5 * (0.98)\) which returns a smaller negative value (vs. un-scaled ARSET) of -25.09.

Calculating ARSE for Entire Sample

Calculation of ARSE and the ARSE family of functions for the entire sample is the same as for individual cases.

# Returns area of resilience to stress event (ARSE) for entire sample with 
# modified data set including calculated ARSE values
# The head function is set to '5' to limit to the first five subjects for display purposes
# The mutate_if function from the dplyr package is used to limit decimals of ARSE output
head(
  mutate_if(
    arse(data = stress_appraisal, xcoord = stress_appraisal[,3:7], 
           ycoord = stress_appraisal[,8:12], saveout = TRUE),
    is.numeric, round, digits = 4), 5) 
##   subj              group tbx t1x t2x t3x t4x tby t1y t2y t3y t4y    arse
## 1    1            Control   0   1   2   3   4  64  40  35  38  47 87.5000
## 2    2 Appraisal_Training   0   1   2   3   4  59  57  64  60  57  1.9524
## 3    3            Control   0   1   2   3   4  41  28  20  19  28 62.5000
## 4    4 Appraisal_Training   0   1   2   3   4  62  70  75  67  61  0.0833
## 5    5            Control   0   1   2   3   4  43  41  42  43  43  3.0000

Calculating ARSET for Entire Sample

# Returns area of resilience to stress event total (ARSE_T) for entire sample 
# with modified data set including calculated ARSE_T values (first five subjects shown)
head(
  mutate_if(
    arse_t(data = stress_appraisal, xcoord = stress_appraisal[,3:7], 
       ycoord = stress_appraisal[,8:12], saveout = TRUE),
    is.numeric, round, digits = 4), 5)
##   subj              group tbx t1x t2x t3x t4x tby t1y t2y t3y t4y arse_t
## 1    1            Control   0   1   2   3   4  64  40  35  38  47   87.5
## 2    2 Appraisal_Training   0   1   2   3   4  59  57  64  60  57   -3.0
## 3    3            Control   0   1   2   3   4  41  28  20  19  28   62.5
## 4    4 Appraisal_Training   0   1   2   3   4  62  70  75  67  61  -25.5
## 5    5            Control   0   1   2   3   4  43  41  42  43  43    3.0

Calculating ARSES for Entire Sample

# Returns area of resilience to stress event scaled (ARSE_S) for entire sample 
# with modified data set including calculated ARSE_S values (first five subjects shown)
head(
  mutate_if(
    arse_s(data = stress_appraisal, xcoord = stress_appraisal[,3:7], 
             ycoord = stress_appraisal[,8:12], saveout = TRUE),
    is.numeric, round, digits = 4), 5)
##   subj              group tbx t1x t2x t3x t4x tby t1y t2y t3y t4y   arse_s
## 1    1            Control   0   1   2   3   4  64  40  35  38  47 119.1489
## 2    2 Appraisal_Training   0   1   2   3   4  59  57  64  60  57   2.0209
## 3    3            Control   0   1   2   3   4  41  28  20  19  28  91.5179
## 4    4 Appraisal_Training   0   1   2   3   4  62  70  75  67  61   0.0847
## 5    5            Control   0   1   2   3   4  43  41  42  43  43   3.0000

Calculating ARSETS for Entire Sample

# Returns area of resilience to stress event total scaled (ARSE_TS) for entire sample with 
# modified data set including calculated ARSE_TS values (first five subjects shown)
head(
  mutate_if(
    arse_ts(data = stress_appraisal, xcoord = stress_appraisal[,3:7], 
              ycoord = stress_appraisal[,8:12], saveout = TRUE),
    is.numeric, round, digits = 4), 5)
##   subj              group tbx t1x t2x t3x t4x tby t1y t2y t3y t4y  arse_ts
## 1    1            Control   0   1   2   3   4  64  40  35  38  47 119.1489
## 2    2 Appraisal_Training   0   1   2   3   4  59  57  64  60  57  -3.1053
## 3    3            Control   0   1   2   3   4  41  28  20  19  28  91.5179
## 4    4 Appraisal_Training   0   1   2   3   4  62  70  75  67  61 -25.9180
## 5    5            Control   0   1   2   3   4  43  41  42  43  43   3.0000

Calculating ARSETS for Entire Sample and Comparing Mean Group Differences with a t-test

In this example, we first calculate values of arse_ts for the entire sample and create a new column ‘arse_ts’ by saving the new dataframe as a new object ‘data1’. Second, we perform a t-test by comparing the control and appraisal_training groups under the ‘group’ factor.

# Returns area of resilience to stress event total scaled (ARSE_TS) for entire sample with 
# modified data set including calculated ARSE_TS values 
data1 <- arse_ts(data = stress_appraisal, xcoord = stress_appraisal[,3:7], 
                 ycoord = stress_appraisal[,8:12], saveout = TRUE)
# Levene's Test for equal variances
leveneTest(arse_ts ~ group, data = data1)
## Levene's Test for Homogeneity of Variance (center = median)
##       Df F value  Pr(>F)  
## group  1  5.8471 0.01945 *
##       48                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
detach("package:car", unload=TRUE)
# Independent Samples t-test
t.test(data1$arse_ts ~ data1$group, var.equal = FALSE)
## 
##  Welch Two Sample t-test
## 
## data:  data1$arse_ts by data1$group
## t = -2.5177, df = 26.175, p-value = 0.01826
## alternative hypothesis: true difference in means between group Appraisal_Training and group Control is not equal to 0
## 95 percent confidence interval:
##  -160.99391  -16.29634
## sample estimates:
## mean in group Appraisal_Training            mean in group Control 
##                         21.27067                        109.91580
# Indicator of effect size magnitude using Cohen's d
psych::cohen.d(data1$arse_ts, group = data1$group, alpha = 0.05)
## Call: psych::cohen.d(x = data1$arse_ts, group = data1$group, alpha = 0.05)
## Cohen d statistic of difference between two means
##      lower effect upper
## [1,]  0.15   0.73   1.3
## 
## Multivariate (Mahalanobis) distance between groups
## [1] 0.73
## r equivalent of difference between two means
## data 
## 0.34
# Summary table of means and MoE for control and appraisal training groups
ggplot_bsci <- Rmisc::summarySE(data1, measurevar = "arse_ts", groupvars = "group")
# Bar plot of mean ARSE_TS for control and appraisal training groups
ggplot(ggplot_bsci, aes(x = group, y = arse_ts, fill = group)) +
  geom_bar(stat = "identity", width = .65, color = "black") +
  geom_errorbar(aes(ymin = arse_ts - ci, ymax = arse_ts + ci), width = .15, size = 0.85) +
  labs(x = "Experimental Condition", y = "Mean ARSE_TS") +
  coord_cartesian(ylim = c(-50, 190)) +
  theme_classic() +
  scale_fill_manual(values = c("#0072B2","#D55E00")) +
  scale_y_continuous(breaks = c(-50, -25, 0, 25, 50, 75, 100, 125, 150, 175)) +
  geom_hline(yintercept = 0, linetype = "solid", color = "black") +
  theme(legend.position = "top")
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

Figure A3. Mean ARSETS grouped by experimental condition. Error bars represent 95% confidence intervals.

The Result of t-test comparing the Control Group to Appraisal Training Group

The result of the t-test reveals a significant difference between the two groups at an alpha level of 0.05. Specifically, subjects in the appraisal training condition had smaller ARSETS values (M = 21.27) compared to the control condition (M = 109.92).

Plotting Mean ARSE of Control and Appraisal Training Groups

Plotting ARSE of Control Group Using Mean Values of Y-Coordinates

# Plots the mean values of 'y' across x-coordinates for the control group
stress_appraisal_group1 <- subset(stress_appraisal, group == "Control", 
                                 select = c("subj", "group", 
                                            "tbx", "t1x", "t2x", "t3x", "t4x", 
                                            "tby", "t1y", "t2y", "t3y", "t4y"))
# Transform dataframe to be in long form  
stress_appraisal_group_long1 <- stress_appraisal_group1 %>% 
  gather(trial, pegs, tby:t4y)
# Recode trial labels to be numbers: 0-4
stress_appraisal_group_long1$trial <- as.factor(recode(stress_appraisal_group_long1$trial, 
                                            tby = "0", t1y = "1", 
                                            t2y = "2", t3y = "3", t4y = "4"))
stress_appraisal_group_long1$subj <- as.factor(stress_appraisal_group_long1$subj)
# Cousineau-Morey within-subject confidence interval correction 
gplot_wsci1 <- Rmisc::summarySEwithin(stress_appraisal_group_long1, measurevar = "pegs", 
                                     withinvars = "trial", idvar = "subj")
# See print out of means to identify baseline peg value for trial '0'
head(gplot_wsci1, 5)
##   trial  N  pegs        sd       se       ci
## 1     0 25 58.04 12.914946 2.582989 5.331028
## 2     1 25 45.44  7.829166 1.565833 3.231721
## 3     2 25 43.08  6.899275 1.379855 2.847881
## 4     3 25 43.04  7.464081 1.492816 3.081021
## 5     4 25 45.80  8.082130 1.616426 3.336140

From the output table you will be able to extract the mean baseline value to input in the ggplot code below to create a baseline graphic using geom_hline (i.e., 58.04) in ggplot. The means at each trial time point are displayed here to be used as inputs for shading the area of resilience using geom_ribbon (i.e., min: 58.04, 45.44, 43.08, 43.04, 45.80; max: 58.04) in ggplot. Although not apparent in this example, if a point would have been observed above the baseline (e.g., 65.01), the geom_ribbon function should be coded so that any points above the baseline do not create a shaded area so that readers can see the shaded area as ARSE and non-shaded areas as AoG.

# Minimum and Max values
gplot_wsci1$ymin <- c(58.04, 45.44, 43.08, 43.04, 45.80)
gplot_wsci1$ymax <- 58.04

# Plot of ARSE using ggplot for control group
ggplot(gplot_wsci1, aes(x = trial, y = pegs, group = 1)) +
  geom_ribbon(aes(ymin = ymin, 
              ymax = ymax), color = NA, fill = "grey", 
              alpha = .3) +
  geom_point() +
  geom_line() +
  geom_errorbar(width = .1, aes(ymin = pegs - ci, ymax = pegs + ci)) +
  labs(x = "Trial Number", y = "Number of Pegs") +
  coord_cartesian(ylim = c(30, 70)) +
  geom_hline(yintercept = 58.04, linetype="dashed", color = "grey") +
  scale_y_continuous(breaks = c(30, 35, 40, 45, 50, 55, 60, 65, 70)) +
  theme_classic()

Figure A4. The plot above reflects the mean values of the ‘y’ variable at each time interval to show the average shape of the ARSE for subjects in the control group. The shaded area represents the average ARSE of the control condition. Error bars represent 95% correlation-adjusted confidence intervals for repeated measures data (see Cousineau, 2017; Morey, 2008).

Plotting ARSE of Appraisal Training Group Using Mean Values of Y-Coordinates

# Plots the mean values of 'y' across x-coordinates for the appraisal training group
stress_appraisal_group2 <- subset(stress_appraisal, group == "Appraisal_Training", 
                                 select = c("subj", "group", 
                                            "tbx", "t1x", "t2x", "t3x", "t4x", 
                                            "tby", "t1y", "t2y", "t3y", "t4y"))
# Transform dataframe to be in long form  
stress_appraisal_group_long2 <- stress_appraisal_group2 %>% 
  gather(trial, pegs, tby:t4y)
# Recode trial labels to be numbers: 0-4
stress_appraisal_group_long2$trial <- as.factor(recode(stress_appraisal_group_long2$trial, 
                                            tby = "0", t1y = "1", 
                                            t2y = "2", t3y = "3", t4y = "4"))
stress_appraisal_group_long2$subj <- as.factor(stress_appraisal_group_long2$subj)
# Cousineau-Morey within-subject confidence interval correction 
gplot_wsci2 <- Rmisc::summarySEwithin(stress_appraisal_group_long2, measurevar = "pegs", 
                                      withinvars = "trial", idvar = "subj")
# See print out of means to identify baseline peg value for trial '0'
head(gplot_wsci2, 5)
##   trial  N  pegs       sd        se       ci
## 1     0 25 59.32 7.258937 1.4517874 2.996342
## 2     1 25 52.80 5.246157 1.0492315 2.165507
## 3     2 25 53.60 4.740042 0.9480084 1.956593
## 4     3 25 54.32 5.066689 1.0133377 2.091426
## 5     4 25 58.08 4.101585 0.8203170 1.693051
# Minimum and Max values
gplot_wsci2$ymin <- c(59.32, 52.80, 53.60, 54.32, 58.08)
gplot_wsci2$ymax <- 59.32

# Plot of ARSE using ggplot for appraisal training group
ggplot(gplot_wsci2, aes(x = trial, y = pegs, group = 1)) +
  geom_ribbon(aes(ymin = ymin, 
              ymax = ymax), color = NA, fill = "grey", 
              alpha = .3) +
  geom_point() +
  geom_line() +
  geom_errorbar(width = .1, aes(ymin = pegs - ci, ymax = pegs + ci)) +
  labs(x = "Trial Number", y = "Number of Pegs") +
  coord_cartesian(ylim = c(30, 70)) +
  geom_hline(yintercept = 59.32, linetype="dashed", color = "grey") +
  scale_y_continuous(breaks = c(30, 35, 40, 45, 50, 55, 60, 65, 70)) +
  theme_classic()

Figure A5. The plot above reflects the mean values of the ‘y’ variable at each time interval to show the average shape of the ARSE for subjects in the appraisal training condition. The shaded area represents the average ARSE of the appraisal training group. Error bars represent 95% correlation-adjusted confidence intervals for repeated measures data (see Cousineau, 2017; Morey, 2008).

Ploting ARSE of Control and Appraisal Group in Combined Graph

# Combine the aggregated summaries of the control and appraisal training group
gplot_wsci_combine <- bind_rows(gplot_wsci1, gplot_wsci2)
# Add back in factor names to output
gplot_wsci_combine <- mutate(gplot_wsci_combine, group = 
                             as.factor(c("Control", "Control", "Control", 
                                         "Control", "Control", "Appraisal_Training", 
                                         "Appraisal_Training", "Appraisal_Training",
                                         "Appraisal_Training", "Appraisal_Training")))
# Plot combined output with shaded regions
# For shaded areas (geom_ribbon), input the means across time points and place NaN to
# fill out the vector expecting inputs the length of the combined dataframe (e.g., 10)

# Minimum and Max values
gplot_wsci_combine$ymin1 <- c(58.04, 45.44, 43.08, 43.04, 45.80, NaN, NaN, NaN, NaN, NaN)
gplot_wsci_combine$ymin2 <- c(NaN, NaN, NaN, NaN, NaN, 59.32, 52.80, 53.60, 54.32, 58.08)
gplot_wsci_combine$ymax1 <- c(58.04, 58.04, 58.04, 58.04, 58.04, NaN, NaN, NaN, NaN, NaN)
gplot_wsci_combine$ymax2 <- c(NaN, NaN, NaN, NaN, NaN, 59.32, 59.32, 59.32, 59.32, 59.32)

ggplot(gplot_wsci_combine, aes(x = trial, y = pegs, group = group, 
                               colour = group, shape = group)) + 
  geom_ribbon(aes(ymin = ymin1, ymax = ymax1), color = NA, fill = "#D55E00", 
              alpha = .25, position = position_dodge(width = .3)) +
  geom_ribbon(aes(ymin = ymin2, ymax = ymax2), color = NA, fill = "#0072B2", 
              alpha = .3, position = position_dodge2(width = .3)) +
  geom_point(size = 2.5, position = position_dodge(width = .3)) +
  geom_line(size = .75, position = position_dodge(width = .3)) +
  geom_errorbar(width = .4, position = position_dodge(width = .3), 
                aes(ymin = pegs - ci, ymax = pegs + ci)) +
  labs(x = "Trial Number", y = "Number of Pegs") +
  coord_cartesian(ylim = c(30, 70)) +
  geom_hline(yintercept = 58.04, linetype = "dotted", color = "#D55E00") +
  geom_hline(yintercept = 59.32, linetype = "dashed", color = "#0072B2") +
  theme_classic() +
  scale_color_manual(values = c('#0072B2','#D55E00')) +
  scale_y_continuous(breaks = c(30, 35, 40, 45, 50, 55, 60, 65, 70)) +
  theme(legend.position = "top")
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf
## Warning in max(ids, na.rm = TRUE): no non-missing arguments to max; returning
## -Inf

Figure A6. The plot above reflects the mean values of the ‘y’ variable at each time interval to show the average shape of the ARSE for subjects in both the control and appraisal training group. The two Shaded areas reflect the average ARSE for each group. Error bars represent 95% correlation-adjusted confidence intervals for repeated measures data (see Cousineau, 2017; Morey, 2008).

References

Cousineau, D. (2017). Varieties of confidence intervals. Advances in Cognitive Psychology, 13, 140–155. https://doi.org/10.5709/acp-0214-z

Morey, R. D. (2008). Confidence intervals from normalized data: A correction to cousineau (2005). Tutorial in Quantitative Methods for Psychology, 4, 61–64. https://doi.org/10.20982/tqmp.04.2.p061

Ratcliff, N. J., Mahoney-Nair, D. T., & Goldstein, J. R. (2019). The Area of resilience to stress event (ARSE): A new method for quantifying the process of resilience. The Quantitative Methods for Psychology, 15, 148–173. https://doi.org/10.20982/tqmp.15.2.p148