# Simple risk difference
data(cachar_sample)
rd_simple <- calc_risk_diff(
data = cachar_sample,
outcome = "abnormal_screen",
exposure = "areca_nut"
)
print(rd_simple)
# Age-adjusted risk difference
rd_adjusted <- calc_risk_diff(
data = cachar_sample,
outcome = "abnormal_screen",
exposure = "areca_nut",
adjust_vars = "age"
)
print(rd_adjusted)
# Stratified analysis with enhanced error checking and boundary detection
rd_stratified <- calc_risk_diff(
data = cachar_sample,
outcome = "abnormal_screen",
exposure = "areca_nut",
strata = "residence",
verbose = TRUE # See diagnostic messages and boundary detection
)
print(rd_stratified)
# Check for boundary cases
if (any(rd_stratified$on_boundary)) {
cat("Boundary cases detected!\n")
boundary_rows <- which(rd_stratified$on_boundary)
for (i in boundary_rows) {
cat("Row", i, ":", rd_stratified$boundary_type[i], "\n")
}
}
# Force profile likelihood CIs for enhanced robustness
rd_profile <- calc_risk_diff(
data = cachar_sample,
outcome = "abnormal_screen",
exposure = "areca_nut",
boundary_method = "profile"
)
Run the code above in your browser using DataLab