Computes pseudo-weighted means and standard errors using a fitted
pseudo-weight object of class "pw_fit" returned by
est_pw. The function applies second-layer missing-data
handling for the outcome and optional domain variable, and then estimates
overall or domain-specific means or prevalences using the pseudo-weighting
method stored in object.
Usage
pwmean(object, y, zcol = NULL, na.action = stats::na.omit)Arguments
- object
An object of class
"pw_fit"returned byest_pw.- y
A character string specifying the name of the outcome variable in the nonprobability sample stored in
object. The outcome must be numeric for mean estimation, including binary 0/1 outcomes for prevalence estimation, or a factor for category prevalence estimation.- zcol
Optional character string giving the name of a categorical domain variable in the nonprobability sample stored in the
object. IfNULL, the overall mean is estimated. If supplied, estimates are computed within domains defined by this variable. The following column types are supported:logical(must contain bothTRUEandFALSE);numericorintegercontaining only0and1after removing missing values;character(empty strings are treated as missing values); andfactor(unused levels are dropped).- na.action
Function specifying how missing values in
yandzcolshould be handled. Default isstats::na.omit.
Value
An object of class "pwmean" containing unweighted and pseudo-weighted
estimates, standard errors, and confidence intervals. For categorical outcomes,
the estimate columns contain category prevalences.
methodCharacter. The pseudo-weighting method used.
estimatesA data frame containing the unweighted and pseudo-weighted estimates.
For numeric outcomes, the first column is
domain. Ifzcol = NULL,domainis"Overall". Ifzcolis alogicalvariable or anumeric/integervariable containing only0and1, there is one row withdomainlabeled"<zcol> = 1". Ifzcolis afactororcharactervariable, there is one row perzcollevel, withdomainlabeled"<zcol> = <level>".For categorical outcomes, the first two columns are
categoryanddomain.categoryidentifies the outcome level as"<y> = <level>". Ifzcol = NULL,domainis"Overall"for each outcome level. Ifzcolis supplied, the rows are formed by each outcome category within each domain, anddomainfollows the same labels described above forzcol.The columns are:
categoryCategory label for categorical outcomes only.
domainDomain label.
unweighted_mean,unweighted_seUnweighted mean of
yand its standard error.unweighted_lower,unweighted_upperBounds of the 95% confidence interval for the unweighted mean, based on the normal approximation.
adjusted_mean,adjusted_sePseudo-weighted mean of
yand its standard error.adjusted_lower,adjusted_upperBounds of the 95% confidence interval for the pseudo-weighted mean, based on the normal approximation.
na.actionInteger vector of row indices omitted at the outcome-estimation step, with class
"omit"or"exclude"matching thena.actionargument, orNULLif no observations were omitted. The indices refer to the nonprobability sample available topwmean()after missing-data handling inest_pw().callThe matched function call.
Details
Missing data handling (layer 2).
After pseudo-weights are constructed by est_pw(), estimation of the
mean requires complete cases for the outcome y and, if supplied, the
domain variable zcol. The argument na.action controls how
these missing values are handled at the outcome-estimation step.
Input object.
The object argument should be an object of class "pw_fit"
returned by est_pw. It stores the estimated pseudo-weights,
participation model information, and design-based quantities required for point
and variance estimation.
Categorical outcomes.
When y is a categorical variable (defined as a factor in R),
pwmean() estimates the prevalence (proportion) of each category.
To do so, each category is internally converted into a 0/1 indicator
variable, and the pseudo-weighted mean estimator is then computed for each
indicator.
Examples
# \donttest{
data(sc)
data(sp1)
ref1_design <- survey::svydesign(
ids = ~psu_sp1,
strata = ~strata_sp1,
weights = ~wts_sp1,
data = sp1,
nest = TRUE
)
fit <- est_pw(
data = list(sc, ref1_design),
p_formula = ~ agecat + race + education + comorbidity + BMI + diabetes,
method = "calibration",
control = pw_solver_control(ftol=1e-6)
)
out <- pwmean(fit, y = "psa_level", zcol = "BMI")
print(out)
#>
#> Pseudo-weighted (calibration) Estimators:
#> Domain: BMI = Morbidly Obese
#> Mean: 1.732436
#> Std. Error: 0.140720
#> 95% CI: [1.456629, 2.008243]
#>
#> Domain: BMI = Normal
#> Mean: 1.728680
#> Std. Error: 0.083032
#> 95% CI: [1.565940, 1.891420]
#>
#> Domain: BMI = Obese
#> Mean: 1.362181
#> Std. Error: 0.057429
#> 95% CI: [1.249623, 1.474740]
#>
#> Domain: BMI = Overweight
#> Mean: 1.491525
#> Std. Error: 0.049834
#> 95% CI: [1.393851, 1.589199]
summary(out)
#> Call:
#> pwmean(object = fit, y = "psa_level", zcol = "BMI")
#>
#> Method: One reference calibration
#>
#> Unweighted estimators:
#> domain mean se CI_lower CI_upper
#> BMI = Morbidly Obese 1.673128 0.12901739 1.420259 1.925998
#> BMI = Normal 1.692864 0.08216978 1.531814 1.853914
#> BMI = Obese 1.360960 0.05707777 1.249089 1.472830
#> BMI = Overweight 1.513487 0.05114169 1.413251 1.613723
#>
#> Pseudo-weighted (calibration) estimators:
#> domain mean se CI_lower CI_upper
#> BMI = Morbidly Obese 1.732436 0.14072032 1.456629 2.008243
#> BMI = Normal 1.728680 0.08303227 1.565940 1.891420
#> BMI = Obese 1.362181 0.05742881 1.249623 1.474740
#> BMI = Overweight 1.491525 0.04983443 1.393851 1.589199
# }