4.9 Estimation of Standard Deviation and Coefficient of Variation

This code block computes the standard deviations (sd) and coefficients of variation (cv) for the theta parameters, both observed and predicted. Initially, the summary() function from the rstan package is used to extract the sd values for observed and predicted theta parameters from the Bayesian estimation model (model_bayes). Subsequently, the sd values are organized into matrices ordered by dam2 and given corresponding names. Using these matrices, another matrix is generated containing the coefficients of variation for the observed theta parameters (theta_obs_ordenado_cv). Similarly, ordered matrices are constructed by dam2 for both the sd and cv values of the predicted theta parameters (theta_pred_ordenado_sd and theta_pred_ordenado_cv, respectively).

tasa_obs_ordenado_sd <- matrix(tasa_obs[,"sd"], 
                               nrow = D,
                               ncol = P,byrow = TRUE) 

colnames(tasa_obs_ordenado_sd) <- c("TD_mod_sd", "TO_mod_sd", "TP_mod_sd")
tasa_obs_ordenado_sd%<>% as.data.frame()
tasa_obs_ordenado_sd <- cbind(dam2 = indicador_dam1$dam2,
                              tasa_obs_ordenado_sd)
tasa_obs_ordenado_cv <- tasa_obs_ordenado_sd[,-1]/tasa_obs_ordenado[,-1]

colnames(tasa_obs_ordenado_cv) <- c("TD_mod_cv", "TO_mod_cv", "TP_mod_cv")

tasa_obs_ordenado_cv <- cbind(dam2 = indicador_dam1$dam2,
                              tasa_obs_ordenado_cv)

tasa_pred_ordenado_sd <- matrix(tasa_pred[,"sd"], 
                                nrow = D1,
                                ncol = P,byrow = TRUE)

colnames(tasa_pred_ordenado_sd) <- c("TD_mod_sd", "TO_mod_sd", "TP_mod_sd")
tasa_pred_ordenado_sd%<>% as.data.frame()
tasa_pred_ordenado_sd <- cbind(dam2 = dam_pred$dam2, tasa_pred_ordenado_sd)

tasa_pred_ordenado_cv <- tasa_pred_ordenado_sd[,-1]/tasa_pred_ordenado[,-1]

colnames(tasa_pred_ordenado_cv) <- c("TD_mod_cv", "TO_mod_cv", "TP_mod_cv")

tasa_pred_ordenado_cv <- cbind(dam2 = dam_pred$dam2, tasa_pred_ordenado_cv)

The last step is to consolidate the bases obtained for the point estimate, standard deviation and coefficient of variation.

tasa_obs_ordenado <-
  full_join(tasa_obs_ordenado, tasa_obs_ordenado_sd) %>%
  full_join(tasa_obs_ordenado_cv)

tasa_pred_ordenado <-
  full_join(tasa_pred_ordenado, tasa_pred_ordenado_sd) %>%
  full_join(tasa_pred_ordenado_cv)


estimaciones_obs <- full_join(indicador_dam1,
                              bind_rows(tasa_obs_ordenado, tasa_pred_ordenado))



saveRDS(object = estimaciones_obs, file = "Recursos/05_Empleo/11_estimaciones.rds")
tba(head(estimaciones_obs,10))
dam2 n_upm n_ocupado n_desocupado n_inactivo Ocupado Ocupado_se Ocupado_var Ocupado_deff Desocupado Desocupado_se Desocupado_var Desocupado_deff Inactivo Inactivo_se Inactivo_var Inactivo_deff TD_mod TO_mod TP_mod TD_mod_sd TO_mod_sd TP_mod_sd TD_mod_cv TO_mod_cv TP_mod_cv
0101 17 784 40 487 0.6000 0.0188 0.0004 1.9501 0.0323 0.0079 1e-04 2.6463 0.3677 0.0238 0.0006 3.2225 0.0536 0.5969 0.6307 0.0106 0.0183 0.0183 0.1978 0.0307 0.0290
0201 11 733 40 420 0.6033 0.0213 0.0005 2.2667 0.0450 0.0101 1e-04 2.8606 0.3517 0.0138 0.0002 1.0063 0.0714 0.6030 0.6494 0.0110 0.0166 0.0161 0.1546 0.0276 0.0249
0202 11 617 25 332 0.6448 0.0470 0.0022 9.4431 0.0258 0.0066 0e+00 1.7200 0.3295 0.0448 0.0020 8.8895 0.0553 0.6224 0.6589 0.0196 0.0316 0.0320 0.3552 0.0507 0.0486
0203 12 645 17 363 0.6409 0.0184 0.0003 1.5181 0.0183 0.0070 0e+00 2.7981 0.3408 0.0188 0.0004 1.6228 0.0350 0.6348 0.6579 0.0080 0.0178 0.0176 0.2287 0.0280 0.0267
0204 11 638 69 402 0.5574 0.0258 0.0007 3.0165 0.0583 0.0131 2e-04 3.4711 0.3843 0.0253 0.0006 3.0083 0.0864 0.5695 0.6233 0.0167 0.0225 0.0226 0.1937 0.0395 0.0362
0207 11 473 22 374 0.5350 0.0193 0.0004 1.3071 0.0327 0.0088 1e-04 2.1232 0.4323 0.0176 0.0003 1.0991 0.0578 0.5403 0.5735 0.0109 0.0180 0.0178 0.1886 0.0333 0.0311
0209 8 434 4 307 0.5666 0.0405 0.0016 5.0127 0.0051 0.0028 0e+00 1.1608 0.4284 0.0412 0.0017 5.1834 0.0338 0.5634 0.5832 0.0135 0.0307 0.0317 0.3991 0.0545 0.0543
0211 13 713 11 396 0.6232 0.0314 0.0010 4.7191 0.0103 0.0050 0e+00 2.7466 0.3665 0.0286 0.0008 3.9631 0.0339 0.6096 0.6310 0.0114 0.0251 0.0253 0.3372 0.0412 0.0401
0212 9 639 49 301 0.6179 0.0274 0.0007 3.1548 0.0649 0.0292 9e-04 13.9661 0.3172 0.0235 0.0006 2.5491 0.0935 0.6094 0.6723 0.0175 0.0224 0.0221 0.1870 0.0367 0.0329
0302 10 676 91 327 0.5907 0.0285 0.0008 3.6997 0.0877 0.0148 2e-04 3.0084 0.3215 0.0189 0.0004 1.8052 0.1318 0.5783 0.6662 0.0190 0.0216 0.0209 0.1442 0.0373 0.0313