This function filters and processes survival and longitudinal data based on a specified landmark time. It adjusts the time variables in the data (i.e., survival time and longitudinal visit time) relative to the landmark time. The data are filtered to include only observations with survival times greater than or equal to the landmark time.

cutLMdata(
  ldata,
  sdata,
  id,
  stime,
  status,
  visitTime,
  lmtime,
  timeDep,
  timeFixed
)

Arguments

ldata

A data frame containing the longitudinal data. It must include the following columns: - `id`: A variable identifying subjects (e.g., subject ID). - `visitTime`: The time variable when the longitudinal measurement was recorded. - `stime`: The survival time variable. - `status`: The event status variable (e.g., 1 for event, 0 for censoring). - `timeDep`: A column containing time-dependent covariates. - `timeFixed`: A column containing time-fixed covariates.

sdata

A data frame containing the survival data. It must include the following columns: - `id`: A variable identifying subjects (same as in `ldata`). - `visitTime`: The time variable when the longitudinal measurement was recorded. - `stime`: The survival time variable. - `status`: The event status variable (same as in `ldata`). - `timeDep`: A column containing time-dependent covariates. - `timeFixed`: A column containing time-fixed covariates.

id

A character string specifying the name of the variable in both `ldata` and `sdata` that identifies subjects.

stime

A character string specifying the name of the survival time variable in both `ldata` and `sdata`.

status

A character string specifying the name of the event status variable in both `ldata` and `sdata`.

visitTime

A character string specifying the name of the visit time variable in both `ldata` and `sdata`.

lmtime

A numeric value specifying the landmark time. This is used to filter the data and adjust the time variables.

timeDep

A character string specifying the name of the time-dependent covariate(s) in both `ldata` and `sdata`.

timeFixed

A character string specifying the name of the time-fixed covariate(s) in both `ldata` and `sdata`.

Value

A list containing two components: - `Longdata`: A data frame containing the longitudinal data (`ldata`) filtered and adjusted relative to the landmark time. - `Survdata`: A data frame containing the survival data (`sdata`) filtered and adjusted relative to the landmark time.

Details

The function checks that the landmark time is within the range of survival times in `sdata`. If the `lmtime` is out of bounds, an error message is returned. Both the survival and longitudinal data are filtered to include only records where the survival time is greater than or equal to the landmark time. After filtering, the function adjusts the survival and visit times by subtracting the landmark time and ensures that negative longitudinal visit times are set to zero.

See also

`Surv` function for creating survival objects.

Examples

# Example usage
result <- cutLMdata(
  ldata = long_data,
  sdata = surv_data,
  id = "ID",
  stime = "survival_time",
  status = "survival_status",
  visitTime = "Time",
  lmtime = 2,
  timeDep = c("marker_1","marker_2","marker_3"),
  timeFixed = c("Z_1","Z_2")
)
# Accessing the processed data:
head(result$Longdata)
#>   ID Time survival_time survival_status  marker_1 marker_2 marker_3      Z_1
#> 3  2    0      6.827812               1  87.35792 46.69227 46.45367 42.94507
#> 4  2    0      6.827812               1  92.53286 49.08752 48.69088 42.94507
#> 5  2    0      6.827812               1  98.48226 50.63569 50.17329 42.94507
#> 6  2    1      6.827812               1 102.72872       NA 54.25012 42.94507
#> 7  2    2      6.827812               1        NA 57.92138 59.65818 42.94507
#> 8  3    0     10.396805               1  83.83849 45.51705 41.27908 39.45258
#>   Z_2
#> 3   1
#> 4   1
#> 5   1
#> 6   1
#> 7   1
#> 8   1
head(result$Survdata)
#>   ID Time survival_time survival_status  marker_1 marker_2 marker_3      Z_1
#> 2  2    4      6.827812               1        NA 57.92138 59.65818 42.94507
#> 3  3    4     10.396805               1  96.84821 56.48724 53.02516 39.45258
#> 4  4    4      4.456136               1 126.42010 67.09301 69.14951 53.85501
#> 5  5    4      7.156370               1 107.40190 59.86177 63.62087 45.34258
#> 6  6    4      9.139249               1 125.86399 68.22229 71.17523 52.16992
#> 7  7    4      9.687020               1  99.99836       NA 56.76058 41.52341
#>   Z_2
#> 2   1
#> 3   1
#> 4   1
#> 5   1
#> 6   1
#> 7   1