This data set corresponds to some socioeconomic variables from 150266 people of a city in a particular year.
data(BigCity)
A data.frame with 150266 rows and 12 variables:
The identifier of the household. It corresponds to an alphanumeric sequence (four letters and five digits).
The identifier of the person within the household. NOTE it is not a unique identifier of a person for the whole population. It corresponds to an alphanumeric sequence (five letters and two digits).
Households are located in geographic strata. There are 119 strata across the city.
Households are clustered in cartographic segments defined as primary sampling units (PSU). There are 1664 PSU and they are nested within strata.
Segments clustered within strata can be located within urban or rural areas along the city.
Sex of the person.
Per capita monthly income.
Per capita monthly expenditure.
A person's employment status.
This variable indicates whether the person is poor or not. It depends on income.
https://CRAN.R-project.org/package=TeachingSampling
Package ‘TeachingSampling’; see BigCity
Creates the Bayes Linear Estimator for Categorical Data
BLE_Categorical(ys, n, N, m = NULL, rho = NULL)
ys |
k-vector of sample proportion for each category. |
n |
sample size. |
N |
total size of the population. |
m |
k-vector with the prior proportion of each strata. If |
rho |
matrix with the prior correlation coefficients between two different units within categories. It must be a symmetric square matrix of dimension k (or k-1). If |
A list containing the following components:
est.prop
- BLE for the sample proportion of each category
Vest.prop
- Variance associated with the above
Vs.Matrix
- Vs matrix, as defined by the BLE method (should be a positive-definite matrix)
R.Matrix
- R matrix, as defined by the BLE method (should be a positive-definite matrix)
https://www150.statcan.gc.ca/n1/en/catalogue/12-001-X201400111886
Gonçalves, K.C.M, Moura, F.A.S and Migon, H.S.(2014). Bayes Linear Estimation for Finite Population with emphasis on categorical data. Survey Methodology, 40, 15-28.
# 2 categories
ys <- c(0.2614, 0.7386)
n <- 153
N <- 15288
m <- c(0.7, 0.3)
rho <- matrix(0.1, 1)
Estimator <- BLE_Categorical(ys,n,N,m,rho)
Estimator
ys <- c(0.2614, 0.7386)
n <- 153
N <- 15288
m <- c(0.7, 0.3)
rho <- matrix(0.5, 1)
Estimator <- BLE_Categorical(ys,n,N,m,rho)
Estimator
# 3 categories
ys <- c(0.2, 0.5, 0.3)
n <- 100
N <- 10000
m <- c(0.4, 0.1, 0.5)
mat <- c(0.4, 0.1, 0.1, 0.1, 0.2, 0.1, 0.1, 0.1, 0.6)
rho <- matrix(mat, 3, 3)
Creates the Bayes Linear Estimator for the Ratio "estimator"
BLE_Ratio(ys, xs, x_nots, m = NULL, v = NULL, sigma = NULL, n = NULL)
ys |
vector of sample observations or sample mean ( |
xs |
vector with values for the auxiliary variable of the elements in the sample or sample mean. |
x_nots |
vector with values for the auxiliary variable of the elements not in the sample. |
m |
prior mean for the ratio between Y and X. If |
v |
prior variance of the ratio between Y and X (bigger than |
sigma |
prior estimate of variability (standard deviation) of the ratio within the population. If |
n |
sample size. Necessary only if |
A list containing the following components:
est.beta
- BLE of Beta
Vest.beta
- Variance associated with the above
est.mean
- BLE for each individual not in the sample
Vest.mean
- Covariance matrix associated with the above
est.tot
- BLE for the total
Vest.tot
- Variance associated with the above
https://www150.statcan.gc.ca/n1/en/catalogue/12-001-X201400111886
Gonçalves, K.C.M, Moura, F.A.S and Migon, H.S.(2014). Bayes Linear Estimation for Finite Population with emphasis on categorical data. Survey Methodology, 40, 15-28.
ys <- c(10,8,6)
xs <- c(5,4,3.1)
x_nots <- c(1,20,13,15,-5)
m <- 2.5
v <- 10
sigma <- 2
Estimator <- BLE_Ratio(ys, xs, x_nots, m, v, sigma)
Estimator
# Same example but informing sample means and sample size instead of sample observations
ys <- mean(c(10,8,6))
xs <- mean(c(5,4,3.1))
n <- 3
x_nots <- c(1,20,13,15,-5)
m <- 2.5
v <- 10
sigma <- 2
Estimator <- BLE_Ratio(ys, xs, x_nots, m, v, sigma, n)
Estimator
Calculates the Bayes Linear Estimator for Regression models (general case)
BLE_Reg(ys, xs, a, R, Vs, x_nots, V_nots)
ys |
response variable of the sample |
xs |
explicative variable of the sample |
a |
vector of means from Beta |
R |
covariance matrix of Beta |
Vs |
covariance of sample errors |
x_nots |
values of X for the individuals not in the sample |
V_nots |
covariance matrix of the individuals not in the sample |
A list containing the following components:
est.beta
- BLE of Beta
Vest.beta
- Variance associated with the above
est.mean
- BLE of each individual not in the sample
Vest.mean
- Covariance matrix associated with the above
est.tot
- BLE for the total
Vest.tot
- Variance associated with the above
https://www150.statcan.gc.ca/n1/en/catalogue/12-001-X201400111886
Gonçalves, K.C.M, Moura, F.A.S and Migon, H.S.(2014). Bayes Linear Estimation for Finite Population with emphasis on categorical data. Survey Methodology, 40, 15-28.
xs <- matrix(c(1,1,1,1,2,3,5,0),nrow=4,ncol=2)
ys <- c(12,17,28,2)
x_nots <- matrix(c(1,1,1,0,1,4),nrow=3,ncol=2)
a <- c(1.5,6)
R <- matrix(c(10,2,2,10),nrow=2,ncol=2)
Vs <- diag(c(1,1,1,1))
V_nots <- diag(c(1,1,1))
Estimator <- BLE_Reg(ys, xs, a, R, Vs, x_nots, V_nots)
Estimator
Creates the Bayes Linear Estimator for the Simple Random Sampling design (without replacement)
BLE_SRS(ys, N, m = NULL, v = NULL, sigma = NULL, n = NULL)
ys |
vector of sample observations or sample mean ( |
N |
total size of the population. |
m |
prior mean. If |
v |
prior variance of an element from the population (bigger than |
sigma |
prior estimate of variability (standard deviation) within the population. If |
n |
sample size. Necessary only if |
A list containing the following components:
est.beta
- BLE of Beta (BLE for every individual)
Vest.beta
- Variance associated with the above
est.mean
- BLE for each individual not in the sample
Vest.mean
- Covariance matrix associated with the above
est.tot
- BLE for the total
Vest.tot
- Variance associated with the above
https://www150.statcan.gc.ca/n1/en/catalogue/12-001-X201400111886
Gonçalves, K.C.M, Moura, F.A.S and Migon, H.S.(2014). Bayes Linear Estimation for Finite Population with emphasis on categorical data. Survey Methodology, 40, 15-28.
ys <- c(5,6,8)
N <- 5
m <- 6
v <- 5
sigma <- 1
Estimator <- BLE_SRS(ys, N, m, v, sigma)
Estimator
# Same example but informing sample mean and sample size instead of sample observations
ys <- mean(c(5,6,8))
N <- 5
n <- 3
m <- 6
v <- 5
sigma <- 1
Estimator <- BLE_SRS(ys, N, m, v, sigma, n)
Estimator
Creates the Bayes Linear Estimator for the Stratified Simple Random Sampling design (without replacement)
BLE_SSRS(ys, h, N, m = NULL, v = NULL, sigma = NULL)
ys |
vector of sample observations or sample mean for each strata ( |
h |
vector with number of observations in each strata. |
N |
vector with the total size of each strata. |
m |
vector with the prior mean of each strata. If |
v |
vector with the prior variance of an element from each strata (bigger than |
sigma |
vector with the prior estimate of variability (standard deviation) within each strata of the population. If |
A list containing the following components:
est.beta
- BLE of Beta (BLE for the individuals in each strata)
Vest.beta
- Variance associated with the above
est.mean
- BLE for each individual not in the sample
Vest.mean
- Covariance matrix associated with the above
est.tot
- BLE for the total
Vest.tot
- Variance associated with the above
https://www150.statcan.gc.ca/n1/en/catalogue/12-001-X201400111886
Gonçalves, K.C.M, Moura, F.A.S and Migon, H.S.(2014). Bayes Linear Estimation for Finite Population with emphasis on categorical data. Survey Methodology, 40, 15-28.
ys <- c(2,-1,1.5, 6,10, 8,8)
h <- c(3,2,2)
N <- c(5,5,3)
m <- c(0,9,8)
v <- c(3,8,1)
sigma <- c(1,2,0.5)
Estimator <- BLE_SSRS(ys, h, N, m, v, sigma)
Estimator
# Same example but informing sample means instead of sample observations
y1 <- mean(c(2,-1,1.5))
y2 <- mean(c(6,10))
y3 <- mean(c(8,8))
ys <- c(y1, y2, y3)
h <- c(3,2,2)
N <- c(5,5,3)
m <- c(0,9,8)
v <- c(3,8,1)
sigma <- c(1,2,0.5)
Estimator <- BLE_SSRS(ys, h, N, m, v, sigma)
Estimator
calculates the C factor
C(ys, xs, R, Vs)
ys |
response variable of the sample |
xs |
explicative variable of the sample |
R |
covariance matrix of Beta |
Vs |
covariance of sample errors |
creates vector of 1's to be used in the estimators
create1(y)
y |
sample matrix |
vector of 1's with size equal to the number of observations in the sample
calculates the BLE for Beta
E_beta(ys, xs, a, R, Vs)
ys |
response variable of the sample |
xs |
explicative variable of the sample |
a |
vector of means from Beta |
R |
covariance matrix of Beta |
Vs |
covariance of sample errors |
calculates the BLE for the individuals not in the sample
E_theta_Reg(ys, xs, a, R, Vs, x_nots)
ys |
response variable of the sample |
xs |
explicative variable of the sample |
a |
vector of means from Beta |
R |
covariance matrix of Beta |
Vs |
covariance of sample errors |
x_nots |
values of X for the individuals not in the sample |
calculates BLE for the total T
T_Reg(ys, xs, a, R, Vs, x_nots)
ys |
response variable of the sample |
xs |
explicative variable of the sample |
a |
vector of means from Beta |
R |
covariance matrix of Beta |
Vs |
covariance of sample errors |
x_nots |
values of X for the individuals not in the sample |
calculates the risk matrix associated with the BLE for Beta
V_beta(ys, xs, R, Vs)
ys |
response variable of the sample |
xs |
explicative variable of the sample |
R |
covariance matrix of Beta |
Vs |
covariance of sample errors |
calculates the risk matrix associated with the BLE for the individuals not in the sample
V_theta_Reg(ys, xs, R, Vs, x_nots, V_nots)
ys |
response variable of the sample |
xs |
explicative variable of the sample |
R |
covariance matrix of Beta |
Vs |
covariance of sample errors |
x_nots |
values of X for the individuals not in the sample |
V_nots |
covariance matrix of the individuals not in the sample |
calculates risk matrix associated with the BLE for for the total T
VT_Reg(ys, xs, a, R, Vs, x_nots, V_nots)
ys |
response variable of the sample |
xs |
explicative variable of the sample |
a |
vector of means from Beta |
R |
covariance matrix of Beta |
Vs |
covariance of sample errors |
x_nots |
values of X for the individuals not in the sample |
V_nots |
covariance matrix of the individuals not in the sample |