To fit the LOCF model, all individuals must have at least one non-NA entry by landmark time x_L for all covariates. This function selects these individuals and removes the other rows.

return_ids_with_LOCF(
  data_long,
  individual_id,
  x_L,
  covariates,
  covariates_time
)

Arguments

data_long

Data frame with repeated measurements data in long format

individual_id

Character string specifying the column name in data_long which contains the individual identifiers

x_L

Numeric specifying the landmark time(s)

covariates

Vector of character strings specifying the column names in data_long which correspond to the covariates

covariates_time

Vector of character strings specifying the column names in data_long which contain the times at which covariates were recorded. This should either be length 1 or the same length as covariates. In the latter case the order of elements must correspond to the order of elements in covariates.

Value

List of data frames which correspond to each landmark time x_L. Each data frame is an updated version of data_long which contains only rows of individuals with a LOCF at age x_L, other rows are removed.

Details

Individuals have a LOCF if there is a non-NA entry for each of the covariates in covariates up until (not including) time x_L.

Author

Isobel Barrott isobel.barrott@gmail.com

Examples

library(Landmarking)
data(data_repeat_outcomes)
data_repeat_outcomes <-
  return_ids_with_LOCF(
    data_long = data_repeat_outcomes,
    individual_id = "id",
    covariates =
      c("ethnicity", "smoking", "diabetes", "sbp_stnd", "tchdl_stnd"),
    covariates_time =
      c(rep("response_time_sbp_stnd", 4), "response_time_tchdl_stnd"),
    x_L = c(60,61)
  )