Skip to contents

Extract MCC estimates from mcc objects

Usage

mcc_estimates(x, ...)

Arguments

x

An mcc object

...

Additional arguments (currently unused)

Value

A tibble with MCC estimates

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 MCC
mcc_result <- 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.

# Extract MCC estimates
estimates <- mcc_estimates(mcc_result)
print(estimates)
#> # A tibble: 5 × 2
#>    time   mcc
#>   <dbl> <dbl>
#> 1     0  0   
#> 2     2  0.25
#> 3     3  0.5 
#> 4     6  0.75
#> 5     7  1   

# For grouped analysis
df_grouped <- df |>
  mutate(group = c("A", "A", "B", "B", "B", "B", "A", "A"))

mcc_grouped <- mcc(df_grouped, "id", "time", "cause", by = "group")
#>  Adjusted time points for events occurring simultaneously for the same subject.
#> 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
estimates_grouped <- mcc_estimates(mcc_grouped)
print(estimates_grouped)
#> # A tibble: 6 × 3
#>   group  time   mcc
#> * <chr> <dbl> <dbl>
#> 1 A         0   0  
#> 2 A         3   0.5
#> 3 B         0   0  
#> 4 B         2   0.5
#> 5 B         6   1  
#> 6 B         7   1.5

# Clean up
rm(df, df_grouped, mcc_result, mcc_grouped, estimates, estimates_grouped)