library(BayesSampling)
In a simple model, where there is no auxiliary variable, and a Simple Random Sample was taken from the population, we can calculate the Bayes Linear Estimator for the individuals of the population with the BLE_SRS() function, which receives the following parameters:
Letting v→∞ and keeping σ2 fixed, that is, assuming prior ignorance, the resulting estimator will be the same as the one seen in the design-based context for the simple random sampling case.
This can be achieved using the BLE_SRS() function by omitting either the prior mean and/or the prior variance, that is:
data(BigCity)
set.seed(1)
sample(BigCity$Expenditure,10000)
Expend <-mean(Expend) #Real mean expenditure value, goal of the estimation
#> [1] 375.586
sample(Expend, size = 20, replace = FALSE) ys <-
Our design-based estimator for the mean will be the sample mean:
mean(ys)
#> [1] 479.869
Applying the prior information about the population we can get a better estimate, especially in cases when only a small sample is available:
BLE_SRS(ys, N = 10000, m=300, v=10.1^5, sigma = sqrt(10^5))
Estimator <-
$est.beta
Estimator#> Beta
#> 1 390.8338
$Vest.beta
Estimator#> V1
#> 1 2524.999
$est.mean[1,]
Estimator#> [1] 390.8338
$Vest.mean[1:5,1:5]
Estimator#> V1 V2 V3 V4 V5
#> 1 102524.999 2524.999 2524.999 2524.999 2524.999
#> 2 2524.999 102524.999 2524.999 2524.999 2524.999
#> 3 2524.999 2524.999 102524.999 2524.999 2524.999
#> 4 2524.999 2524.999 2524.999 102524.999 2524.999
#> 5 2524.999 2524.999 2524.999 2524.999 102524.999
c(5,6,8)
ys <- 5
N <- 6
m <- 5
v <- 1
sigma <-
BLE_SRS(ys, N, m, v, sigma)
Estimator <-
Estimator#> $est.beta
#> Beta
#> 1 6.307692
#>
#> $Vest.beta
#> V1
#> 1 0.3076923
#>
#> $est.mean
#> y_nots
#> 1 6.307692
#> 2 6.307692
#>
#> $Vest.mean
#> V1 V2
#> 1 1.3076923 0.3076923
#> 2 0.3076923 1.3076923
#>
#> $est.tot
#> [1] 31.61538
#>
#> $Vest.tot
#> [1] 3.230769
mean(c(5,6,8))
ys <- 3
n <- 5
N <- 6
m <- 5
v <- 1
sigma <-
BLE_SRS(ys, N, m, v, sigma, n)
Estimator <-#> sample mean informed instead of sample observations, parameters 'n' and 'sigma' will be necessary
Estimator#> $est.beta
#> Beta
#> 1 6.307692
#>
#> $Vest.beta
#> V1
#> 1 0.3076923
#>
#> $est.mean
#> y_nots
#> 1 6.307692
#> 2 6.307692
#>
#> $Vest.mean
#> V1 V2
#> 1 1.3076923 0.3076923
#> 2 0.3076923 1.3076923
#>
#> $est.tot
#> [1] 31.61538
#>
#> $Vest.tot
#> [1] 3.230769