sampling_distribution: Compute a sampling distribution from a small population

Description Usage Arguments Value Examples

View source: R/sampling_distribution.R

Description

Composes draw_samples to compute the sampling distribution of an estimator given a population, sample size, and statistic. The population must be a vector of numeric variables. The statistic must be the sample mean, sample total, or sample proportion. The function must store the entire sample as a matrix at some point, so it is bound on what samples can taken by choose(N, n).

Usage

1
sampling_distribution(y, n, stat = "mean")

Arguments

y

A numeric vector of measurements on observations units. The population, N, will be computed as the length of y.

n

The size of samples to draw from y.

stat

A point estimate ("mean", "total", or "prop") to estimate from the population. Must be a string input.

Value

The sampling distribution of the sample mean

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
y <- c(1, 1, 2, 2, 3, 3)
n <- 2
sampling_distribution(y, n, stat="mean")
# [1] 1.0 1.5 1.5 2.0 2.0 1.5 1.5 2.0 2.0 2.0 2.5 2.5 2.5 2.5 3.0

y <- c(1, 1, 2, 2, 3, 3)
n <- 2
sampling_distribution(y, n, stat="total")
# [1]  6  9  9 12 12  9  9 12 12 12 15 15 15 15 18

y <- c(0,0,0,0,1,1)
n <- 2
sampling_distribution(y, n, stat="prop")
# [1] 0.0 0.0 0.0 0.5 0.5 0.0 0.0 0.5 0.5 0.0 0.5 0.5 0.5 0.5 1.0

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