make_quad_form_matrix {svrep} | R Documentation |
Represent a variance estimator as a quadratic form
Description
Common variance estimators for estimated population totals can be represented as a quadratic form.
Given a choice of variance estimator and information about the sample design,
this function constructs the matrix of the quadratic form.
In notation, let
v(\hat{Y}) = \mathbf{\breve{y}}^{\prime}\mathbf{\Sigma}\mathbf{\breve{y}}
,
where \breve{y}
is the vector of weighted values, y_i/\pi_i, \space i=1,\dots,n
.
This function constructs the n \times n
matrix of the quadratic form, \mathbf{\Sigma}
.
Usage
make_quad_form_matrix(
variance_estimator = "Yates-Grundy",
probs = NULL,
joint_probs = NULL,
cluster_ids = NULL,
strata_ids = NULL,
strata_pop_sizes = NULL,
sort_order = NULL,
aux_vars = NULL
)
Arguments
variance_estimator |
The name of the variance estimator whose quadratic form matrix should be created. See the section "Variance Estimators" below. Options include:
|
probs |
Required if |
joint_probs |
Only used if |
cluster_ids |
Required unless |
strata_ids |
Required if |
strata_pop_sizes |
Required if |
sort_order |
Required if |
aux_vars |
Required if |
Value
The matrix of the quadratic form representing the variance estimator.
Variance Estimators
See variance-estimators for a description of each variance estimator.
Arguments required for each variance estimator
Below are the arguments that are required or optional for each variance estimator.
variance_estimator | probs | joint_probs | cluster_ids | strata_ids | strata_pop_sizes | sort_order | aux_vars |
Stratified Multistage SRS | Required | Required | Required | ||||
Ultimate Cluster | Required | Required | Optional | ||||
SD1 | Required | Optional | Optional | Required | |||
SD2 | Required | Optional | Optional | Required | |||
Deville-1 | Required | Required | Optional | ||||
Deville-2 | Required | Required | Optional | ||||
Deville-Tille | Required | Required | Optional | Required | |||
Yates-Grundy | Required | ||||||
Horvitz-Thompson | Required | ||||||
See Also
See variance-estimators for a description of each variance estimator.
For a two-phase design, the function make_twophase_quad_form combines the quadratic form matrix from each phase.
Examples
## Not run:
# Example 1: The Horvitz-Thompson Estimator
library(survey)
data("election", package = "survey")
ht_quad_form_matrix <- make_quad_form_matrix(variance_estimator = "Horvitz-Thompson",
joint_probs = election_jointprob)
##_ Produce variance estimate
wtd_y <- as.matrix(election_pps$wt * election_pps$Bush)
t(wtd_y) %*% ht_quad_form_matrix %*% wtd_y
##_ Compare against result from 'survey' package
svytotal(x = ~ Bush,
design = svydesign(data=election_pps,
variance = "HT",
pps = ppsmat(election_jointprob),
ids = ~ 1, fpc = ~ p)) |> vcov()
# Example 2: Stratified multistage Sample ----
data("mu284", package = 'survey')
multistage_srswor_design <- svydesign(data = mu284,
ids = ~ id1 + id2,
fpc = ~ n1 + n2)
multistage_srs_quad_form <- make_quad_form_matrix(
variance_estimator = "Stratified Multistage SRS",
cluster_ids = mu284[,c('id1', 'id2')],
strata_ids = matrix(1, nrow = nrow(mu284), ncol = 2),
strata_pop_sizes = mu284[,c('n1', 'n2')]
)
wtd_y <- as.matrix(weights(multistage_srswor_design) * mu284$y1)
t(wtd_y) %*% multistage_srs_quad_form %*% wtd_y
##_ Compare against result from 'survey' package
svytotal(x = ~ y1, design = multistage_srswor_design) |> vcov()
# Example 3: Successive-differences estimator ----
data('library_stsys_sample', package = 'svrep')
sd1_quad_form <- make_quad_form_matrix(
variance_estimator = 'SD1',
cluster_ids = library_stsys_sample[,'FSCSKEY',drop=FALSE],
strata_ids = library_stsys_sample[,'SAMPLING_STRATUM',drop=FALSE],
strata_pop_sizes = library_stsys_sample[,'STRATUM_POP_SIZE',drop=FALSE],
sort_order = library_stsys_sample[['SAMPLING_SORT_ORDER']]
)
wtd_y <- as.matrix(library_stsys_sample[['TOTCIR']] /
library_stsys_sample$SAMPLING_PROB)
wtd_y[is.na(wtd_y)] <- 0
t(wtd_y) %*% sd1_quad_form %*% wtd_y
# Example 4: Deville estimators ----
data('library_multistage_sample', package = 'svrep')
deville_quad_form <- make_quad_form_matrix(
variance_estimator = 'Deville-1',
cluster_ids = library_multistage_sample[,c("PSU_ID", "SSU_ID")],
strata_ids = cbind(rep(1, times = nrow(library_multistage_sample)),
library_multistage_sample$PSU_ID),
probs = library_multistage_sample[,c("PSU_SAMPLING_PROB",
"SSU_SAMPLING_PROB")]
)
## End(Not run)