postStrat: Compute a post-stratified estimator

View source: R/postStrat.R

postStratR Documentation

Compute a post-stratified estimator

Description

Calculates a post-stratified estimator for a finite population mean/proportion or total based on sample data collected from a complex sampling design and a single, categorical auxiliary population variable.

Usage

postStrat(
  y,
  xsample,
  xpop,
  pi = NULL,
  N = NULL,
  var_est = FALSE,
  var_method = "LinHB",
  pi2 = NULL,
  datatype = "raw",
  B = 1000,
  fpc = TRUE,
  messages = TRUE
)

Arguments

y

A numeric vector of the sampled response variable.

xsample

A vector containing the post-stratum for each sampled unit.

xpop

A vector or data frame, depending on datatype. If datatype = "raw", then a vector containing the post-stratum for each population unit. If datatype = "totals" or "means", then a data frame, where the first column lists the possible post-strata and the second column contains the population total or proportion in each post-stratum.

pi

A numeric vector of inclusion probabilities for each sampled unit in y. If NULL, then simple random sampling without replacement is assumed.

N

A numeric value of the population size. If NULL, it is estimated with the sum of the inverse of the pis.

var_est

Default to FALSE, logical for whether or not to compute estimate of variance

var_method

The method to use when computing the variance estimator. Options are a Taylor linearized technique: "LinHB"= Hajek-Berger estimator, "LinHH" = Hansen-Hurwitz estimator, "LinHTSRS" = Horvitz-Thompson estimator under simple random sampling without replacement, and "LinHT" = Horvitz-Thompson estimator or a resampling technique: "bootstrapSRS" = bootstrap variance estimator under simple random sampling without replacement, "SRSunconditional" = simple random sampling variance estimator which accounts for random strata.

pi2

A square matrix of the joint inclusion probabilities. Needed for the "LinHT" variance estimator.

datatype

Default to "raw", takes values "raw", "totals" or "means" for whether the user is providing the raw population stratum memberships, the population totals of each stratum, or the population proportions of each stratum.

B

The number of bootstrap samples if computing the bootstrap variance estimator. Default is 1000.

fpc

Default to TRUE, logical for whether or not the variance calculation should include a finite population correction when calculating the "LinHTSRS", "SRSunconditional", or the "SRSbootstrap" variance estimator.

messages

A logical indicating whether to output the messages internal to mase. Default is TRUE.

Value

A list of output containing:

* pop_total: Estimate of population total.

* pop_mean: Estimate of the population mean (or proportion).

* pop_total_var: Estimated variance of population total estimate.

* pop_mean_var: Estimated variance of population mean estimate.

* strat_ests: Table of total and mean estimates for each strata.

* weights: Survey weights produced by PS.

References

\insertRef

coc77mase

\insertRef

sar92mase

Examples

library(tidyr)
library(dplyr)

data(IdahoPop)
data(IdahoSamp)

xsample <- filter(IdahoSamp, COUNTYFIPS == "16055")
xpop <- filter(IdahoPop, COUNTYFIPS == "16055")

pop <- xpop[c("tnt.1", "tnt.2")] |> 
    pivot_longer(everything(), names_to = "tnt", values_to = "prop") |>
    mutate(tnt = as.numeric(gsub("\\D", "", tnt)))
    
postStrat(y = xsample$BA_TPA_ADJ,
          N = xpop$npixels,
          xsample = xsample$tnt,
          xpop = pop,
          datatype = "means",
          var_est = TRUE,
          var_method = "SRSunconditional")
          

Swarthmore-Statistics/mase documentation built on March 5, 2024, 6:16 a.m.