# Three measurement methods with an approximately normal core
set.seed(42)
x <- rnorm(40)
measurements <- cbind(
reference = x,
method_a = x + rnorm(40, sd = 0.2),
method_b = 0.4 + 1.2 * x + rnorm(40, sd = 0.3)
)
fit <- robust_ccc(measurements, seed = 42)
print(fit)
summary(fit)
estimate(fit)
coef(fit)
tidy(fit)
plot(fit)
# Compare classical and robust CCC before and after discordant contamination
contaminated <- measurements
contaminated[1, "reference"] <- 9
contaminated[1, "method_a"] <- -8
fit_contaminated <- robust_ccc(contaminated, seed = 42)
rbind(
clean = c(
classical = estimate(ccc(measurements))[1, 2],
robust = estimate(fit)[1, 2]
),
contaminated = c(
classical = estimate(ccc(contaminated))[1, 2],
robust = estimate(fit_contaminated)[1, 2]
)
)
# Alpha controls the retained subset fraction, not the search count
fit_half <- robust_ccc(contaminated, alpha = 0.5, seed = 42)
estimate(fit_half)
# Increase the initial subset search count while retaining reweighted MCD
fit_more <- robust_ccc(contaminated, mcd_nsamp = 1000L, seed = 42)
attr(fit_more, "mcd_nsamp")
attr(fit_more, "mcd_estimate")
# Global complete rows versus the finite overlap for each pair
incomplete <- measurements
incomplete[1, "reference"] <- NA
incomplete[2, "method_a"] <- Inf
fit_complete <- robust_ccc(incomplete, na_method = "complete", seed = 42)
fit_pairwise <- robust_ccc(incomplete, na_method = "pairwise", seed = 42)
estimate(fit_complete)
estimate(fit_pairwise)
# Thresholded outputs retain entries with absolute CCC at least 0.9
# Every MCD pair is still fitted before output conversion
fit_sparse <- robust_ccc(
measurements, seed = 42, output = "sparse", threshold = 0.9, diag = FALSE
)
fit_edges <- robust_ccc(
measurements, seed = 42, output = "edge_list", threshold = 0.9, diag = FALSE
)
fit_sparse
tidy(fit_edges)
# Paired percentile bootstrap intervals require many additional MCD fits
# \donttest{
# A small count keeps this illustration short; the default is 500 resamples
fit_ci <- robust_ccc(
measurements, ci = TRUE, conf_level = 0.95, n_boot = 100L, seed = 42
)
summary(fit_ci)
tidy(fit_ci)
ci(fit_ci)
confint(fit_ci)
plot(fit_ci)
attr(fit_ci, "diagnostics")$n_complete
# Off diagonal entries count finite bootstrap estimates
# Valid diagonal intervals are fixed at [1, 1] without refitting
attr(fit_ci, "diagnostics")$n_boot_success
# }
# Interactive viewing requires both suggested packages
if (interactive() &&
requireNamespace("shiny", quietly = TRUE) &&
requireNamespace("shinyWidgets", quietly = TRUE)) {
view_corr_shiny(fit)
}
Run the code above in your browser using DataLab