inst/doc/Handling_of_NA_and_domains.md

Handling of NA and domains

Tobias Schoch – 31-01-2025

1 Intro

2 Basic robust estimators

2.1 Bare-bone functions (R/robsurvey-interal.R)

.check_data_weights(x, w, na.rm = FALSE, check_NA = TRUE), file: robsurvey-interal.R

2.2 Survey methods (R/robsurvey-interal.R)

.check_formula(f, design, na.rm = FALSE, check_NA = TRUE), file: robsurvey-interal.R

The prototype of a call (for the example svymean_trimmed(); unimportant code has been left away)

    dat <- .check_formula(x, design, na.rm)

Population- vs. domain-level estimate using the dat object

    res <- if (dat$domain)
        weighted_mean_trimmed(dat$y[dat$in_domain], dat$w[dat$in_domain], LB,
                              UB, info = TRUE, na.rm = FALSE)
    else
        weighted_mean_trimmed(dat$y, dat$w, LB, UB, info = TRUE, na.rm = FALSE)

Variance estimation

    # influence function
    infl <- .infl_trimmed(res$model$y, res$model$w, LB, UB, res$estimate) *
                res$model$w / sum(res$model$w)
    if (dat$domain) {
        tmp <- numeric(dat$n)
        tmp[dat$in_domain] <- infl
        infl <- tmp
    }
    # variance
    design <- dat$design
    res$variance <- svyrecvar(infl, design$cluster, design$strata, design$fpc,
                              postStrata = design$postStrata)

==ISSUE== With NA present in the data, infl is vector of length $\vert r\vert$ (response set), whereas all vectors of dat$design are of length $\vert s\vert$ (sample).

    # return
    res$estimator$domain <- dat$domain

3 Regression



tobiasschoch/robsurvey documentation built on June 1, 2025, 10:10 p.m.