Skip to contents

Helper to tag reversed outcomes by prepending "(reduced)" to labels. This function now handles the new "_r" suffix convention for flipped models.

Usage

margot_reversed_labels(
  label_map,
  reversed,
  use_r_suffix = TRUE,
  remove_original = FALSE
)

Arguments

label_map

named list mapping variable names to human-readable labels

reversed

character vector of variable names that have been flipped

use_r_suffix

logical; if TRUE (default), creates new entries with "_r" suffix for flipped outcomes. If FALSE, uses the old behavior of modifying in-place.

remove_original

logical; if TRUE and use_r_suffix is TRUE, removes the original (non-flipped) entries from the label map. Default is FALSE.

Value

named list of labels, with "(reduced)" prepended to specified entries

Examples

label_mapping_all <- list(
  t2_log_hours_exercise_z        = "Hours of Exercise (log)",
  t2_hlth_fatigue_z              = "Fatigue",
  t2_kessler_latent_anxiety_z    = "Anxiety",
  t2_kessler_latent_depression_z = "Depression",
  t2_rumination_z                = "Rumination",
  t2_foregiveness_z              = "Forgiveness",
  t2_perfectionism_z             = "Perfectionism",
  t2_self_esteem_z               = "Self Esteem",
  t2_gratitude_z                 = "Gratitude",
  t2_lifesat_z                   = "Life Satisfaction",
  t2_meaning_purpose_z           = "Meaning: Purpose",
  t2_meaning_sense_z             = "Meaning: Sense",
  t2_pwi_z                       = "Personal Well-being Index",
  t2_belong_z                    = "Social Belonging",
  t2_neighbourhood_community_z   = "Neighbourhood Community",
  t2_support_z                   = "Social Support"
)

flip_outcomes <- c(
  "t2_kessler_latent_anxiety_z",
  "t2_kessler_latent_depression_z",
  "t2_rumination_z"
)

# new behavior (default): creates entries with _r suffix
label_mapping_new <- margot_reversed_labels(label_mapping_all, flip_outcomes)
print(label_mapping_new[c("t2_kessler_latent_anxiety_z", "t2_kessler_latent_anxiety_z_r")])
#> $t2_kessler_latent_anxiety_z
#> [1] "Anxiety"
#> 
#> $t2_kessler_latent_anxiety_z_r
#> [1] "(reduced) Anxiety"
#> 
#> $t2_kessler_latent_anxiety_z
#> [1] "Anxiety"
#> $t2_kessler_latent_anxiety_z_r
#> [1] "(reduced) Anxiety"

# old behavior: modifies in place
label_mapping_old <- margot_reversed_labels(label_mapping_all, flip_outcomes, use_r_suffix = FALSE)
print(label_mapping_old[["t2_kessler_latent_anxiety_z"]])
#> [1] "(reduced) Anxiety"
#> [1] "(reduced) Anxiety"

# remove original entries
label_mapping_clean <- margot_reversed_labels(label_mapping_all, flip_outcomes, remove_original = TRUE)
# original anxiety entry removed, only _r version remains