The function stratamean estimates the population mean out of stratified samples either with or without consideration of finite population correction.

stratamean(y, h, Nh, wh, level = 0.95, eae = FALSE)

Arguments

y

vector of target variable.

h

vector of stratifying variable.

Nh

vector of sizes of every stratum, which has to be supplied in alphabetical or numerical order of the categories of h.

wh

vector of weights of every stratum, which has to be supplied in alphabetical or numerical order of the categories of h.

level

coverage probability for confidence intervals. Default is level=0.95.

eae

TRUE for extensive output with the result in each and every stratum. Default is eae=FALSE.

Details

If the absolute stratum sizes Nh are given, the variances are calculated with finite population correction. Otherwise, if the stratum weights wh are given, the variances are calculated without finite population correction.

Value

The function stratamean returns a value, which is a list consisting of the components

call

is a list of call components: y target variable in sample data, h stratifying variable in sample data, Nh sizes of every stratum, wh weights of every stratum, fpc finite population correction, level coverage probability for confidence intervals

mean

mean estimate for population

se

standard error of the mean estimate for population

ci

vector of confidence interval boundaries for population

References

Kauermann, Goeran/Kuechenhoff, Helmut (2010): Stichproben. Methoden und praktische Umsetzung mit R. Springer.

Author

Shuai Shao and Juliane Manitz

See also

Examples

# random data testy <- rnorm(100) testh <- c(rep("male",40), rep("female",60)) stratamean(testy, testh, wh=c(0.5, 0.5))
#> #> stratamean object: Stratified sample mean estimate #> Without finite population correction. #> Mean estimate: -0.0212 #> Standard error: 0.0992 #> 95% confidence interval: [-0.2157,0.1732] #>
stratamean(testy, testh, wh=c(0.5, 0.5), eae=TRUE)
#> Mean SE CIu CIo #> female -0.033409733 0.12415553 -0.2767501 0.2099306 #> male -0.009039405 0.15477062 -0.3123842 0.2943054 #> overall -0.021224569 0.09920753 -0.2156678 0.1732186
# tax data data(tax) summary(tax)
#> id estRefund actRefund diff #> Min. : 1 Min. : 0.27 Min. : 0.00 Min. : 0.0 #> 1st Qu.:2272 1st Qu.: 124.77 1st Qu.: 76.31 1st Qu.: 0.0 #> Median :4542 Median : 543.23 Median : 378.08 Median : 0.0 #> Mean :4542 Mean : 3842.28 Mean : 3227.43 Mean : 614.9 #> 3rd Qu.:6812 3rd Qu.: 2246.06 3rd Qu.: 1756.24 3rd Qu.: 0.0 #> Max. :9083 Max. :200504.35 Max. :178104.99 Max. :129520.4 #> Class #> Length:9083 #> Class :character #> Mode :character #> #> #>
nh <- as.vector(table(tax$Class)) wh <- nh/sum(nh) stratamean(y=tax$diff, h=as.vector(tax$Class), wh=wh, eae=TRUE)
#> Mean SE CIu CIo #> 1 40.36435 1.623603 37.18214 43.54655 #> 2 480.43275 24.026405 433.34186 527.52364 #> 3 3840.83780 312.559990 3228.23147 4453.44412 #> 4 11161.88331 2216.524710 6817.57471 15506.19191 #> overall 614.85125 40.010241 536.43262 693.26988