calcPtEst: Calculate point estimates and errors

Description Usage Arguments Examples

Description

Calculates point estimates and errors using the package 'survey' based on sampling weights from a survey design

Usage

1
2
3
calcPtEst(df, var, use_weights = FALSE, by_var = NA, design = NA,
  psu_var = NA, strata_var = NA, weight_var = NA, na.rm = TRUE,
  ci_factor = 2)

Arguments

df

main data frame containing the raw data

var

string containing the variable name you want to average

use_weights

TRUE/FALSE for whether to apply a sampling frame or calculate a simple average.

by_var

(optional) string containing the variable name over which you want to calculate the estimates

design

(optional) svydesign object containing the sample frame

psu_var

(optional) if design isn't specified, string containing the primary sampling unit variable from the survey design (argument id in library('survey'))

strata_var

(optional) if design isn't specified, string containing the strata variable from the survey design (argument strata in library('survey')

weight_var

(optional)if design isn't specified, string containing the weights variable from the survey design (argument weights in library('survey')

na.rm

remove NAs from the mean or not

ci_factor

value to calculate confidence interval; in standard deviations. 1.96 standard deviations –> ~ 95 percent of the area under a normal gaussian distribution

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Generate simple random data to average
df = data.frame(region = rep(letters, 100), value = sample(100, 2600, replace = TRUE))

calcPtEst(df, 'value', by_var = 'region', use_weights = FALSE)

# generate data from a survey
data(api, package = 'survey')
dclus1 <- survey::svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc)
# no weights
calcPtEst(apiclus1, var = 'api99', by_var = 'stype', use_weights = FALSE)
# specifying the sampling frame as a design object
calcPtEst(apiclus1, var = 'api99', by_var = 'stype', design = dclus1, use_weights = TRUE)

flaneuse/svywrangler documentation built on May 24, 2019, 2:49 p.m.