direct: Direct estimators.

Description Usage Arguments Value References See Also Examples

View source: R/direct.R

Description

This function calculates direct estimators of domain means.

Usage

1
direct(y, dom, sweight, domsize, data, replace = FALSE)

Arguments

y

vector specifying the individual values of the variable for which we want to estimate the domain means.

dom

vector or factor (same size as y) with domain codes.

sweight

optional vector (same size as y) with sampling weights. When this argument is not included, by default estimators are obtained under simple random sampling (SRS).

domsize

D*2 data frame with domain codes in the first column and the corresponding domain population sizes in the second column. This argument is not required when sweight is not included and replace=TRUE (SRS with replacement).

data

optional data frame containing the variables named in y, dom and sweight. By default the variables are taken from the environment from which direct is called.

replace

logical variable with default value FALSE for random sampling without replacement within each domain is considered and TRUE for random sampling with replacement within each domain.

Value

The function returns a data frame of size D*5 with the following columns:

Domain

domain codes in ascending order.

SampSize

domain sample sizes.

Direct

direct estimators of domain means of variable y.

SD

estimated standard deviations of domain direct estimators. If sampling design is SRS or Poisson sampling, estimated variances are unbiased. Otherwise, estimated variances are obtained under the approximation that second order inclusion probabilities are the product of first order inclusion probabilities.

CV

absolute value of percent coefficients of variation of domain direct estimators.

Cases with NA values in y, dom or sweight are ignored.

References

- Cochran, W.G. (1977). Sampling techniques. Wiley, New York.

- Rao, J.N.K. (2003). Small Area Estimation. Wiley, London.

- Sarndal, C.E., Swensson, B. and Wretman, J. (1992). Model Assisted Survey Sampling. Springer-Verlag.

See Also

pssynt for post-stratified synthetic estimator, ssd for sample size dependent estimator.

In case that the sampling design is known, see packages survey or sampling for more exact variance estimation.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Load data set with synthetic income data for provinces (domains)
data(incomedata)

# Load population sizes of provinces
data(sizeprov)   

# Compute Horvitz-Thompson direct estimator of mean income for each 
# province under random sampling without replacement within each province.
result1 <- direct(y=income, dom=prov, sweight=weight,
                   domsize=sizeprov[,2:3], data=incomedata)
result1

# The same but using province labels as domain codes
result2 <- direct(y=incomedata$income, dom=incomedata$provlab,
                  sweight=incomedata$weight, domsize=sizeprov[,c(1,3)])
result2

# The same, under SRS without replacement within each province.
result3 <- direct(y=income ,dom=provlab, domsize=sizeprov[,c(1,3)],
                  data=incomedata)
result3

# Compute direct estimator of mean income for each province
# under SRS with replacement within each province
result4 <- direct(y=income, dom=provlab, data=incomedata, replace=TRUE)
result4

Example output

Loading required package: MASS
Loading required package: lme4
Loading required package: Matrix
   Domain SampSize    Direct        SD        CV
