Skip to contents

Check if mcc object uses weighted estimation

Usage

is_weighted(x)

Arguments

x

An mcc object

Value

Logical indicating whether weighted estimation was used

Examples

# Create sample data
library(dplyr)
df <- data.frame(
  id = c(1, 2, 3, 4, 4, 4, 5, 5),
  time = c(8, 1, 5, 2, 6, 7, 3, 3),
  cause = c(0, 0, 2, 1, 1, 1, 1, 2)
) |>
  arrange(id, time)

# Calculate unweighted MCC
mcc_unweighted <- mcc(df, "id", "time", "cause")
#> Warning: Found 1 participant where last observation is an event of interest (`cause_var`
#> = 1)
#> ! ID: 4
#>  `mcc()` assumes these participants are censored at their final `time_var`
#>  If participants were actually censored or experienced competing risks after
#>   their last event, add those observations to ensure correct estimates
#>  Adjusted time points for events occurring simultaneously for the same subject.
is_weighted(mcc_unweighted)  # FALSE
#> [1] FALSE

# Create weighted data
df_weighted <- df |>
  group_by(id) |>
  slice(1) |>
  ungroup() |>
  mutate(weights = runif(n(), 0.5, 2.0)) |>
  select(id, weights) |>
  right_join(df, by = "id") |>
  arrange(id, time)

# Calculate weighted MCC
mcc_weighted <- mcc(df_weighted, "id", "time", "cause", weights = "weights")
#> Warning: Found 1 participant where last observation is an event of interest (`cause_var`
#> = 1)
#> ! ID: 4
#>  `mcc()` assumes these participants are censored at their final `time_var`
#>  If participants were actually censored or experienced competing risks after
#>   their last event, add those observations to ensure correct estimates
#>  Adjusted time points for events occurring simultaneously for the same subject.
is_weighted(mcc_weighted)  # TRUE
#> [1] TRUE

# Clean up
rm(df, df_weighted, mcc_unweighted, mcc_weighted)