This function calculates the Area Under the Curve (AUC) and its design-correct standard error and 95 the weighted ROC curve.
Value
If `plot = FALSE` (default), returns a `data.frame` with the AUC, SE, and 95 If `plot = TRUE`, invisibly returns a list containing the summary `data.frame` and another `data.frame` with the ROC curve coordinates (TPR and FPR).
Examples
if (FALSE) { # \dontrun{
# Ensure required packages are loaded
if (requireNamespace("survey", quietly = TRUE) &&
requireNamespace("NHANES", quietly = TRUE) &&
requireNamespace("dplyr", quietly = TRUE)) {
# 1. Prepare Data
data(NHANESraw, package = "NHANES")
nhanes_data <- NHANESraw %>%
dplyr::filter(Age >= 20) %>%
dplyr::mutate(ObeseStatus = factor(ifelse(BMI >= 30, "Obese", "Not Obese"),
levels = c("Not Obese", "Obese"))) %>%
dplyr::filter(complete.cases(ObeseStatus, Age, Gender, Race1,
WTMEC2YR, SDMVPSU, SDMVSTRA))
# 2. Create a replicate design object
std_design <- survey::svydesign(
ids = ~SDMVPSU,
strata = ~SDMVSTRA,
weights = ~WTMEC2YR,
nest = TRUE,
data = nhanes_data
)
rep_design <- survey::as.svrepdesign(std_design)
# 3. Fit a survey logistic regression model using the replicate design
fit_obesity_rep <- survey::svyglm(
ObeseStatus ~ Age + Gender + Race1,
design = rep_design,
family = quasibinomial()
)
# 4. Calculate the design-correct AUC
auc_results <- svyAUC(fit_obesity_rep, rep_design)
print(auc_results)
}
} # }