1       1       96  7121.005  978.9280 13.747049
2       2      173 13091.669 1380.7139 10.546508
3       3      539 13054.001  697.0416  5.339678
4       4      198 13158.890 1242.0200  9.438638
5       5       58 10592.494 1802.3255 17.015120
6       6      494 13213.102  759.5069  5.748134
7       7      634 14240.291  780.7269  5.482521
8       8     1420 11391.583  387.3791  3.400573
9       9      168 17193.316 1941.0206 11.289391
10     10      282  9173.640  781.1630  8.515301
11     11      398 16590.280 1047.6163  6.314639
12     12      118  7922.602  890.4710 11.239629
13     13      250 13014.733 1069.4094  8.216914
14     14      224  9238.661  756.3274  8.186549
15     15      495 10664.224  640.1909  6.003164
16     16       92  9726.538 1278.6810 13.146311
17     17      142  9631.635 1001.6669 10.399760
18     18      208  9492.997  869.7582  9.162103
19     19       89 10197.979 1532.7710 15.030146
20     20      285 11665.247  942.8695  8.082722
21     21      122 13287.910 1524.2953 11.471295
22     22      115  9105.395 1136.5260 12.481897
23     23      232 12730.452 1085.3034  8.525254
24     24      218  9819.389  873.2891  8.893518
25     25      130 15563.262 2058.6055 13.227339
26     26      510 11836.719  780.5658  6.594444
27     27      173  9444.694  941.5500  9.969090
28     28      944 13057.341  605.1017  4.634187
29     29      379 11662.044  802.1492  6.878290
30     30      885 13259.506  638.0530  4.812042
31     31      564 13735.008  783.8567  5.706999
32     32      129  8942.922 1320.8213 14.769460
33     33      803 11221.799  591.8854  5.274425
34     34       72  9189.167 1385.4011 15.076460
35     35      472 16529.191 1080.7667  6.538534
36     36      448 15337.141  919.5169  5.995361
37     37      164 12020.292 1328.1631 11.049342
38     38      381  9092.715  611.0477  6.720190
39     39      434  9731.450  704.8761  7.243279
40     40       58  8994.437 1470.5287 16.349313
41     41      482 11117.879  617.7463  5.556332
42     42       20  6597.581 1753.4391 26.577001
43     43      134  6204.736  681.4471 10.982694
44     44       72  9677.507 1855.1802 19.170022
45     45      275 14107.708 1136.2947  8.054424
46     46      714 11643.482  553.7125  4.755557
47     47      299 16833.008 1206.8993  7.169837
48     48      524 12607.676  723.4707  5.738336
49     49      104 11360.706 1432.0437 12.605235
50     50      564 15454.577  883.0556  5.713878
51     51      235 14501.279 1307.0182  9.013124
52     52      180 11661.446 1370.2542 11.750295
        Domain SampSize    Direct        SD        CV
1        Alava       96  7121.005  978.9280 13.747049
2     Albacete      173 13091.669 1380.7139 10.546508
3     Alicante      539 13054.001  697.0416  5.339678
4      Almeria      198 13158.890 1242.0200  9.438638
5        Avila       58 10592.494 1802.3255 17.015120
6      Badajoz      494 13213.102  759.5069  5.748134
7     Baleares      634 14240.291  780.7269  5.482521
8    Barcelona     1420 11391.583  387.3791  3.400573
9       Burgos      168 17193.316 1941.0206 11.289391
10     Caceres      282  9173.640  781.1630  8.515301
11       Cadiz      398 16590.280 1047.6163  6.314639
12   Castellon      118  7922.602  890.4710 11.239629
51       Ceuta      235 14501.279 1307.0182  9.013124
13  CiudadReal      250 13014.733 1069.4094  8.216914
14     Cordoba      224  9238.661  756.3274  8.186549
15    CorunaLa      495 10664.224  640.1909  6.003164
16      Cuenca       92  9726.538 1278.6810 13.146311
17      Gerona      142  9631.635 1001.6669 10.399760
18     Granada      208  9492.997  869.7582  9.162103
19 Guadalajara       89 10197.979 1532.7710 15.030146
20   Guipuzcoa      285 11665.247  942.8695  8.082722
21      Huelva      122 13287.910 1524.2953 11.471295
22      Huesca      115  9105.395 1136.5260 12.481897
23        Jaen      232 12730.452 1085.3034  8.525254
24        Leon      218  9819.389  873.2891  8.893518
25      Lerida      130 15563.262 2058.6055 13.227339
27        Lugo      173  9444.694  941.5500  9.969090
28      Madrid      944 13057.341  605.1017  4.634187
29      Malaga      379 11662.044  802.1492  6.878290
52     Melilla      180 11661.446 1370.2542 11.750295
30      Murcia      885 13259.506  638.0530  4.812042
31     Navarra      564 13735.008  783.8567  5.706999
32      Orense      129  8942.922 1320.8213 14.769460
33      Oviedo      803 11221.799  591.8854  5.274425
34    Palencia       72  9189.167 1385.4011 15.076460
35   PalmasLas      472 16529.191 1080.7667  6.538534
36  Pontevedra      448 15337.141  919.5169  5.995361
26     RiojaLa      510 11836.719  780.5658  6.594444
37   Salamanca      164 12020.292 1328.1631 11.049342
39   Santander      434  9731.450  704.8761  7.243279
40     Segovia       58  8994.437 1470.5287 16.349313
41     Sevilla      482 11117.879  617.7463  5.556332
42       Soria       20  6597.581 1753.4391 26.577001
43   Tarragona      134  6204.736  681.4471 10.982694
38    Tenerife      381  9092.715  611.0477  6.720190
44      Teruel       72  9677.507 1855.1802 19.170022
45      Toledo      275 14107.708 1136.2947  8.054424
46    Valencia      714 11643.482  553.7125  4.755557
47  Valladolid      299 16833.008 1206.8993  7.169837
48     Vizcaya      524 12607.676  723.4707  5.738336
49      Zamora      104 11360.706 1432.0437 12.605235
50    Zaragoza      564 15454.577  883.0556  5.713878
        Domain SampSize    Direct        SD       CV
