Title: | Identify Sudden Gains in Longitudinal Data |
---|---|
Description: | Identify sudden gains based on the three criteria outlined by Tang and DeRubeis (1999) <doi:10.1037/0022-006X.67.6.894> to a selection of repeated measures. Sudden losses, defined as the opposite of sudden gains can also be identified. Two different datasets can be created, one including all sudden gains/losses and one including one selected sudden gain/loss for each case. It can extract scores around sudden gains/losses. It can plot the average change around sudden gains/losses and trajectories of individual cases. |
Authors: | Milan Wiedemann [aut, cre] , Graham M Thew [aut] , Richard Stott [ctb] , Anke Ehlers [ctb, ths] , Mental Health Research UK [fnd], Wellcome Trust [fnd] |
Maintainer: | Milan Wiedemann <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.7.2 |
Built: | 2024-11-20 03:20:18 UTC |
Source: | https://github.com/milanwiedemann/suddengains |
Checks if a specific session to session interval is a sudden gain/loss.
check_interval( pre_values, post_values, sg_crit1_cutoff, sg_crit2_pct = 0.25, sg_crit3 = TRUE, sg_crit3_alpha = 0.05, sg_crit3_adjust = TRUE, sg_crit3_critical_value = 2.776, identify = c("sg", "sl"), details = TRUE )
check_interval( pre_values, post_values, sg_crit1_cutoff, sg_crit2_pct = 0.25, sg_crit3 = TRUE, sg_crit3_alpha = 0.05, sg_crit3_adjust = TRUE, sg_crit3_critical_value = 2.776, identify = c("sg", "sl"), details = TRUE )
pre_values |
Vector, three pre gain/loss values to be checked for a sudden gain/loss (n-2, n-1, n) |
post_values |
Vector, three post gain/loss values to be checked for a sudden gain/loss (n+1, n+2, n+3) |
sg_crit1_cutoff |
Numeric, specifying the cut-off value to be used for the first sudden gains criterion.
The function |
sg_crit2_pct |
Numeric, specifying the percentage change to be used for the second sudden gains/losses criterion.
If set to |
sg_crit3 |
If set to |
sg_crit3_alpha |
Numeric, alpha for the student t-test (two-tailed) to determine the critical value to be used for the third criterion. Degrees of freedom are based on the number of available data in the three sessions preceding the gain and the three sessions following the gain. |
sg_crit3_adjust |
Logical, specify whether critical value gets adjusted for missingness, see Lutz et al. (2013) and the documentation of this R package for further details.
This argument is set to |
sg_crit3_critical_value |
Numeric, specifying the critical value to instead be used for all comparisons, regardless of missingnes in the sequence of data points that are investigated for potential sudden gains. |
identify |
String, specifying whether to identify sudden gains ( |
details |
Logical, details yes no? |
Information on whether a given interval is a sudden gain/loss
# Check interval for sudden gain using all 3 criteria # No missing data, alpha = 0.05 check_interval(pre_values = c(32, 31, 33), post_values = c(5, 6, 7), sg_crit1_cutoff = 7, sg_crit2_pct = .25, sg_crit3 = TRUE, sg_crit3_alpha = .05, identify = "sg") # No missing data, alpha = 0.01 check_interval(pre_values = c(32, 31, 33), post_values = c(5, 6, 7), sg_crit1_cutoff = 7, sg_crit2_pct = .25, sg_crit3 = TRUE, sg_crit3_alpha = .01, identify = "sg") # Check interval for sudden gain using only third criterion # Some missing data, alpha = 0.01 check_interval(pre_values = c(NA,31,33), post_values = c(5, NA, 7), sg_crit1_cutoff = NULL, sg_crit2_pct = NULL, sg_crit3 = TRUE, sg_crit3_alpha = .01, identify = "sg") # Check interval for sudden loss using all three criteria # Some missing data, alpha = 0.05 check_interval(pre_values = c(5, NA, 7), post_values = c(16, 12, 14), sg_crit1_cutoff = -7, sg_crit2_pct = .25, sg_crit3 = TRUE, sg_crit3_alpha = .05, identify = "sl")
# Check interval for sudden gain using all 3 criteria # No missing data, alpha = 0.05 check_interval(pre_values = c(32, 31, 33), post_values = c(5, 6, 7), sg_crit1_cutoff = 7, sg_crit2_pct = .25, sg_crit3 = TRUE, sg_crit3_alpha = .05, identify = "sg") # No missing data, alpha = 0.01 check_interval(pre_values = c(32, 31, 33), post_values = c(5, 6, 7), sg_crit1_cutoff = 7, sg_crit2_pct = .25, sg_crit3 = TRUE, sg_crit3_alpha = .01, identify = "sg") # Check interval for sudden gain using only third criterion # Some missing data, alpha = 0.01 check_interval(pre_values = c(NA,31,33), post_values = c(5, NA, 7), sg_crit1_cutoff = NULL, sg_crit2_pct = NULL, sg_crit3 = TRUE, sg_crit3_alpha = .01, identify = "sg") # Check interval for sudden loss using all three criteria # Some missing data, alpha = 0.05 check_interval(pre_values = c(5, NA, 7), post_values = c(16, 12, 14), sg_crit1_cutoff = -7, sg_crit2_pct = .25, sg_crit3 = TRUE, sg_crit3_alpha = .05, identify = "sl")
Calculates the number of total between-session intervals present in the data set and the number of between-session intervals that are available to identify sudden gains talking into account the pattern of missing data.
count_intervals(data, id_var_name, sg_var_list, identify_sg_1to2 = FALSE)
count_intervals(data, id_var_name, sg_var_list, identify_sg_1to2 = FALSE)
data |
A data set in wide format including an ID variable and variables for each measurement point. |
id_var_name |
String, specifying the name of the ID variable. Each row should have a unique value. |
sg_var_list |
Vector, specifying the variable names of each measurement point sequentially. |
identify_sg_1to2 |
Logical, indicating whether to identify sudden losses from measurement point 1 to 2.
If set to TRUE, this implies that the first variable specified in |
List with values for:
total_between_sess_intervals: The total number of between-session intervals present in the data set, NAs are also included here. This multiplies the number of cases (rows) with the number of specified between-session intervals: nrows * (length(sg_var_list) - 1)
.
total_between_sess_intervals_sg: The total number of between-session intervals where sudden gains can theoretically, NAs are also included here. This multiplies the number of cases (rows) with the number of between-session intervals where sudden gains can be identified using the 3 original criteria: nrows * (length(sg_var_list) - 3)
.
available_between_sess_intervals_sg: The total number of between-session intervals that can be analysed for sudden gains taking into account the pattern of missing data.
not_available_between_sess_intervals_sg: The total number of between-session intervals that can not be analysed for sudden gains due to the pattern of missing data.
# Count between session intervals in "sgdata" count_intervals(data = sgdata, id_var_name = "id", sg_var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"))
# Count between session intervals in "sgdata" count_intervals(data = sgdata, id_var_name = "id", sg_var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"))
This function returns a wide data set with one row for each case in data
.
The data set includes variables indicating whether each case experienced a sudden gain/loss or not,
values around the period of each gain/loss, and descriptives.
For cases with no sudden gain/loss the descriptive variables are coded as missing (NA
).
create_byperson( data, sg_crit1_cutoff, id_var_name, sg_var_list, tx_start_var_name, tx_end_var_name, sg_measure_name, multiple_sg_select = c("first", "last", "smallest", "largest"), data_is_bysg = FALSE, identify = c("sg", "sl"), sg_crit2_pct = 0.25, sg_crit3 = TRUE, sg_crit3_alpha = 0.05, sg_crit3_adjust = TRUE, sg_crit3_critical_value = 2.776, identify_sg_1to2 = FALSE )
create_byperson( data, sg_crit1_cutoff, id_var_name, sg_var_list, tx_start_var_name, tx_end_var_name, sg_measure_name, multiple_sg_select = c("first", "last", "smallest", "largest"), data_is_bysg = FALSE, identify = c("sg", "sl"), sg_crit2_pct = 0.25, sg_crit3 = TRUE, sg_crit3_alpha = 0.05, sg_crit3_adjust = TRUE, sg_crit3_critical_value = 2.776, identify_sg_1to2 = FALSE )
data |
A data set in wide format including an ID variable and variables for each measurement point. |
sg_crit1_cutoff |
Numeric, specifying the cut-off value to be used for the first sudden gains criterion.
The function |
id_var_name |
String, specifying the name of the ID variable. |
sg_var_list |
Vector, specifying the variable names of each measurement point sequentially. |
tx_start_var_name |
String, specifying the variable name of the first measurement point of the intervention. |
tx_end_var_name |
String, specifying the variable name of the last measurement point of the intervention. |
sg_measure_name |
String, specifying the name of the measure used to identify sudden gains/losses. |
multiple_sg_select |
String, specifying which sudden gain/loss to select for this data set if more than one gain/loss was identified per case.
Options are: |
data_is_bysg |
Logical, specifying whether the data set in the |
identify |
String, specifying whether to identify sudden gains ( |
sg_crit2_pct |
Numeric, specifying the percentage change to be used for the second sudden gains/losses criterion.
If set to |
sg_crit3 |
If set to |
sg_crit3_alpha |
Numeric, alpha for the student t-test (two-tailed) to determine the critical value to be used for the third criterion. Degrees of freedom are based on the number of available data in the three sessions preceding the gain and the three sessions following the gain. |
sg_crit3_adjust |
Logical, specify whether critical value gets adjusted for missingness, see Lutz et al. (2013) and the documentation of this R package for further details.
This argument is set to |
sg_crit3_critical_value |
Numeric, specifying the critical value to instead be used for all comparisons, regardless of missingnes in the sequence of data points that are investigated for potential sudden gains. |
identify_sg_1to2 |
Logical, indicating whether to identify sudden losses from measurement point 1 to 2.
If set to TRUE, this implies that the first variable specified in |
A wide data set with one row per case (id_var_name
) in data
.
Tang, T. Z., & DeRubeis, R. J. (1999). Sudden gains and critical sessions in cognitive-behavioral therapy for depression. Journal of Consulting and Clinical Psychology, 67(6), 894–904. doi:10.1037/0022-006X.67.6.894.
# Create byperson data set, selecting the largest gain in case of muliple gains create_byperson(data = sgdata, sg_crit1_cutoff = 7, id_var_name = "id", tx_start_var_name = "bdi_s1", tx_end_var_name = "bdi_s12", sg_var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"), sg_measure_name = "bdi", multiple_sg_select = "largest")
# Create byperson data set, selecting the largest gain in case of muliple gains create_byperson(data = sgdata, sg_crit1_cutoff = 7, id_var_name = "id", tx_start_var_name = "bdi_s1", tx_end_var_name = "bdi_s12", sg_var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"), sg_measure_name = "bdi", multiple_sg_select = "largest")
This function returns a wide data set with one row for each sudden gain/loss and assigns a unique identifier to each. The data set includes variables indicating values around the period of each gain/loss, and calculates descriptives of each gain/loss.
create_bysg( data, sg_crit1_cutoff, id_var_name, sg_var_list, tx_start_var_name, tx_end_var_name, sg_measure_name, sg_crit2_pct = 0.25, sg_crit3 = TRUE, sg_crit3_alpha = 0.05, sg_crit3_adjust = TRUE, sg_crit3_critical_value = 2.776, identify = c("sg", "sl"), identify_sg_1to2 = FALSE )
create_bysg( data, sg_crit1_cutoff, id_var_name, sg_var_list, tx_start_var_name, tx_end_var_name, sg_measure_name, sg_crit2_pct = 0.25, sg_crit3 = TRUE, sg_crit3_alpha = 0.05, sg_crit3_adjust = TRUE, sg_crit3_critical_value = 2.776, identify = c("sg", "sl"), identify_sg_1to2 = FALSE )
data |
A data set in wide format including an ID variable and variables for each measurement point. |
sg_crit1_cutoff |
Numeric, specifying the cut-off value to be used for the first sudden gains criterion.
The function |
id_var_name |
String, specifying the name of the ID variable. |
sg_var_list |
Vector, specifying the variable names of each measurement point sequentially. |
tx_start_var_name |
String, specifying the variable name of the first measurement point of the intervention. |
tx_end_var_name |
String, specifying the variable name of the last measurement point of the intervention. |
sg_measure_name |
String, specifying the name of the measure used to identify sudden gains/losses. |
sg_crit2_pct |
Numeric, specifying the percentage change to be used for the second sudden gains/losses criterion.
If set to |
sg_crit3 |
If set to |
sg_crit3_alpha |
Numeric, alpha for the student t-test (two-tailed) to determine the critical value to be used for the third criterion. Degrees of freedom are based on the number of available data in the three sessions preceding the gain and the three sessions following the gain. |
sg_crit3_adjust |
Logical, specify whether critical value gets adjusted for missingness, see Lutz et al. (2013) and the documentation of this R package for further details.
This argument is set to |
sg_crit3_critical_value |
Numeric, specifying the critical value to instead be used for all comparisons, regardless of missingnes in the sequence of data points that are investigated for potential sudden gains.#' |
identify |
String, specifying whether to identify sudden gains ( |
identify_sg_1to2 |
Logical, indicating whether to identify sudden losses from measurement point 1 to 2.
If set to TRUE, this implies that the first variable specified in |
A wide data set with one row per sudden gain/loss.
Tang, T. Z., & DeRubeis, R. J. (1999). Sudden gains and critical sessions in cognitive-behavioral therapy for depression. Journal of Consulting and Clinical Psychology, 67(6), 894–904. doi:10.1037/0022-006X.67.6.894.
# Create bypsg data set create_bysg(data = sgdata, sg_crit1_cutoff = 7, id_var_name = "id", tx_start_var_name = "bdi_s1", tx_end_var_name = "bdi_s12", sg_var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"), sg_measure_name = "bdi")
# Create bypsg data set create_bysg(data = sgdata, sg_crit1_cutoff = 7, id_var_name = "id", tx_start_var_name = "bdi_s1", tx_end_var_name = "bdi_s12", sg_var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"), sg_measure_name = "bdi")
Define a cut-off value for the first sudden gains criterion based on the Reliable Change Index (RCI; Jacobson & Truax, 1991) using an estimate for the standard deviation (sd) of the normal population and the reliability of the scale.
These values can be entered manually using the arguments sd
and reliability
or extracted from data using the arguments data_sd
and data_reliability
.
This function calculates the standard error of measurement (se), the standard error of the difference (sdiff) and a value that classifies as reliable change (reliable_change_value) based on the Reliable Change Index (RCI; Jacobson & Truax, 1991).
define_crit1_cutoff( sd = NULL, reliability = NULL, data_sd = NULL, data_reliability = NULL )
define_crit1_cutoff( sd = NULL, reliability = NULL, data_sd = NULL, data_reliability = NULL )
sd |
Numeric, standard deviation of normal population or standard deviation at baseline.
This argument is not needed if a vector with pretreatment scores is specified in the |
reliability |
Numeric, between 0 and 1 indicating reliability of the scale.
This argument is not needed if item-by-item data is specified in the |
data_sd |
A vector with pretreatment values.
This argument is not needed if the standard deviation is specified in the |
data_reliability |
A dataset in wide format (one row for each individual and one column for each item) including only the item-by-item scores of the SG measure (no ID variable).
According to Jacobson & Truax (1991) the test-retest reliability should be used.
Martinovich et al. (1996) suggest that the internal consistency (Cronbach's alpha) can be used instead of the test-retest reliability and may be more appropriate for estimating the standard error in some cases.
This argument is not needed if the reliability is specified in the |
A list with estimates the for standard error of measurement (se), the standard error of the difference (sdiff) and a value that classifies as reliable change (reliable_change_value).
Jacobson, N. S., & Truax, P. A. (1991). Clinical significance: A statistical approach to defining meaningful change in psychotherapy research. Journal of Consulting and Clinical Psychology, 59 (1), 12-19. doi:10.1037/0022-006X.59.1.12.
Martinovich, Z., Saunders, S., & Howard, K. (1996). Some Comments on “Assessing Clinical Significance”. Psychotherapy Research, 6(2), 124–132. doi:10.1080/10503309612331331648.
Stiles et al. (2003). Early sudden gains in psychotherapy under routine clinic conditions: Practice-based evidence. Journal of Consulting and Clinical Psychology, 71 (1), 14-21. doi:10.1037/0022-006X.71.1.14.
# Define cut-off value for first SG criterion # In this example the standard deviation and the reliability are specified manually define_crit1_cutoff(sd = 10.5, reliability = 0.931) # In this example the reliability is specified manually # The standard deviation of the variable "bdi_s0" in the dataset "sgdata" gets calculated define_crit1_cutoff(data_sd = sgdata$bdi_s0, reliability = 0.931)
# Define cut-off value for first SG criterion # In this example the standard deviation and the reliability are specified manually define_crit1_cutoff(sd = 10.5, reliability = 0.931) # In this example the reliability is specified manually # The standard deviation of the variable "bdi_s0" in the dataset "sgdata" gets calculated define_crit1_cutoff(data_sd = sgdata$bdi_s0, reliability = 0.931)
Descriptives might differ between the bysg and byperson data sets depending on whether multiple gains are present.
describe_sg(data, sg_data_structure = c("bysg", "byperson"))
describe_sg(data, sg_data_structure = c("bysg", "byperson"))
data |
A |
sg_data_structure |
String, indicating whether the input data is a |
A list, showing basic descriptive statistics for sudden gains within the dataset specified.
Note that some numbers (e.g. percentages) will be different depending which dataset is selected, because where a participant has multiple gains, only one is selected for the byperson
dataset.
The list includes values for:
total_n: number of rows in input dataset
sg_total_n: total number of sudden gains
sg_n: number of people who experienced a sudden gain (byperson dataset only)
sg_pct: percentage of people in the input dataset who experienced a sudden gain
sg_multiple_n: number of people who experienced a sudden gain (byperson dataset only)
sg_multiple_pct: percentage of people in the input dataset who experienced more than one sudden gain
sg_reversal_n: number of sudden gains that later meet the criteria for a reversal
sg_reversal_pct: percentage of sudden gains that later meet the criteria for a reversal
sg_magnitude_m: mean magnitude of the sudden gains observed
sg_magnitude_sd: standard deviation of the magnitude of the sudden gains observed
# Create bysg dataset bysg <- create_bysg(data = sgdata, sg_crit1_cutoff = 7, id_var_name = "id", tx_start_var_name = "bdi_s1", tx_end_var_name = "bdi_s12", sg_var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"), sg_measure_name = "bdi") # Describe bysg dataset describe_sg(data = bysg, sg_data_structure = "bysg")
# Create bysg dataset bysg <- create_bysg(data = sgdata, sg_crit1_cutoff = 7, id_var_name = "id", tx_start_var_name = "bdi_s1", tx_end_var_name = "bdi_s12", sg_var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"), sg_measure_name = "bdi") # Describe bysg dataset describe_sg(data = bysg, sg_data_structure = "bysg")
Extract values of measures around the time of a sudden gain.
extract_values( data, id_var_name, extract_var_list, sg_session_n_var_name = "sg_session_n", extract_measure_name = "x", start_numbering = 1, add_to_data = TRUE )
extract_values( data, id_var_name, extract_var_list, sg_session_n_var_name = "sg_session_n", extract_measure_name = "x", start_numbering = 1, add_to_data = TRUE )
data |
A |
id_var_name |
String, specifying the name of the ID variable. |
extract_var_list |
List or vector, specifying the variable names of session to session scores to extract from.
If this is a list, the name of each element will be used when creating new variables.
Note that each element of this list must have the same number of repeated measures as specified in |
sg_session_n_var_name |
String, specifying variable name that contains information about the pregain session number. If the sudden gains data set was created using the suddengains R package, the default argument "sg_session_n" should be used. |
extract_measure_name |
String, if |
start_numbering |
Numeric, set to by default 1.
Change to 0 if a pre-treatment (e.g. baseline assessment) measurement point is included in |
add_to_data |
Logical, if set to |
A wide dataset with values for extract_measure_name
around the sudden gain.
# Create bysg dataset bysg <- create_bysg(data = sgdata, sg_crit1_cutoff = 7, id_var_name = "id", tx_start_var_name = "bdi_s1", tx_end_var_name = "bdi_s12", sg_var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"), sg_measure_name = "bdi") # For bysg dataset select "id" and "rq" variables first sgdata_rq <- sgdata %>% dplyr::select(id, rq_s0:rq_s12) # Join them with the sudden gains data set, here "bysg" bysg_rq <- bysg %>% dplyr::left_join(sgdata_rq, by = "id") # Extract "rq" scores around sudden gains on "bdi" in the bysg dataset bysg_rq <- extract_values(data = bysg_rq, id_var_name = "id_sg", extract_var_list = c("rq_s1", "rq_s2", "rq_s3", "rq_s4", "rq_s5", "rq_s6", "rq_s7", "rq_s8", "rq_s9", "rq_s10", "rq_s11", "rq_s12"), extract_measure_name = "rq", add_to_data = TRUE)
# Create bysg dataset bysg <- create_bysg(data = sgdata, sg_crit1_cutoff = 7, id_var_name = "id", tx_start_var_name = "bdi_s1", tx_end_var_name = "bdi_s12", sg_var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"), sg_measure_name = "bdi") # For bysg dataset select "id" and "rq" variables first sgdata_rq <- sgdata %>% dplyr::select(id, rq_s0:rq_s12) # Join them with the sudden gains data set, here "bysg" bysg_rq <- bysg %>% dplyr::left_join(sgdata_rq, by = "id") # Extract "rq" scores around sudden gains on "bdi" in the bysg dataset bysg_rq <- extract_values(data = bysg_rq, id_var_name = "id_sg", extract_var_list = c("rq_s1", "rq_s2", "rq_s3", "rq_s4", "rq_s5", "rq_s6", "rq_s7", "rq_s8", "rq_s9", "rq_s10", "rq_s11", "rq_s12"), extract_measure_name = "rq", add_to_data = TRUE)
Function to identify sudden gains in longitudinal data structured in wide format.
identify_sg( data, id_var_name, sg_var_list, sg_crit1_cutoff, sg_crit2_pct = 0.25, sg_crit3 = TRUE, sg_crit3_alpha = 0.05, sg_crit3_adjust = TRUE, sg_crit3_critical_value = 2.776, identify_sg_1to2 = FALSE, crit123_details = FALSE )
identify_sg( data, id_var_name, sg_var_list, sg_crit1_cutoff, sg_crit2_pct = 0.25, sg_crit3 = TRUE, sg_crit3_alpha = 0.05, sg_crit3_adjust = TRUE, sg_crit3_critical_value = 2.776, identify_sg_1to2 = FALSE, crit123_details = FALSE )
data |
A data set in wide format including an ID variable and variables for each measurement point. |
id_var_name |
String, specifying the name of the ID variable. Each row should have a unique value. |
sg_var_list |
Vector, specifying the variable names of each measurement point sequentially. |
sg_crit1_cutoff |
Numeric, specifying the cut-off value to be used for the first sudden gains criterion.
The function |
sg_crit2_pct |
Numeric, specifying the percentage change to be used for the second sudden gains criterion.
If set to |
sg_crit3 |
If set to |
sg_crit3_alpha |
Numeric, alpha for the two-tailed student t-test to determine the critical value to be used for the third criterion. Degrees of freedom are based on the number of available data in the three sessions preceding the gain and the three sessions following the gain. |
sg_crit3_adjust |
Logical, specify whether critical value gets adjusted for missingness, see Lutz et al. (2013) and the documentation of this R package for further details.
This argument is set to |
sg_crit3_critical_value |
Numeric, specifying the critical value to instead be used for all comparisons, regardless of missingnes in the sequence of data points that are investigated for potential sudden gains. |
identify_sg_1to2 |
Logical, indicating whether to identify sudden gains from measurement point 1 to 2.
If set to TRUE, this implies that the first variable specified in |
crit123_details |
Logical, if set to |
A wide data set indicating whether sudden gains are present for each session to session interval for all cases in data
.
Lutz, W., Ehrlich, T., Rubel, J., Hallwachs, N., Röttger, M.-A., Jorasz, C., … Tschitsaz-Stucki, A. (2013). The ups and downs of psychotherapy: Sudden gains and sudden losses identified with session reports. Psychotherapy Research, 23(1), 14–24. doi:10.1080/10503307.2012.693837.
Tang, T. Z., & DeRubeis, R. J. (1999). Sudden gains and critical sessions in cognitive-behavioral therapy for depression. Journal of Consulting and Clinical Psychology, 67(6), 894–904. doi:10.1037/0022-006X.67.6.894.
# Identify sudden gains identify_sg(data = sgdata, sg_crit1_cutoff = 7, id_var_name = "id", sg_var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"))
# Identify sudden gains identify_sg(data = sgdata, sg_crit1_cutoff = 7, id_var_name = "id", sg_var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"))
Function to identify sudden losses in longitudinal data structured in wide format.
identify_sl( data, id_var_name, sg_var_list, sg_crit1_cutoff, sg_crit2_pct = 0.25, sg_crit3 = TRUE, sg_crit3_alpha = 0.05, sg_crit3_adjust = TRUE, sg_crit3_critical_value = 2.776, identify_sg_1to2 = FALSE, crit123_details = FALSE )
identify_sl( data, id_var_name, sg_var_list, sg_crit1_cutoff, sg_crit2_pct = 0.25, sg_crit3 = TRUE, sg_crit3_alpha = 0.05, sg_crit3_adjust = TRUE, sg_crit3_critical_value = 2.776, identify_sg_1to2 = FALSE, crit123_details = FALSE )
data |
A data set in wide format including an ID variable and variables for each measurement point. |
id_var_name |
String, specifying the name of the ID variable. Each row should have a unique value. |
sg_var_list |
Vector, specifying the variable names of each measurement point sequentially. |
sg_crit1_cutoff |
Numeric, specifying the negative cut-off value to be used for the first sudden losses criterion, see examples below.
The function |
sg_crit2_pct |
Numeric, specifying the percentage change to be used for the second sudden losses criterion.
If set to |
sg_crit3 |
Logical, if set to |
sg_crit3_alpha |
Numeric, alpha for the student t-test (two-tailed) to determine the critical value to be used for the third criterion. Degrees of freedom are based on the number of available data in the three sessions preceding the loss and the three sessions following the loss. |
sg_crit3_adjust |
Logical, specify whether critical value gets adjusted for missingness, see Lutz et al. (2013) and the documentation of this R package for further details.
This argument is set to |
sg_crit3_critical_value |
Numeric, if the argument |
identify_sg_1to2 |
Logical, indicating whether to identify sudden losses from measurement point 1 to 2.
If set to TRUE, this implies that the first variable specified in |
crit123_details |
Logical, if set to |
A wide data set indicating whether sudden losses are present for each session to session interval for all cases in data
.
Lutz, W., Ehrlich, T., Rubel, J., Hallwachs, N., Röttger, M.-A., Jorasz, C., … Tschitsaz-Stucki, A. (2013). The ups and downs of psychotherapy: Sudden gains and sudden losses identified with session reports. Psychotherapy Research, 23(1), 14–24. doi:10.1080/10503307.2012.693837.
Tang, T. Z., & DeRubeis, R. J. (1999). Sudden gains and critical sessions in cognitive-behavioral therapy for depression. Journal of Consulting and Clinical Psychology, 67(6), 894–904. doi:10.1037/0022-006X.67.6.894.
# Identify sudden losses identify_sl(data = sgdata, # Negative cut-off value to identify sudden losses sg_crit1_cutoff = -7, id_var_name = "id", sg_var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"))
# Identify sudden losses identify_sl(data = sgdata, # Negative cut-off value to identify sudden losses sg_crit1_cutoff = -7, id_var_name = "id", sg_var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"))
Generates a plot of the mean values around the sudden gain using ggplot
.
This can be used to plot the primary outcome or secondary measures.
The parameters starting with "group" allow to plot the average gain magnitude by group.
Further ggplot2 components can be added using + following this function.
plot_sg( data, id_var_name, tx_start_var_name, tx_end_var_name, sg_pre_post_var_list, ylab, xlab = "Session", colour_single = "#239b89ff", colour_group = c("viridis", "ggplot", "grey"), viridis_option = c("D", "A", "B", "C"), viridis_begin = 0, viridis_end = 1, group_var_name = NULL, group_levels = NULL, group_labels = NULL, group_title = NULL, apaish = TRUE )
plot_sg( data, id_var_name, tx_start_var_name, tx_end_var_name, sg_pre_post_var_list, ylab, xlab = "Session", colour_single = "#239b89ff", colour_group = c("viridis", "ggplot", "grey"), viridis_option = c("D", "A", "B", "C"), viridis_begin = 0, viridis_end = 1, group_var_name = NULL, group_levels = NULL, group_labels = NULL, group_title = NULL, apaish = TRUE )
data |
A |
id_var_name |
String, specifying the name of the ID variable. |
tx_start_var_name |
String, specifying the variable name of the first measurement point of the intervention. |
tx_end_var_name |
String, specifying the variable name of the last measurement point of the intervention. |
sg_pre_post_var_list |
Vector, specifying the variable names of the 3 measurement points before, and the 3 after the sudden gain, for the measure being plotted. |
ylab |
String, specifying the label for the y axis i.e. the name of the measure being plotted. |
xlab |
String, specifying the label for the x axis, e.g. |
colour_single |
String, specifying the colour of the plot for one group. |
colour_group |
String, specifying the discrete colour palette to be used for the groups. |
viridis_option |
String specifying the colour option for discrete viridis palette, see |
viridis_begin |
Numeric, specifying hue between 0 and 1 at which the viridis colormap begins, see |
viridis_end |
Numeric, specifying hue between 0 and 1 at which the viridis colormap ends, see |
group_var_name |
String, specifying the variable name of the group variable. |
group_levels |
Vector, specifying the levels as numeric for the groups in |
group_labels |
Vector, specifying the label names as strings for the groups in |
group_title |
String, specifying the title that will be used for the groups specified in |
apaish |
Logical, make plot APA publishable. |
A plot of the mean values around the sudden gain, for the measure specified.
# First create a bysg (or byperson) dataset bysg <- create_bysg(data = sgdata, sg_crit1_cutoff = 7, id_var_name = "id", tx_start_var_name = "bdi_s1", tx_end_var_name = "bdi_s12", sg_var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"), sg_measure_name = "bdi") # Plot average change of BDI values around the period of the sudden gain plot_sg(data = bysg, id_var_name = "id", tx_start_var_name = "bdi_s1", tx_end_var_name = "bdi_s12", sg_pre_post_var_list = c("sg_bdi_2n", "sg_bdi_1n", "sg_bdi_n", "sg_bdi_n1", "sg_bdi_n2", "sg_bdi_n3"), ylab = "BDI", xlab = "Session")
# First create a bysg (or byperson) dataset bysg <- create_bysg(data = sgdata, sg_crit1_cutoff = 7, id_var_name = "id", tx_start_var_name = "bdi_s1", tx_end_var_name = "bdi_s12", sg_var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"), sg_measure_name = "bdi") # Plot average change of BDI values around the period of the sudden gain plot_sg(data = bysg, id_var_name = "id", tx_start_var_name = "bdi_s1", tx_end_var_name = "bdi_s12", sg_pre_post_var_list = c("sg_bdi_2n", "sg_bdi_1n", "sg_bdi_n", "sg_bdi_n1", "sg_bdi_n2", "sg_bdi_n3"), ylab = "BDI", xlab = "Session")
Plot summary of available data per time point and analysed session to session intervals
plot_sg_intervals(data, id_var_name, sg_var_list, identify_sg_1to2 = FALSE)
plot_sg_intervals(data, id_var_name, sg_var_list, identify_sg_1to2 = FALSE)
data |
A data set in wide format including an ID variable and variables for each measurement point. |
id_var_name |
String, specifying the name of the ID variable. Each row should have a unique value. |
sg_var_list |
Vector, specifying the variable names of each measurement point sequentially. |
identify_sg_1to2 |
Logical, indicating whether to identify sudden losses from measurement point 1 to 2.
If set to TRUE, this implies that the first variable specified in |
Plot showing percentage of available data per time point and percentage of session to session intervals that were analysed for sudden gains.
# Create plot plot_sg_intervals(data = sgdata, id_var_name = "id", sg_var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"))
# Create plot plot_sg_intervals(data = sgdata, id_var_name = "id", sg_var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"))
Plot individual trajectories of selected cases using ggplot
.
This function can be combined with a filter command to explore the trajectories of individual or groups of cases.
Further ggplot2 components can be added using + following this function.
plot_sg_trajectories( data, id_var, var_list, select_id_list = NULL, select_n = NULL, show_id = TRUE, show_legend = TRUE, legend_title = "ID", id_label_size = 2, connect_missing = TRUE, colour = c("viridis", "ggplot", "grey"), viridis_option = c("D", "A", "B", "C"), viridis_begin = 0, viridis_end = 1, line_alpha = 1, point_alpha = 1, xlab = "X", ylab = "Y", scale_x_num = FALSE, scale_x_num_start = 1, apaish = TRUE, ... )
plot_sg_trajectories( data, id_var, var_list, select_id_list = NULL, select_n = NULL, show_id = TRUE, show_legend = TRUE, legend_title = "ID", id_label_size = 2, connect_missing = TRUE, colour = c("viridis", "ggplot", "grey"), viridis_option = c("D", "A", "B", "C"), viridis_begin = 0, viridis_end = 1, line_alpha = 1, point_alpha = 1, xlab = "X", ylab = "Y", scale_x_num = FALSE, scale_x_num_start = 1, apaish = TRUE, ... )
data |
Dataset in wide format. |
id_var |
String, specifying ID variable. |
var_list |
Vector, specifying variable names to be plotted in sequential order. |
select_id_list |
Vector, specifying case IDs to be plotted. |
select_n |
Numeric, specifying number of randomly selected cases to be plotted. |
show_id |
Logical, specifying whether or not to show ID variables inside the plot near the first measurement point. |
show_legend |
Logical, specifying whether or not a legend of all IDs. |
legend_title |
String, specifying the title of legend, by default the variable name of |
id_label_size |
Numeric, specifying the size of the ID label, if |
connect_missing |
Logical, specifying whether to connect points across missing values. |
colour |
String, specifying the discrete colour palette to be used. |
viridis_option |
String, specifying the colour option for discrete viridis palette, if |
viridis_begin |
Numeric, specifying hue between 0 and 1 at which the viridis colormap begins, if |
viridis_end |
Numeric, specifying hue between 0 and 1 at which the viridis colormap ends, if |
line_alpha |
Numeric, specifying alpha (transparency) of lines. |
point_alpha |
Numeric, specifying alpha (transparency) of points. |
xlab |
String for x axis label. |
ylab |
String for y axis label. |
scale_x_num |
Logical, if |
scale_x_num_start |
Numeric, specifying the starting value of the x axis, if |
apaish |
Logical, if |
... |
Further arguments to be passed on to |
ggplot2 object
# Plot individual trajectories of IDs 2, 4, 5, and 9 plot_sg_trajectories(data = sgdata, id_var = "id", select_id_list = c("2", "4", "5", "9"), var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"), show_id = TRUE, id_label_size = 4, label.padding = .2, show_legend = FALSE, colour = "viridis", viridis_option = "D", viridis_begin = 0, viridis_end = .8, connect_missing = FALSE, scale_x_num = TRUE, scale_x_num_start = 1, apaish = TRUE, xlab = "Session", ylab = "BDI") # Create byperson dataset to use for plotting byperson <- create_byperson(data = sgdata, sg_crit1_cutoff = 7, id_var_name = "id", tx_start_var_name = "bdi_s1", tx_end_var_name = "bdi_s12", sg_var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"), sg_measure_name = "bdi") # First, filter byperson dataset to only include cases with more than one sudden gain # Next, plot BDI trajectory of 3 randomly selected cases with with more than one sudden gain byperson %>% dplyr::filter(sg_freq_byperson > 1) %>% plot_sg_trajectories(id_var = "id_sg", var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"), select_n = 3, show_id = TRUE, show_legend = TRUE, scale_x_num = TRUE, scale_x_num_start = 1, xlab = "Session", ylab = "BDI")
# Plot individual trajectories of IDs 2, 4, 5, and 9 plot_sg_trajectories(data = sgdata, id_var = "id", select_id_list = c("2", "4", "5", "9"), var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"), show_id = TRUE, id_label_size = 4, label.padding = .2, show_legend = FALSE, colour = "viridis", viridis_option = "D", viridis_begin = 0, viridis_end = .8, connect_missing = FALSE, scale_x_num = TRUE, scale_x_num_start = 1, apaish = TRUE, xlab = "Session", ylab = "BDI") # Create byperson dataset to use for plotting byperson <- create_byperson(data = sgdata, sg_crit1_cutoff = 7, id_var_name = "id", tx_start_var_name = "bdi_s1", tx_end_var_name = "bdi_s12", sg_var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"), sg_measure_name = "bdi") # First, filter byperson dataset to only include cases with more than one sudden gain # Next, plot BDI trajectory of 3 randomly selected cases with with more than one sudden gain byperson %>% dplyr::filter(sg_freq_byperson > 1) %>% plot_sg_trajectories(id_var = "id_sg", var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"), select_n = 3, show_id = TRUE, show_legend = TRUE, scale_x_num = TRUE, scale_x_num_start = 1, xlab = "Session", ylab = "BDI")
Rename variable names to a generic and consistent format that can be used by other functions of the suddengains package.
rename_sg_vars( data, rename_var_list, new_var_str = "temp_var_", start_numbering = 1 )
rename_sg_vars( data, rename_var_list, new_var_str = "temp_var_", start_numbering = 1 )
data |
Dataframe in wide format. |
rename_var_list |
Vector of variables to be renamed. |
new_var_str |
String, new name for variables. |
start_numbering |
Numeric, first number to be used as suffix for renaming variables specified in "rename_var_list". |
Dataframe in wide format with renamed variables.
Select sample for further sudden gains analyses depending on specified methods.
The following table shows the different data patterns that get selected when method = "pattern"
.
This function goes through the data and selects all cases with at least one of the following data patterns.
Pattern | x1 | x2 | x3 | x4 | x5 | x6 |
1. | x | N | x | x | . | . |
2. | x | N | x | . | x | . |
3. | x | . | N | x | x | . |
4. | x | . | N | x | . | x |
Note. x1 to x6 are consecutive data points of the primary outcome measure. 'x' = Available data; '.' = Missing data. 'N' represents available data to be examined as a possible pregain session.
select_cases( data, id_var_name, sg_var_list, method = c("pattern", "min_sess"), min_sess_num = NULL, return_id_lgl = FALSE )
select_cases( data, id_var_name, sg_var_list, method = c("pattern", "min_sess"), min_sess_num = NULL, return_id_lgl = FALSE )
data |
A dataset in wide format with an id variable and the sudden gains variables. |
id_var_name |
String, specifying the name of the ID variable. Each row should have a unique value. |
sg_var_list |
Vector, specifying the variable names of each measurement point sequentially. |
method |
String, specifying the method used to select cases: |
min_sess_num |
Numeric, minimum number of available sessions to be selected.
This argument needs to be specified if |
return_id_lgl |
Logical, if |
A wide dataset indicating with all cases and a variable indicating whether each cases provides enough data to identify sudden gains.
# 1. method = "pattern" select_cases(data = sgdata, id_var_name = "id", sg_var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"), method = "pattern", return_id_lgl = FALSE) # 2. method = "min_sess" select_cases(data = sgdata, id_var_name = "id", sg_var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"), method = "min_sess", min_sess_num = 9, return_id_lgl = TRUE)
# 1. method = "pattern" select_cases(data = sgdata, id_var_name = "id", sg_var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"), method = "pattern", return_id_lgl = FALSE) # 2. method = "min_sess" select_cases(data = sgdata, id_var_name = "id", sg_var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"), method = "min_sess", min_sess_num = 9, return_id_lgl = TRUE)
Example dataset with a measure of depression symptoms (BDI) and a secondary process measure (RQ; Rumination Questionnaire) to illustrate how the package works.
data(sgdata)
data(sgdata)
A longitudinal dataset in wide format, i.e one row per person, one column per variable.
id: ID variable, unique identifier for each person
bdi_s0: BDI value, baseline assessment
bdi_s1: BDI value, session 1
bdi_s2: BDI value, session 2
bdi_s3: BDI value, session 3
bdi_s4: BDI value, session 4
bdi_s5: BDI value, session 5
bdi_s6: BDI value, session 6
bdi_s7: BDI value, session 7
bdi_s8: BDI value, session 8
bdi_s9: BDI value, session 9
bdi_s10: BDI value, session 10
bdi_s11: BDI value, session 11
bdi_s12: BDI value, session 12
bdi_fu1: BDI value, follow-up measure 1
bdi_fu2: BDI value, follow-up measure 2
rq_s0: RQ value, baseline assessment
rq_s1: RQ value, session 1
rq_s2: RQ value, session 2
rq_s3: RQ value, session 3
rq_s4: RQ value, session 4
rq_s5: RQ value, session 5
rq_s6: RQ value, session 6
rq_s7: RQ value, session 7
rq_s8: RQ value, session 8
rq_s9: RQ value, session 9
rq_s10: RQ value, session 10
rq_s11: RQ value, session 11
rq_s12: RQ value, session 12
rq_fu1: RQ value, follow-up measure 1
rq_fu2: RQ value, follow-up measure 2
# Load data into global environment data(sgdata)
# Load data into global environment data(sgdata)
Same as sgdata
but with bad variable names to illustrate that the package can also work with inconsistent names.
data(sgdata_bad)
data(sgdata_bad)
A longitudinal dataset in wide format, i.e one row per person, one column per variable.
id: ID variable, unique identifier for each person
bdi_intake: BDI value, baseline assessment
bdi1: BDI value, session 1
wk2bdi: BDI value, session 2
bdi.S3: BDI value, session 3
bdis4: BDI value, session 4
bdi_session5: BDI value, session 5
bdi_weekSix: BDI value, session 6
beck.dep.inv_sess7: BDI value, session 7
weeeek8bdi: BDI value, session 8
bdi_nine: BDI value, session 9
bdii10: BDI value, session 10
bDi11: BDI value, session 11
bdi_s12_end: BDI value, session 12
bdi_fu1: BDI value, follow-up measure 1
bdi_followup2: BDI value, follow-up measure 2
rq_intake: RQ value, baseline assessment
rqi1: RQ value, session 1
wk2rq: RQ value, session 2
rq.S3: RQ value, session 3
rq_s4: RQ value, session 4
rq_session5: RQ value, session 5
rq_weekSix: RQ value, session 6
rq_sess7: RQ value, session 7
weeeek8rq: RQ value, session 8
rqnine: RQ value, session 9
rq10: RQ value, session 10
rqi11: RQ value, session 11
rq_s12_end: RQ value, session 12
prq_fu1: RQ value, follow-up measure 1
rqq_followup2: RQ value, follow-up measure 2
# Load data into global environment data(sgdata_bad)
# Load data into global environment data(sgdata_bad)
Writes a data frame as a specified file type.
write_byperson( data, sg_crit1_cutoff, id_var_name, sg_var_list, tx_start_var_name, tx_end_var_name, sg_measure_name, sg_crit2_pct = 0.25, sg_crit3 = TRUE, sg_crit3_alpha = 0.05, sg_crit3_adjust = TRUE, sg_crit3_critical_value = 2.776, identify = c("sg", "sl"), identify_sg_1to2 = FALSE, multiple_sg_select = c("first", "last", "smallest", "largest"), data_is_bysg = FALSE, format = c("CSV", "SPSS", "STATA", "Excel"), path, stata_version = 14, ... )
write_byperson( data, sg_crit1_cutoff, id_var_name, sg_var_list, tx_start_var_name, tx_end_var_name, sg_measure_name, sg_crit2_pct = 0.25, sg_crit3 = TRUE, sg_crit3_alpha = 0.05, sg_crit3_adjust = TRUE, sg_crit3_critical_value = 2.776, identify = c("sg", "sl"), identify_sg_1to2 = FALSE, multiple_sg_select = c("first", "last", "smallest", "largest"), data_is_bysg = FALSE, format = c("CSV", "SPSS", "STATA", "Excel"), path, stata_version = 14, ... )
data |
A data set in wide format including an ID variable and variables for each measurement point. |
sg_crit1_cutoff |
Numeric, specifying the cut-off value to be used for the first sudden gains criterion.
The function |
id_var_name |
String, specifying the name of the ID variable. Each row should have a unique value. |
sg_var_list |
Vector, specifying the variable names of each measurement point sequentially. |
tx_start_var_name |
String, specifying the variable name of the first measurement point of the intervention. |
tx_end_var_name |
String, specifying the variable name of the last measurement point of the intervention. |
sg_measure_name |
String, specifying the name of the measure used to identify sudden gains/losses. |
sg_crit2_pct |
Numeric, specifying the percentage change to be used for the second sudden gains/losses criterion.
If set to |
sg_crit3 |
If set to |
sg_crit3_alpha |
Numeric, alpha for the student t-test (two-tailed) to determine the critical value to be used for the third criterion. Degrees of freedom are based on the number of available data in the three sessions preceding the gain and the three sessions following the gain. |
sg_crit3_adjust |
Logical, specify whether critical value gets adjusted for missingness, see Lutz et al. (2013) and the documentation of this R package for further details.
This argument is set to |
sg_crit3_critical_value |
Numeric, specifying the critical value to instead be used for all comparisons, regardless of missingnes in the sequence of data points that are investigated for potential sudden gains.#' |
identify |
String, specifying whether to identify sudden gains ( |
identify_sg_1to2 |
Logical, indicating whether to identify sudden losses from measurement point 1 to 2. |
multiple_sg_select |
String, specifying which sudden gain/loss to select for this data set if more than one gain/loss was identified per case.
Options are: |
data_is_bysg |
Logical, specifying whether the data set in the |
format |
String, specifying the format of the data file, |
path |
String, specifying the file name ending with the matching file extension,
|
stata_version |
Numeric, specifying STATA version number. |
... |
Additional parameters to be passed on to the specified write function,
see |
A csv file containing a wide data set with one row per case (id_var_name
) in data
.
Tang, T. Z., & DeRubeis, R. J. (1999). Sudden gains and critical sessions in cognitive-behavioral therapy for depression. Journal of Consulting and Clinical Psychology, 67(6), 894–904. doi:10.1037/0022-006X.67.6.894.
# Adjust "path" argument before running # Create character string name for temporary "byperson.csv" file temp <- tempfile(pattern = "byperson", fileext = ".csv") # Write byperson dataset (CSV file) # To write a different format change the 'format' argument ... # ... as well as the file extension in the 'path' argument write_byperson(data = sgdata, sg_crit1_cutoff = 7, id_var_name = "id", tx_start_var_name = "bdi_s1", tx_end_var_name = "bdi_s12", sg_var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"), sg_measure_name = "bdi", identify_sg_1to2 = FALSE, multiple_sg_select = "largest", format = "CSV", path = temp)
# Adjust "path" argument before running # Create character string name for temporary "byperson.csv" file temp <- tempfile(pattern = "byperson", fileext = ".csv") # Write byperson dataset (CSV file) # To write a different format change the 'format' argument ... # ... as well as the file extension in the 'path' argument write_byperson(data = sgdata, sg_crit1_cutoff = 7, id_var_name = "id", tx_start_var_name = "bdi_s1", tx_end_var_name = "bdi_s12", sg_var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"), sg_measure_name = "bdi", identify_sg_1to2 = FALSE, multiple_sg_select = "largest", format = "CSV", path = temp)
Writes a data frame as a specified file type.
write_bysg( data, sg_crit1_cutoff, id_var_name, sg_var_list, tx_start_var_name, tx_end_var_name, sg_measure_name, sg_crit2_pct = 0.25, sg_crit3 = TRUE, sg_crit3_alpha = 0.05, sg_crit3_adjust = TRUE, sg_crit3_critical_value = 2.776, identify = c("sg", "sl"), identify_sg_1to2 = FALSE, format = c("CSV", "SPSS", "STATA", "Excel"), path, stata_version = 14, ... )
write_bysg( data, sg_crit1_cutoff, id_var_name, sg_var_list, tx_start_var_name, tx_end_var_name, sg_measure_name, sg_crit2_pct = 0.25, sg_crit3 = TRUE, sg_crit3_alpha = 0.05, sg_crit3_adjust = TRUE, sg_crit3_critical_value = 2.776, identify = c("sg", "sl"), identify_sg_1to2 = FALSE, format = c("CSV", "SPSS", "STATA", "Excel"), path, stata_version = 14, ... )
data |
A data set in wide format including an ID variable and variables for each measurement point. |
sg_crit1_cutoff |
Numeric, specifying the cut-off value to be used for the first sudden gains criterion.
The function |
id_var_name |
String, specifying the name of the ID variable. Each row should have a unique value. |
sg_var_list |
Vector, specifying the variable names of each measurement point sequentially. |
tx_start_var_name |
String, specifying the variable name of the first measurement point of the intervention. |
tx_end_var_name |
String, specifying the variable name of the last measurement point of the intervention. |
sg_measure_name |
String, specifying the name of the measure used to identify sudden gains/losses. |
sg_crit2_pct |
Numeric, specifying the percentage change to be used for the second sudden gains/losses criterion.
If set to |
sg_crit3 |
If set to |
sg_crit3_alpha |
Numeric, alpha for the student t-test (two-tailed) to determine the critical value to be used for the third criterion. Degrees of freedom are based on the number of available data in the three sessions preceding the gain and the three sessions following the gain. |
sg_crit3_adjust |
Logical, specify whether critical value gets adjusted for missingness, see Lutz et al. (2013) and the documentation of this R package for further details.
This argument is set to |
sg_crit3_critical_value |
Numeric, specifying the critical value to instead be used for all comparisons, regardless of missingnes in the sequence of data points that are investigated for potential sudden gains. |
identify |
String, specifying whether to identify sudden gains ( |
identify_sg_1to2 |
Logical, indicating whether to identify sudden losses from measurement point 1 to 2. |
format |
String, specifying the format of the data file, |
path |
String, specifying the file name ending with the matching file extension,
|
stata_version |
Numeric, specifying STATA version number. |
... |
Additional parameters to be passed on to the specified write function,
see |
A csv file containing a wide data set with one row per sudden gain/loss.
Tang, T. Z., & DeRubeis, R. J. (1999). Sudden gains and critical sessions in cognitive-behavioral therapy for depression. Journal of Consulting and Clinical Psychology, 67(6), 894–904. doi:10.1037/0022-006X.67.6.894.
# Adjust "path" argument before running # Create character string name for temporary "bysg.csv" file temp <- tempfile(pattern = "bysg", fileext = ".csv") # Write bysg dataset (CSV file) # To write a different format change the 'format' argument # as well as the file extension in the 'path' argument write_bysg(data = sgdata, sg_crit1_cutoff = 7, id_var_name = "id", tx_start_var_name = "bdi_s1", tx_end_var_name = "bdi_s12", sg_var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"), sg_measure_name = "bdi", identify_sg_1to2 = FALSE, format = "CSV", path = temp)
# Adjust "path" argument before running # Create character string name for temporary "bysg.csv" file temp <- tempfile(pattern = "bysg", fileext = ".csv") # Write bysg dataset (CSV file) # To write a different format change the 'format' argument # as well as the file extension in the 'path' argument write_bysg(data = sgdata, sg_crit1_cutoff = 7, id_var_name = "id", tx_start_var_name = "bdi_s1", tx_end_var_name = "bdi_s12", sg_var_list = c("bdi_s1", "bdi_s2", "bdi_s3", "bdi_s4", "bdi_s5", "bdi_s6", "bdi_s7", "bdi_s8", "bdi_s9", "bdi_s10", "bdi_s11", "bdi_s12"), sg_measure_name = "bdi", identify_sg_1to2 = FALSE, format = "CSV", path = temp)