Transform to wide data with labels and impute baseline missing values
Source:R/margot_wide_impute_baseline.R
margot_wide_impute_baseline.Rd
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.
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