Description Usage Arguments Details Value Author(s) References See Also Examples
Computes the Horvitz-Thompson estimator of the population total for several variables of interest
1 |
y |
Vector, matrix or data frame containing the recollected information of the variables of interest for every unit in the selected sample |
Pik |
A vector containing the inclusion probabilities for each unit in the selected sample |
The Horvitz-Thompson estimator is given by
∑_{k \in U}\frac{y_k}{{π}_k}
where y_k is the value of the variables of interest for the kth unit, and {π}_k its corresponding inclusion probability. This estimator could be used for without replacement designs as well as for with replacement designs.
The function returns a vector of total population estimates for each variable of interest.
Hugo Andres Gutierrez Rojas hagutierrezro@gmail.com
Sarndal, C-E. and Swensson, B. and Wretman, J. (1992), Model Assisted Survey Sampling. Springer.
Gutierrez, H. A. (2009), Estrategias de muestreo: Diseno de encuestas y estimacion de parametros.
Editorial Universidad Santo Tomas.
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | ############
## Example 1
############
# Uses the Lucy data to draw a simple random sample without replacement
data(Lucy)
attach(Lucy)
N <- dim(Lucy)[1]
n <- 400
sam <- sample(N,n)
# The vector of inclusion probabilities for each unit in the sample
pik <- rep(n/N,n)
# The information about the units in the sample is stored in an object called data
data <- Lucy[sam,]
attach(data)
names(data)
# The variables of interest are: Income, Employees and Taxes
# This information is stored in a data frame called estima
estima <- data.frame(Income, Employees, Taxes)
HT(estima, pik)
############
## Example 2
############
# Uses the Lucy data to draw a simple random sample with replacement
data(Lucy)
N <- dim(Lucy)[1]
m <- 400
sam <- sample(N,m,replace=TRUE)
# The vector of selection probabilities of units in the sample
pk <- rep(1/N,m)
# Computation of the inclusion probabilities
pik <- 1-(1-pk)^m
# The information about the units in the sample is stored in an object called data
data <- Lucy[sam,]
attach(data)
names(data)
# The variables of interest are: Income, Employees and Taxes
# This information is stored in a data frame called estima
estima <- data.frame(Income, Employees, Taxes)
HT(estima, pik)
############
## Example 3
############
# Without replacement sampling
# Vector U contains the label of a population of size N=5
U <- c("Yves", "Ken", "Erik", "Sharon", "Leslie")
# Vector y1 and y2 are the values of the variables of interest
y1<-c(32, 34, 46, 89, 35)
y2<-c(1,1,1,0,0)
y3<-cbind(y1,y2)
# The population size is N=5
N <- length(U)
# The sample size is n=2
n <- 2
# The sample membership matrix for fixed size without replacement sampling designs
Ind <- Ik(N,n)
# p is the probability of selection of every possible sample
p <- c(0.13, 0.2, 0.15, 0.1, 0.15, 0.04, 0.02, 0.06, 0.07, 0.08)
# Computation of the inclusion probabilities
inclusion <- Pik(p, Ind)
# Selection of a random sample
sam <- sample(5,2)
# The selected sample
U[sam]
# The inclusion probabilities for these two units
inclusion[sam]
# The values of the variables of interest for the units in the sample
y1[sam]
y2[sam]
y3[sam,]
# The Horvitz-Thompson estimator
HT(y1[sam],inclusion[sam])
HT(y2[sam],inclusion[sam])
HT(y3[sam,],inclusion[sam])
############
## Example 4
############
# Following Example 3... With replacement sampling
# The population size is N=5
N <- length(U)
# The sample size is m=2
m <- 2
# pk is the probability of selection of every single unit
pk <- c(0.9, 0.025, 0.025, 0.025, 0.025)
# Computation of the inclusion probabilities
pik <- 1-(1-pk)^m
# Selection of a random sample with replacement
sam <- sample(5,2, replace=TRUE, prob=pk)
# The selected sample
U[sam]
# The inclusion probabilities for these two units
inclusion[sam]
# The values of the variables of interest for the units in the sample
y1[sam]
y2[sam]
y3[sam,]
# The Horvitz-Thompson estimator
HT(y1[sam],inclusion[sam])
HT(y2[sam],inclusion[sam])
HT(y3[sam,],inclusion[sam])
####################################################################
## Example 5 HT is unbiased for without replacement sampling designs
## Fixed sample size
####################################################################
# Vector U contains the label of a population of size N=5
U <- c("Yves", "Ken", "Erik", "Sharon", "Leslie")
# Vector y1 and y2 are the values of the variables of interest
y<-c(32, 34, 46, 89, 35)
# The population size is N=5
N <- length(U)
# The sample size is n=2
n <- 2
# The sample membership matrix for fixed size without replacement sampling designs
Ind <- Ik(N,n)
Ind
# p is the probability of selection of every possible sample
p <- c(0.13, 0.2, 0.15, 0.1, 0.15, 0.04, 0.02, 0.06, 0.07, 0.08)
sum(p)
# Computation of the inclusion probabilities
inclusion <- Pik(p, Ind)
inclusion
sum(inclusion)
# The support with the values of the elements
Qy <-Support(N,n,ID=y)
Qy
# The HT estimates for every single sample in the support
HT1<- HT(y[Ind[1,]==1], inclusion[Ind[1,]==1])
HT2<- HT(y[Ind[2,]==1], inclusion[Ind[2,]==1])
HT3<- HT(y[Ind[3,]==1], inclusion[Ind[3,]==1])
HT4<- HT(y[Ind[4,]==1], inclusion[Ind[4,]==1])
HT5<- HT(y[Ind[5,]==1], inclusion[Ind[5,]==1])
HT6<- HT(y[Ind[6,]==1], inclusion[Ind[6,]==1])
HT7<- HT(y[Ind[7,]==1], inclusion[Ind[7,]==1])
HT8<- HT(y[Ind[8,]==1], inclusion[Ind[8,]==1])
HT9<- HT(y[Ind[9,]==1], inclusion[Ind[9,]==1])
HT10<- HT(y[Ind[10,]==1], inclusion[Ind[10,]==1])
# The HT estimates arranged in a vector
Est <- c(HT1, HT2, HT3, HT4, HT5, HT6, HT7, HT8, HT9, HT10)
Est
# The HT is actually desgn-unbiased
data.frame(Ind, Est, p)
sum(Est*p)
sum(y)
####################################################################
## Example 6 HT is unbiased for without replacement sampling designs
## Random sample size
####################################################################
# Vector U contains the label of a population of size N=5
U <- c("Yves", "Ken", "Erik", "Sharon", "Leslie")
# Vector y1 and y2 are the values of the variables of interest
y<-c(32, 34, 46, 89, 35)
# The population size is N=5
N <- length(U)
# The sample membership matrix for random size without replacement sampling designs
Ind <- IkRS(N)
Ind
# p is the probability of selection of every possible sample
p <- c(0.59049, 0.06561, 0.06561, 0.06561, 0.06561, 0.06561, 0.00729, 0.00729,
0.00729, 0.00729, 0.00729, 0.00729, 0.00729, 0.00729, 0.00729, 0.00729, 0.00081,
0.00081, 0.00081, 0.00081, 0.00081, 0.00081, 0.00081, 0.00081, 0.00081, 0.00081,
0.00009, 0.00009, 0.00009, 0.00009, 0.00009, 0.00001)
sum(p)
# Computation of the inclusion probabilities
inclusion <- Pik(p, Ind)
inclusion
sum(inclusion)
# The support with the values of the elements
Qy <-SupportRS(N, ID=y)
Qy
# The HT estimates for every single sample in the support
HT1<- HT(y[Ind[1,]==1], inclusion[Ind[1,]==1])
HT2<- HT(y[Ind[2,]==1], inclusion[Ind[2,]==1])
HT3<- HT(y[Ind[3,]==1], inclusion[Ind[3,]==1])
HT4<- HT(y[Ind[4,]==1], inclusion[Ind[4,]==1])
HT5<- HT(y[Ind[5,]==1], inclusion[Ind[5,]==1])
HT6<- HT(y[Ind[6,]==1], inclusion[Ind[6,]==1])
HT7<- HT(y[Ind[7,]==1], inclusion[Ind[7,]==1])
HT8<- HT(y[Ind[8,]==1], inclusion[Ind[8,]==1])
HT9<- HT(y[Ind[9,]==1], inclusion[Ind[9,]==1])
HT10<- HT(y[Ind[10,]==1], inclusion[Ind[10,]==1])
HT11<- HT(y[Ind[11,]==1], inclusion[Ind[11,]==1])
HT12<- HT(y[Ind[12,]==1], inclusion[Ind[12,]==1])
HT13<- HT(y[Ind[13,]==1], inclusion[Ind[13,]==1])
HT14<- HT(y[Ind[14,]==1], inclusion[Ind[14,]==1])
HT15<- HT(y[Ind[15,]==1], inclusion[Ind[15,]==1])
HT16<- HT(y[Ind[16,]==1], inclusion[Ind[16,]==1])
HT17<- HT(y[Ind[17,]==1], inclusion[Ind[17,]==1])
HT18<- HT(y[Ind[18,]==1], inclusion[Ind[18,]==1])
HT19<- HT(y[Ind[19,]==1], inclusion[Ind[19,]==1])
HT20<- HT(y[Ind[20,]==1], inclusion[Ind[20,]==1])
HT21<- HT(y[Ind[21,]==1], inclusion[Ind[21,]==1])
HT22<- HT(y[Ind[22,]==1], inclusion[Ind[22,]==1])
HT23<- HT(y[Ind[23,]==1], inclusion[Ind[23,]==1])
HT24<- HT(y[Ind[24,]==1], inclusion[Ind[24,]==1])
HT25<- HT(y[Ind[25,]==1], inclusion[Ind[25,]==1])
HT26<- HT(y[Ind[26,]==1], inclusion[Ind[26,]==1])
HT27<- HT(y[Ind[27,]==1], inclusion[Ind[27,]==1])
HT28<- HT(y[Ind[28,]==1], inclusion[Ind[28,]==1])
HT29<- HT(y[Ind[29,]==1], inclusion[Ind[29,]==1])
HT30<- HT(y[Ind[30,]==1], inclusion[Ind[30,]==1])
HT31<- HT(y[Ind[31,]==1], inclusion[Ind[31,]==1])
HT32<- HT(y[Ind[32,]==1], inclusion[Ind[32,]==1])
# The HT estimates arranged in a vector
Est <- c(HT1, HT2, HT3, HT4, HT5, HT6, HT7, HT8, HT9, HT10, HT11, HT12, HT13,
HT14, HT15, HT16, HT17, HT18, HT19, HT20, HT21, HT22, HT23, HT24, HT25, HT26,
HT27, HT28, HT29, HT30, HT31, HT32)
Est
# The HT is actually desgn-unbiased
data.frame(Ind, Est, p)
sum(Est*p)
sum(y)
################################################################
## Example 7 HT is unbiased for with replacement sampling designs
################################################################
# Vector U contains the label of a population of size N=5
U <- c("Yves", "Ken", "Erik", "Sharon", "Leslie")
# Vector y1 and y2 are the values of the variables of interest
y<-c(32, 34, 46, 89, 35)
# The population size is N=5
N <- length(U)
# The sample size is m=2
m <- 2
# pk is the probability of selection of every single unit
pk <- c(0.35, 0.225, 0.175, 0.125, 0.125)
# p is the probability of selection of every possible sample
p <- p.WR(N,m,pk)
p
sum(p)
# The sample membership matrix for random size without replacement sampling designs
Ind <- IkWR(N,m)
Ind
# The support with the values of the elements
Qy <- SupportWR(N,m, ID=y)
Qy
# Computation of the inclusion probabilities
pik <- 1-(1-pk)^m
pik
# The HT estimates for every single sample in the support
HT1 <- HT(y[Ind[1,]==1], pik[Ind[1,]==1])
HT2 <- HT(y[Ind[2,]==1], pik[Ind[2,]==1])
HT3 <- HT(y[Ind[3,]==1], pik[Ind[3,]==1])
HT4 <- HT(y[Ind[4,]==1], pik[Ind[4,]==1])
HT5 <- HT(y[Ind[5,]==1], pik[Ind[5,]==1])
HT6 <- HT(y[Ind[6,]==1], pik[Ind[6,]==1])
HT7 <- HT(y[Ind[7,]==1], pik[Ind[7,]==1])
HT8 <- HT(y[Ind[8,]==1], pik[Ind[8,]==1])
HT9 <- HT(y[Ind[9,]==1], pik[Ind[9,]==1])
HT10 <- HT(y[Ind[10,]==1], pik[Ind[10,]==1])
HT11 <- HT(y[Ind[11,]==1], pik[Ind[11,]==1])
HT12 <- HT(y[Ind[12,]==1], pik[Ind[12,]==1])
HT13 <- HT(y[Ind[13,]==1], pik[Ind[13,]==1])
HT14 <- HT(y[Ind[14,]==1], pik[Ind[14,]==1])
HT15 <- HT(y[Ind[15,]==1], pik[Ind[15,]==1])
# The HT estimates arranged in a vector
Est <- c(HT1, HT2, HT3, HT4, HT5, HT6, HT7, HT8, HT9, HT10, HT11, HT12, HT13,
HT14, HT15)
Est
# The HT is actually desgn-unbiased
data.frame(Ind, Est, p)
sum(Est*p)
sum(y)
|
The following objects are masked from Lucy:
Employees, ID, Income, Level, SPAM, Taxes, Ubication, Zone
[1] "ID" "Ubication" "Level" "Zone" "Income" "Employees"
[7] "Taxes" "SPAM"
[,1]
Income 1061793.39
Employees 153895.08
Taxes 31174.96
The following objects are masked from data (pos = 3):
Employees, ID, Income, Level, SPAM, Taxes, Ubication, Zone
The following objects are masked from Lucy:
Employees, ID, Income, Level, SPAM, Taxes, Ubication, Zone
[1] "ID" "Ubication" "Level" "Zone" "Income" "Employees"
[7] "Taxes" "SPAM"
[,1]
Income 1045679.50
Employees 160153.97
Taxes 26241.48
[1] "Ken" "Leslie"
[1] 0.34 0.27
[1] 34 35
[1] 1 0
y1 y2
[1,] 34 1
[2,] 35 0
[,1]
[1,] 229.6296
[,1]
[1,] 2.941176
[,1]
y1 229.629630
y2 2.941176
[1] "Yves" "Yves"
[1] 0.58 0.58
[1] 32 32
[1] 1 1
y1 y2
[1,] 32 1
[2,] 32 1
[,1]
[1,] 110.3448
[,1]
[1,] 3.448276
[,1]
y1 110.344828
y2 3.448276
[,1] [,2] [,3] [,4] [,5]
[1,] 1 1 0 0 0
[2,] 1 0 1 0 0
[3,] 1 0 0 1 0
[4,] 1 0 0 0 1
[5,] 0 1 1 0 0
[6,] 0 1 0 1 0
[7,] 0 1 0 0 1
[8,] 0 0 1 1 0
[9,] 0 0 1 0 1
[10,] 0 0 0 1 1
[1] 1
[,1] [,2] [,3] [,4] [,5]
[1,] 0.58 0.34 0.48 0.33 0.27
[1] 2
[,1] [,2]
[1,] 32 34
[2,] 32 46
[3,] 32 89
[4,] 32 35
[5,] 34 46
[6,] 34 89
[7,] 34 35
[8,] 46 89
[9,] 46 35
[10,] 89 35
[1] 155.1724 151.0057 324.8694 184.8020 195.8333 369.6970 229.6296 365.5303
[9] 225.4630 399.3266
X1 X2 X3 X4 X5 Est p
1 1 1 0 0 0 155.1724 0.13
2 1 0 1 0 0 151.0057 0.20
3 1 0 0 1 0 324.8694 0.15
4 1 0 0 0 1 184.8020 0.10
5 0 1 1 0 0 195.8333 0.15
6 0 1 0 1 0 369.6970 0.04
7 0 1 0 0 1 229.6296 0.02
8 0 0 1 1 0 365.5303 0.06
9 0 0 1 0 1 225.4630 0.07
10 0 0 0 1 1 399.3266 0.08
[1] 236
[1] 236
[,1] [,2] [,3] [,4] [,5]
[1,] 0 0 0 0 0
[2,] 1 0 0 0 0
[3,] 0 1 0 0 0
[4,] 0 0 1 0 0
[5,] 0 0 0 1 0
[6,] 0 0 0 0 1
[7,] 1 1 0 0 0
[8,] 1 0 1 0 0
[9,] 1 0 0 1 0
[10,] 1 0 0 0 1
[11,] 0 1 1 0 0
[12,] 0 1 0 1 0
[13,] 0 1 0 0 1
[14,] 0 0 1 1 0
[15,] 0 0 1 0 1
[16,] 0 0 0 1 1
[17,] 1 1 1 0 0
[18,] 1 1 0 1 0
[19,] 1 1 0 0 1
[20,] 1 0 1 1 0
[21,] 1 0 1 0 1
[22,] 1 0 0 1 1
[23,] 0 1 1 1 0
[24,] 0 1 1 0 1
[25,] 0 1 0 1 1
[26,] 0 0 1 1 1
[27,] 1 1 1 1 0
[28,] 1 1 1 0 1
[29,] 1 1 0 1 1
[30,] 1 0 1 1 1
[31,] 0 1 1 1 1
[32,] 1 1 1 1 1
[1] 1
[,1] [,2] [,3] [,4] [,5]
[1,] 0.1 0.1 0.1 0.1 0.1
[1] 0.5
[,1] [,2] [,3] [,4] [,5]
[1,] NA NA NA NA NA
[2,] 32 NA NA NA NA
[3,] 34 NA NA NA NA
[4,] 46 NA NA NA NA
[5,] 89 NA NA NA NA
[6,] 35 NA NA NA NA
[7,] 32 34 NA NA NA
[8,] 32 46 NA NA NA
[9,] 32 89 NA NA NA
[10,] 32 35 NA NA NA
[11,] 34 46 NA NA NA
[12,] 34 89 NA NA NA
[13,] 34 35 NA NA NA
[14,] 46 89 NA NA NA
[15,] 46 35 NA NA NA
[16,] 89 35 NA NA NA
[17,] 32 34 46 NA NA
[18,] 32 34 89 NA NA
[19,] 32 34 35 NA NA
[20,] 32 46 89 NA NA
[21,] 32 46 35 NA NA
[22,] 32 89 35 NA NA
[23,] 34 46 89 NA NA
[24,] 34 46 35 NA NA
[25,] 34 89 35 NA NA
[26,] 46 89 35 NA NA
[27,] 32 34 46 89 NA
[28,] 32 34 46 35 NA
[29,] 32 34 89 35 NA
[30,] 32 46 89 35 NA
[31,] 34 46 89 35 NA
[32,] 32 34 46 89 35
[1] 0 320 340 460 890 350 660 780 1210 670 800 1230 690 1350 810
[16] 1240 1120 1550 1010 1670 1130 1560 1690 1150 1580 1700 2010 1470 1900 2020
[31] 2040 2360
X1 X2 X3 X4 X5 Est p
1 0 0 0 0 0 0 0.59049
2 1 0 0 0 0 320 0.06561
3 0 1 0 0 0 340 0.06561
4 0 0 1 0 0 460 0.06561
5 0 0 0 1 0 890 0.06561
6 0 0 0 0 1 350 0.06561
7 1 1 0 0 0 660 0.00729
8 1 0 1 0 0 780 0.00729
9 1 0 0 1 0 1210 0.00729
10 1 0 0 0 1 670 0.00729
11 0 1 1 0 0 800 0.00729
12 0 1 0 1 0 1230 0.00729
13 0 1 0 0 1 690 0.00729
14 0 0 1 1 0 1350 0.00729
15 0 0 1 0 1 810 0.00729
16 0 0 0 1 1 1240 0.00729
17 1 1 1 0 0 1120 0.00081
18 1 1 0 1 0 1550 0.00081
19 1 1 0 0 1 1010 0.00081
20 1 0 1 1 0 1670 0.00081
21 1 0 1 0 1 1130 0.00081
22 1 0 0 1 1 1560 0.00081
23 0 1 1 1 0 1690 0.00081
24 0 1 1 0 1 1150 0.00081
25 0 1 0 1 1 1580 0.00081
26 0 0 1 1 1 1700 0.00081
27 1 1 1 1 0 2010 0.00009
28 1 1 1 0 1 1470 0.00009
29 1 1 0 1 1 1900 0.00009
30 1 0 1 1 1 2020 0.00009
31 0 1 1 1 1 2040 0.00009
32 1 1 1 1 1 2360 0.00001
[1] 236
[1] 236
[1] 0.122500 0.157500 0.122500 0.087500 0.087500 0.050625 0.078750 0.056250
[9] 0.056250 0.030625 0.043750 0.043750 0.015625 0.031250 0.015625
[1] 1
[,1] [,2] [,3] [,4] [,5]
[1,] 1 0 0 0 0
[2,] 1 1 0 0 0
[3,] 1 0 1 0 0
[4,] 1 0 0 1 0
[5,] 1 0 0 0 1
[6,] 0 1 0 0 0
[7,] 0 1 1 0 0
[8,] 0 1 0 1 0
[9,] 0 1 0 0 1
[10,] 0 0 1 0 0
[11,] 0 0 1 1 0
[12,] 0 0 1 0 1
[13,] 0 0 0 1 0
[14,] 0 0 0 1 1
[15,] 0 0 0 0 1
[,1] [,2]
[1,] 32 32
[2,] 32 34
[3,] 32 46
[4,] 32 89
[5,] 32 35
[6,] 34 34
[7,] 34 46
[8,] 34 89
[9,] 34 35
[10,] 46 46
[11,] 46 89
[12,] 46 35
[13,] 89 89
[14,] 89 35
[15,] 35 35
[1] 0.577500 0.399375 0.319375 0.234375 0.234375
[1] 55.41126 140.54428 199.44257 435.14459 204.74459 85.13302 229.16433
[8] 464.86635 234.46635 144.03131 523.76464 293.36464 379.73333 529.06667
[15] 149.33333
X1 X2 X3 X4 X5 Est p
1 1 0 0 0 0 55.41126 0.122500
2 1 1 0 0 0 140.54428 0.157500
3 1 0 1 0 0 199.44257 0.122500
4 1 0 0 1 0 435.14459 0.087500
5 1 0 0 0 1 204.74459 0.087500
6 0 1 0 0 0 85.13302 0.050625
7 0 1 1 0 0 229.16433 0.078750
8 0 1 0 1 0 464.86635 0.056250
9 0 1 0 0 1 234.46635 0.056250
10 0 0 1 0 0 144.03131 0.030625
11 0 0 1 1 0 523.76464 0.043750
12 0 0 1 0 1 293.36464 0.043750
13 0 0 0 1 0 379.73333 0.015625
14 0 0 0 1 1 529.06667 0.031250
15 0 0 0 0 1 149.33333 0.015625
[1] 236
[1] 236
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.