1        Alava       96 10105.287  702.3915 6.950732
2     Albacete      173 13265.970  539.9709 4.070346
3     Alicante      539 12179.521  313.9160 2.577409
4      Almeria      198 12059.517  529.6645 4.392088
5        Avila       58 14019.712  963.9689 6.875811
6      Badajoz      494 12511.970  321.8370 2.572233
7     Baleares      634 14882.657  305.4036 2.052077
8    Barcelona     1420 10807.535  177.9112 1.646178
9       Burgos      168 13186.984  608.5386 4.614691
10     Caceres      282  9896.033  354.1848 3.579059
11       Cadiz      398 14529.255  407.9764 2.807965
12   Castellon      118 10823.324  529.4779 4.892009
51       Ceuta      235 12969.666  492.9915 3.801111
13  CiudadReal      250 12674.666  476.8651 3.762348
14     Cordoba      224 10066.604  388.0481 3.854807
15    CorunaLa      495 11127.150  301.6030 2.710514
16      Cuenca       92 11617.417  726.9723 6.257607
17      Gerona      142 11499.240  490.8290 4.268360
18     Granada      208 10351.829  480.7398 4.644008
19 Guadalajara       89 11779.328  718.5038 6.099701
20   Guipuzcoa      285 11579.721  412.5300 3.562521
21      Huelva      122 14799.152  740.0982 5.000950
22      Huesca      115 10636.029  589.6462 5.543856
23        Jaen      232 11180.785  463.7766 4.147979
24        Leon      218 10760.151  387.5303 3.601532
25      Lerida      130 13651.307  702.5331 5.146270
27        Lugo      173  9711.226  408.5270 4.206750
28      Madrid      944 13082.632  250.4293 1.914212
29      Malaga      379 11864.375  364.1834 3.069554
52     Melilla      180 12336.983  546.3280 4.428376
30      Murcia      885 13051.420  251.9265 1.930261
31     Navarra      564 13747.753  353.4242 2.570778
32      Orense      129 10705.264  640.9692 5.987421
33      Oviedo      803 11022.379  240.5450 2.182333
34    Palencia       72 11074.678  713.4901 6.442536
35   PalmasLas      472 14373.607  382.8277 2.663407
36  Pontevedra      448 14104.526  383.2660 2.717326
26     RiojaLa      510 11501.371  322.5749 2.804665
37   Salamanca      164 13143.700  657.6108 5.003239
39   Santander      434  9587.014  310.8231 3.242126
40     Segovia       58 10528.493  817.9002 7.768445
41     Sevilla      482 11751.782  290.6764 2.473466
42       Soria       20 13250.332 1150.4417 8.682361
43   Tarragona      134  8500.723  462.8108 5.444370
38    Tenerife      381 11426.812  333.3318 2.917102
44      Teruel       72 10639.357  937.4045 8.810725
45      Toledo      275 13885.110  457.9127 3.297869
46    Valencia      714 11812.881  255.4532 2.162497
47  Valladolid      299 13652.277  431.5035 3.160671
48     Vizcaya      524 12098.812  321.0908 2.653904
49      Zamora      104 10996.844  649.9185 5.910046
50    Zaragoza      564 14940.941  336.9009 2.254884
        Domain SampSize    Direct        SD       CV
