Skip to contents

This function transforms longitudinal data into a wide format and performs imputation on baseline variables. It leverages the `mice` package for imputation, ensuring that missing baseline data are appropriately handled. The function arranges data by participant id and time, filters based on time conditions, and reshapes the data into wide format. Imputed data are then merged back, maintaining the structure suitable for analysis.

Usage

margot_wide_impute_baseline(.data, baseline_vars, exposure_var, outcome_vars)

Arguments

.data

A dataframe containing the longitudinal data.

baseline_vars

A character vector of baseline variable names to include and impute if necessary.

exposure_var

A character vector specifying the names of exposure variables.

outcome_vars

A character vector specifying the names of outcome variables.

Value

A data frame in wide format with imputed baseline variables.

Examples

# df_nz is a synthetic dataset included in this package
data(df_nz, package = "margot")

df_nz <- data.frame(df_nz)
wide_data_imputed <- margot_wide_impute_baseline(df_nz,
  baseline_vars = c("age", "male", "religion_believe_god"),
  exposure_var = ("forgiveness"),
  outcome_vars = ("kessler_latent_anxiety")
  )
#> 
#>  iter imp variable
#>   1   1  t0_forgiveness  t0_kessler_latent_anxiety  t0_religion_believe_god
#>   2   1  t0_forgiveness  t0_kessler_latent_anxiety  t0_religion_believe_god
#>   3   1  t0_forgiveness  t0_kessler_latent_anxiety  t0_religion_believe_god
#>   4   1  t0_forgiveness  t0_kessler_latent_anxiety  t0_religion_believe_god
#>   5   1  t0_forgiveness  t0_kessler_latent_anxiety  t0_religion_believe_god