suddengains (version 0.4.4)

select_cases: Select sample providing enough data to identify sudden gains

Description

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.

Patternx1x2x3x4x5x6
1.xNxx..
2.xNx.x.
3.x.Nxx.
4.x.Nx.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.

Usage

select_cases(
  data,
  id_var_name,
  sg_var_list,
  method = c("pattern", "min_sess"),
  min_sess_num = NULL,
  return_id_lgl = FALSE
)

Value

A wide dataset indicating with all cases and a variable indicating whether each cases provides enough data to identify sudden gains.

Arguments

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: pattern or min_sess.

min_sess_num

Numeric, minimum number of available sessions to be selected. This argument needs to be specified if method = min_sess.

return_id_lgl

Logical, if TRUE the function returns the ID variable and a new variable sg_select indicating whether there is enough data available to identify sudden gains. If set to FALSE this function returns the input data together with the new variable sg_select.

Examples

Run this code
# 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)

Run the code above in your browser using DataCamp Workspace