1        Alava       96 10105.287  702.5052 6.951858
2     Albacete      173 13265.970  540.0934 4.071270
3     Alicante      539 12179.521  313.9653 2.577813
4      Almeria      198 12059.517  529.7494 4.392791
5        Avila       58 14019.712  964.1403 6.877034
6      Badajoz      494 12511.970  321.9575 2.573196
7     Baleares      634 14882.657  305.5020 2.052738
8    Barcelona     1420 10807.535  177.9358 1.646405
9       Burgos      168 13186.984  608.6834 4.615789
10     Caceres      282  9896.033  354.3085 3.580308
11       Cadiz      398 14529.255  408.0460 2.808444
12   Castellon      118 10823.324  529.5355 4.892541
51       Ceuta      235 12969.666  493.8096 3.807419
13  CiudadReal      250 12674.666  476.9855 3.763298
14     Cordoba      224 10066.604  388.1045 3.855366
15    CorunaLa      495 11127.150  301.6704 2.711120
16      Cuenca       92 11617.417  727.1344 6.259002
17      Gerona      142 11499.240  490.8820 4.268821
18     Granada      208 10351.829  480.7975 4.644566
19 Guadalajara       89 11779.328  718.6593 6.101021
20   Guipuzcoa      285 11579.721  412.6168 3.563270
21      Huelva      122 14799.152  740.1922 5.001585
22      Huesca      115 10636.029  589.8053 5.545352
23        Jaen      232 11180.785  463.8598 4.148723
24        Leon      218 10760.151  387.6185 3.602352
25      Lerida      130 13651.307  702.6477 5.147109
27        Lugo      173  9711.226  408.6289 4.207800
28      Madrid      944 13082.632  250.4493 1.914365
29      Malaga      379 11864.375  364.2313 3.069957
52     Melilla      180 12336.983  547.0822 4.434489
30      Murcia      885 13051.420  252.0101 1.930902
31     Navarra      564 13747.753  353.5958 2.572026
32      Orense      129 10705.264  641.0954 5.988600
33      Oviedo      803 11022.379  240.6369 2.183167
34    Palencia       72 11074.678  713.6430 6.443916
35   PalmasLas      472 14373.607  382.9173 2.664031
36  Pontevedra      448 14104.526  383.3590 2.717986
26     RiojaLa      510 11501.371  322.8506 2.807062
37   Salamanca      164 13143.700  657.7684 5.004439
39   Santander      434  9587.014  310.9450 3.243397
40     Segovia       58 10528.493  818.0547 7.769913
41     Sevilla      482 11751.782  290.7156 2.473801
42       Soria       20 13250.332 1150.5694 8.683325
43   Tarragona      134  8500.723  462.8547 5.444886
38    Tenerife      381 11426.812  333.3992 2.917692
44      Teruel       72 10639.357  937.6474 8.813008
45      Toledo      275 13885.110  458.0186 3.298631
46    Valencia      714 11812.881  255.4915 2.162821
47  Valladolid      299 13652.277  431.6310 3.161605
48     Vizcaya      524 12098.812  321.1658 2.654523
49      Zamora      104 10996.844  650.0931 5.911633
50    Zaragoza      564 14940.941  337.0070 2.255594

sae documentation built on March 26, 2020, 7:52 p.m.