postStr_wt {AuxSurvey} | R Documentation |
Weighted or Unweighted Post-Stratification Estimator
Description
This function performs post-stratification adjustment for survey data, which adjusts the sample weights to match the marginal distributions of auxiliary variables in the population. It supports both weighted and unweighted estimations for various outcome variables, including Gaussian (continuous) and Binomial (binary) outcomes. The function computes estimates and confidence intervals (CIs) for the outcome variable using post-stratification based on the specified auxiliary variables.
Usage
postStr_wt(
svysmpl,
svypopu,
auxVars,
svyVar,
subset = NULL,
family = gaussian(),
invlvls,
weights = NULL
)
Arguments
svysmpl |
A dataframe or tibble representing the sample data ( |
svypopu |
A dataframe or tibble representing the population data ( |
auxVars |
A character vector containing the names of auxiliary variables to be used for post-stratification. These variables will be used to adjust the weights. |
svyVar |
The outcome variable for which the post-stratification estimate is calculated. |
subset |
A character vector representing filtering conditions to select subsets of the sample and population.
Default is |
family |
The distribution family of the outcome variable. Supported options are:
|
invlvls |
A numeric vector specifying the confidence levels for the post-stratification estimators. If more than one value is provided, multiple CIs will be calculated. |
weights |
A numeric vector of case weights. The length should match the number of cases in |
Value
A list where each element contains the post-stratification estimate and confidence intervals (CIs) for a subset or the entire
dataset. The list includes:
- est
: The post-stratification estimate for the outcome variable.
- se
: The standard error of the estimate.
- tCI
: The confidence intervals for the estimate.
- sample_size
: The sample size for the subset or entire dataset.
- population_size
: The population size, if provided, including the finite population correction (FPC).
Examples
## Simulate data with nonlinear association (setting 3).
data = simulate(N = 3000, discretize = 3, setting = 3, seed = 123)
population = data$population # Population data (3000 cases)
samples = data$samples # Sample data (600 cases)
ipw = 1 / samples$true_pi # Compute inverse probability weights
## Perform weighted post-stratification with auxiliary variables
auxVars = c("Z1", "Z2", "Z3")
Weighted_postStratify = postStr_wt(svysmpl = samples, svypopu = population, auxVars = auxVars,
svyVar = "Y1", subset = NULL, family = gaussian(),
invlvls = c(0.95), weights = ipw)
Weighted_postStratify
## Perform unweighted post-stratification
Unweighted_postStratify = postStr_wt(svysmpl = samples, svypopu = population, auxVars = auxVars,
svyVar = "Y1", subset = NULL, family = gaussian(),
invlvls = c(0.95), weights = NULL)
Unweighted_postStratify