stratamean: Stratified Sample Mean Estimation

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/stratamean.R

Description

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

Usage

1
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

Author(s)

Shuai Shao and Juliane Manitz

References

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

See Also

Smean, Sprop

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# random data
testy <- rnorm(100)
testh <- c(rep("male",40), rep("female",60))
stratamean(testy, testh, wh=c(0.5, 0.5))
stratamean(testy, testh, wh=c(0.5, 0.5), eae=TRUE)

# tax data
data(tax)
summary(tax)

nh <- as.vector(table(tax$Class))
wh <- nh/sum(nh)
stratamean(y=tax$diff, h=as.vector(tax$Class), wh=wh, eae=TRUE)

Example output

Loading required package: pps
Loading required package: sampling
Loading required package: survey
Loading required package: grid
Loading required package: Matrix
Loading required package: survival

Attaching package: 'survival'

The following objects are masked from 'package:sampling':

    cluster, strata


Attaching package: 'survey'

The following object is masked from 'package:graphics':

    dotchart


stratamean object: Stratified sample mean estimate
Without finite population correction.
Mean estimate: 0.0384
Standard error: 0.1071
95% confidence interval: [-0.1714,0.2483]

               Mean        SE        CIu       CIo
female  -0.06961238 0.1262084 -0.3169764 0.1777516
male     0.14651084 0.1730072 -0.1925771 0.4855987
overall  0.03844923 0.1070748 -0.1714136 0.2483120
       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.07   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  
                   
                   
                   
               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

samplingbook documentation built on April 3, 2021, 1:06 a.m.