unitVar {PracTools} | R Documentation |
Compute the unit (population) variance for a variable
Description
Compute the unit (population) variance for a variable based on either a full population file or a sample from a finite population.
Usage
unitVar(pop.sw = NULL, w = NULL, p = NULL, y = NULL)
Arguments
pop.sw |
TRUE if the full population is input; FALSE if a sample is input |
w |
vector of sample weights if |
p |
vector of 1-draw selection probabilities; optionally provided if |
y |
vector of values of an analysis variable; must be numeric |
Details
unitVar
computes unit (population) variances of an analysis variable from either a population or a sample.
S2
is the unweighted population variance, where
is the universe of elements,
is the population size, and
is the population mean. If the input is a sample,
S2
is estimated as where
is the set of sample elements,
is the sample size, and
is the weighted sample mean.
V1
is a weighted population variance used in calculations for samples where elements are selected with varying probabilities. If the is a population vector,
where
is the 1-draw probability for element
and
is the population total of
. If
is for a sample,
with
computed as
.
Value
A list with three or four components:
Note |
Describes whether output was computed from a full population or estimated from a sample. |
Pop size N |
Size of the population; included if |
S2 |
Unit variance of |
V1 |
Population variance of |
Author(s)
Richard Valliant
References
Valliant, R., Dever, J., Kreuter, F. (2018, chap. 3). Practical Tools for Designing and Weighting Survey Samples, 2nd edition. New York: Springer.
See Also
nCont
, nContMoe
, nContOpt
, nPPS
Examples
library(PracTools)
data("smho.N874")
y <- smho.N874[,"EXPTOTAL"]
x <- smho.N874[, "BEDS"]
y <- y[x>0]
x <- x[x>0]
pik <- x/sum(x)
require(sampling)
n <- 50
sam <- UPrandomsystematic(n * pik)
wts <- 1/(n*pik[sam==1])
unitVar(pop.sw = TRUE, w = NULL, p = pik, y=y)
unitVar(pop.sw = FALSE, w = wts, p = NULL, y=y[sam==1])