wtd.moments {PracTools} | R Documentation |
Compute moments of a variable from either a population or sample
Description
Compute the 2nd, 3rd, 4th moments, skewness, and kurtosis of a variable from either population or sample input
Usage
wtd.moments(y, w=NULL, pop.sw=TRUE)
Arguments
y |
variable to be analyzed |
w |
vector of weights if the input is a sample |
pop.sw |
is the input for a population ( |
Details
The population moment is defined as
where U is the set of population units, N is the population size, and
is the population mean. When the input is for the whole population,
wtd.moments
evaluates this directly for . When the input is for a sample, the
moment is estimated as
where
is the set of sample units,
is the weight for sample unit
,
, and
. When
,
so that the estimator equals the unbiased variance estimator if the sample is a simple random sample; if
, then
. The function also computes or estimates the population skewness, defined as
and the population kurtosis,
.
The weights should be scaled for estimating population totals. The sample can be obtained from any complex design.
Value
Vector with values:
m2 |
2nd moment |
m3 |
3rd moment |
m4 |
4th moment |
skewness |
skewness |
kurtosis |
kurtosis |
Author(s)
Richard Valliant, Jill A. Dever, Frauke Kreuter
References
Valliant, R., Dever, J., Kreuter, F. (2018, sect. 3.4). Practical Tools for Designing and Weighting Survey Samples, 2nd edition. New York: Springer.
See Also
Examples
require(PracTools)
wtd.moments(y = hospital$y, w = NULL)
require(sampling)
sam <- strata(data = labor, stratanames = "h", size = c(30, 20, 10), method = c("srswor"),
description=TRUE)
samdat <- labor[sam$ID_unit,]
wtd.moments(y = samdat$WklyWage, w = 1/sam$Prob, pop.sw=FALSE)