An internal function to create an A matrix for calibration of quantiles
Source:R/joint_calib_create_matrix.R
joint_calib_create_matrix.Rd
joint_calib_create_matrix
is function that creates an \(A = [a_{ij}]\) matrix for calibration of quantiles. Function allows to create matrix using logistic
interpolation (using stats::plogis
, default) or linear
(as in Harms and Duchesne (2006), i.e. slightly modified Heavyside function).
In case of logistic
interpolation elements of \(A\) are created as follows
\[a_{i j} = \frac{1}{(1 + \exp\left(-2l\left(x_{ij}-Q_{x_j, \alpha}\right)\right))N},\]
where \(x_{ij}\) is the \(i\)th row of the auxiliary variable \(X_j\), \(N\) is the population size, \(Q_{x_j, \alpha}\) is the known population \(\alpha\)th quantile, and \(l\) is set to -1000 (by default).
In case of linear
interpolation elements of \(A\) are created as follows
\[a_{i j}= \begin{cases} N^{-1}, & x_{i j} \leqslant L_{x_{j}, r} \left(Q_{x_j, \alpha}\right), \cr N^{-1} \beta_{x_{j}, r}\left(Q_{x_j, \alpha}\right), & x_{i j}=U_{x_{j}, r}\left(Q_{x_j, \alpha}\right), \cr 0, & x_{i j}>U_{x_{j}, r} \left(Q_{x_j, \alpha}\right), \end{cases}\]
\(i=1,...,r\), \(j=1,...,k\), where \(r\) is the set of respondents, \(k\) is the auxiliary variable index and
\[L_{x_{j}, r}(t) = \max \left\lbrace\left\lbrace{x_{i j}}, i \in s \mid x_{i j} \leqslant t\right\rbrace \cup \lbrace-\infty\rbrace \right\rbrace,\] \[U_{x_{j}, r}(t) = \min \left\lbrace\left\lbrace{x_{i j}}, i \in s \mid x_{i j}>t\right\rbrace \cup \lbrace\infty\rbrace \right\rbrace,\] \[\beta_{x_{j}, r}(t) = \frac{t-L_{x_{j}, s}(t)}{U_{x_{j}, s}(t)-L_{x_{j}, s}(t)},\]
\(i=1,...,r\), \(j=1,...,k\), \(t \in \mathbb{R}\).
Usage
joint_calib_create_matrix(X_q, N, pop_quantiles, control = control_calib())
Arguments
- X_q
matrix of variables for calibration of quantiles,
- N
population size for calibration of quantiles,
- pop_quantiles
a vector of population quantiles for
X_q
,- control
a control parameter for creation of
X_q
matrix.
References
Harms, T. and Duchesne, P. (2006). On calibration estimation for quantiles. Survey Methodology, 32(1), 37.
Examples
# Create matrix for one variable and 3 quantiles
set.seed(123)
N <- 1000
x <- as.matrix(rnorm(N))
quants <- list(quantile(x, c(0.25,0.5,0.75)))
A <- joint_calib_create_matrix(x, N, quants)
head(A)
#> [,1] [,2] [,3]
#> [1,] 3.417662e-33 1.000000e-03 0.001
#> [2,] 1.221974e-176 1.000000e-03 0.001
#> [3,] 0.000000e+00 0.000000e+00 0.000
#> [4,] 3.168423e-307 2.389406e-30 0.001
#> [5,] 0.000000e+00 7.091618e-56 0.001
#> [6,] 0.000000e+00 0.000000e+00 0.000
colSums(A)
#> [1] 0.2502323 0.4999654 0.7498815
# Create matrix with linear interpolation
A <- joint_calib_create_matrix(x, N, quants, control_calib(interpolation="linear"))
head(A)
#> [,1] [,2] [,3]
#> [1,] 0 0.001 0.001
#> [2,] 0 0.001 0.001
#> [3,] 0 0.000 0.000
#> [4,] 0 0.000 0.001
#> [5,] 0 0.000 0.001
#> [6,] 0 0.000 0.000
colSums(A)
#> [1] 0.24975 0.49950 0.74925
# Create matrix for two variables and different number of quantiles
set.seed(123)
x1 <- rnorm(N)
x2 <- rchisq(N, 1)
x <- cbind(x1, x2)
quants <- list(quantile(x1, 0.5), quantile(x2, c(0.1, 0.75, 0.9)))
B <- joint_calib_create_matrix(x, N, quants)
head(B)
#> [,1] [,2] [,3] [,4]
#> [1,] 1.000000e-03 7.889542e-30 1.000000e-03 0.001
#> [2,] 1.000000e-03 1.614292e-242 1.000000e-03 0.001
#> [3,] 0.000000e+00 0.000000e+00 0.000000e+00 0.001
#> [4,] 2.389406e-30 0.000000e+00 0.000000e+00 0.000
#> [5,] 7.091618e-56 0.000000e+00 1.360616e-132 0.001
#> [6,] 0.000000e+00 0.000000e+00 1.000000e-03 0.001
colSums(B)
#> [1] 0.49996541 0.09961593 0.74980652 0.89987264