mk_stat: Estimate a statistic from a simple random sample design

Description Usage Arguments Value References Examples

View source: R/srs_functions.R

Description

Function to get point estimates and statistics associated with them. Given a point estimate (mean, total, prop), mk_stat will generate the

Usage

1
mk_stat(y, stat = "mean", N = NULL, fpc = TRUE, weights = NULL)

Arguments

y

A numeric vector with at least two elements

stat

A string, either "mean", "total", or "prop" (proportion)

N

The population size. This must be supplied and must be larger than length(y). If unknown, recommend passing it as some N > n with fpc=FALSE.

fpc

TRUE/FALSE. Whether or not to compute a finite population correction (for variance).

weights

Optional. If passed, it must be a vector of weights at least as long as the input y.

Value

tibble with

References

Lohr, Sharon L. Sampling: Design and Analysis. Chapman and Hall/CRC, 2019.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
N <- 10
n <- 5
y <- c(0, 0, 0, 1, 1)
weights <- rep(N/n, n)
mk_stat(y, stat="mean", N, fpc=TRUE, weights=weights)
# A tibble: 1 x 5
#      n point   var    se    cv
#  <int> <dbl> <dbl> <dbl> <dbl>
#1     5   0.4  0.15 0.387 0.968

N <- 10
n <- 5
y <- c(0, 0, 0, 1, 1)
weights <- rep(N/n, n)
mk_stat(y, stat="total", N, fpc=TRUE, weights=weights)
# A tibble: 1 x 5
#      n point   var    se    cv
#  <int> <dbl> <dbl> <dbl> <dbl>
#1     5     4    15  3.87 0.968

#' N <- 10
n <- 5
y <- c(0, 0, 0, 1, 1)
weights <- rep(N/n, n)
mk_stat(y, stat="prop", N, fpc=TRUE, weights=weights)
# A tibble: 1 x 5
#      n point   var    se    cv
#  <int> <dbl> <dbl> <dbl> <dbl>
#1     5   0.4  0.03 0.173 0.433

danjdrennan/surveyr documentation built on Dec. 19, 2021, 8:08 p.m.