library(BayesSampling)
In a simple model, where there is no auxiliary variable, and a Stratified Simple Random Sample was taken from the population, we can calculate the Bayes Linear Estimator for the individuals of each strata of the population with the BLE_SSRS() function, which receives the following parameters:
data(BigCity)
dim(BigCity)[1]
end <- seq(from = 1, to = end, by = 1)
s <-
set.seed(3)
sample(s, size = 10000, replace = FALSE)
samp <- sort(samp)
ordered_samp <- BigCity[ordered_samp,]
BigCity_red <-
BigCity_red[which(BigCity_red$Zone == "Rural"),]
Rural <- Rural$Expenditure
Rural_Exp <-length(Rural_Exp)
#> [1] 4757
sample(Rural_Exp, size = 30, replace = FALSE)
Rural_ys <-
BigCity_red[which(BigCity_red$Zone == "Urban"),]
Urban <- Urban$Expenditure
Urban_Exp <-length(Urban_Exp)
#> [1] 5243
sample(Urban_Exp, size = 30, replace = FALSE) Urban_ys <-
The real expenditure means will be the values we want to estimate. In this example we know their real values:
mean(Rural_Exp)
#> [1] 291.978
mean(Urban_Exp)
#> [1] 449.0023
Our design-based estimator for the mean will be the sample mean for each strata:
mean(Rural_ys)
#> [1] 302.5523
mean(Urban_ys)
#> [1] 477.8243
Applying the prior information about the population we can get a better estimate, especially in cases when only a small sample is available:
c(Rural_ys, Urban_ys)
ys <- c(30,30)
h <- c(length(Rural_Exp), length(Urban_Exp))
N <- c(280, 420)
m <-c(4*(10.1^4), 10.1^5)
v= c(sqrt(4*10^4), sqrt(10^5))
sigma =
BLE_SSRS(ys, h, N, m, v, sigma) Estimator <-
Our Bayes Linear Estimator for the mean expenditure of each strata:
$est.beta
Estimator#> Beta
#> 1 292.3850
#> 2 454.9716
$Vest.beta
Estimator#> V1 V2
#> 1 732.2238 0.000
#> 2 0.0000 2015.967
c(2,-1,1.5, 6,10, 8,8)
ys <- c(3,2,2)
h <- c(5,5,3)
N <- c(0,9,8)
m <- c(3,8,1)
v <- c(1,2,0.5)
sigma <-
BLE_SSRS(ys, h, N, m, v, sigma)
Estimator <-
Estimator#> $est.beta
#> Beta
#> 1 0.7142857
#> 2 8.3333333
#> 3 8.0000000
#>
#> $Vest.beta
#> V1 V2 V3
#> 1 0.2857143 0.000000 0.0000000
#> 2 0.0000000 1.333333 0.0000000
#> 3 0.0000000 0.000000 0.1071429
#>
#> $est.mean
#> y_nots
#> 1 0.7142857
#> 2 0.7142857
#> 3 8.3333333
#> 4 8.3333333
#> 5 8.3333333
#> 6 8.0000000
#>
#> $Vest.mean
#> V1 V2 V3 V4 V5 V6
#> 1 1.2857143 0.2857143 0.000000 0.000000 0.000000 0.0000000
#> 2 0.2857143 1.2857143 0.000000 0.000000 0.000000 0.0000000
#> 3 0.0000000 0.0000000 5.333333 1.333333 1.333333 0.0000000
#> 4 0.0000000 0.0000000 1.333333 5.333333 1.333333 0.0000000
#> 5 0.0000000 0.0000000 1.333333 1.333333 5.333333 0.0000000
#> 6 0.0000000 0.0000000 0.000000 0.000000 0.000000 0.3571429
#>
#> $est.tot
#> [1] 68.92857
#>
#> $Vest.tot
#> [1] 27.5
mean(c(2,-1,1.5))
y1 <- mean(c(6,10))
y2 <- mean(c(8,8))
y3 <- c(y1, y2, y3)
ys <- c(3,2,2)
h <- c(5,5,3)
N <- c(0,9,8)
m <- c(3,8,1)
v <- c(1,2,0.5)
sigma <-
BLE_SSRS(ys, h, N, m, v, sigma)
Estimator <-#> sample means informed instead of sample observations, parameter 'sigma' will be necessary
Estimator#> $est.beta
#> Beta
#> 1 0.7142857
#> 2 8.3333333
#> 3 8.0000000
#>
#> $Vest.beta
#> V1 V2 V3
#> 1 0.2857143 0.000000 0.0000000
#> 2 0.0000000 1.333333 0.0000000
#> 3 0.0000000 0.000000 0.1071429
#>
#> $est.mean
#> y_nots
#> 1 0.7142857
#> 2 0.7142857
#> 3 8.3333333
#> 4 8.3333333
#> 5 8.3333333
#> 6 8.0000000
#>
#> $Vest.mean
#> V1 V2 V3 V4 V5 V6
#> 1 1.2857143 0.2857143 0.000000 0.000000 0.000000 0.0000000
#> 2 0.2857143 1.2857143 0.000000 0.000000 0.000000 0.0000000
#> 3 0.0000000 0.0000000 5.333333 1.333333 1.333333 0.0000000
#> 4 0.0000000 0.0000000 1.333333 5.333333 1.333333 0.0000000
#> 5 0.0000000 0.0000000 1.333333 1.333333 5.333333 0.0000000
#> 6 0.0000000 0.0000000 0.000000 0.000000 0.000000 0.3571429
#>
#> $est.tot
#> [1] 68.92857
#>
#> $Vest.tot
#> [1] 27.5