4.8 Parameter estimation.
This code block starts by importing an dam_pred.rds file and sets some variables for the number of parameters and the number of domains. Then, it extracts summaries from a model named model_bayes for observed and predicted rates. Next, it organizes these rates into ordered matrices, assigning appropriate column names and converting them into data frames. These data frames are concatenated with the dam2 column from the original indicador_dam1 and dam_pred data, respectively, creating two data frames (tasa_obs_ordered and tasa_pred_ordered) containing organized parameter estimates ready for further analysis.
dam_pred <- readRDS("Recursos/05_Empleo/dam_pred.rds")
P <- 3
D <- nrow(indicador_dam1)
D1 <- nrow(dam_pred)
## Estimación del modelo.
theta_dir <- indicador_dam1
tasa_obs <- summary(model_bayes,pars = "tasa_obs")$summary
tasa_pred <- summary(model_bayes,pars = "tasa_pred")$summary
## Ordenando la matrix de theta
tasa_obs_ordenado <- matrix(tasa_obs[,"mean"],
nrow = D,
ncol = P,byrow = TRUE)
colnames(tasa_obs_ordenado) <- c("TD_mod", "TO_mod", "TP_mod")
tasa_obs_ordenado%<>% as.data.frame()
tasa_obs_ordenado <- cbind(dam2 = indicador_dam1$dam2,
tasa_obs_ordenado)
tasa_pred_ordenado <- matrix(tasa_pred[,"mean"],
nrow = D1,
ncol = P,byrow = TRUE)
colnames(tasa_pred_ordenado) <- c("TD_mod", "TO_mod", "TP_mod")
tasa_pred_ordenado%<>% as.data.frame()
tasa_pred_ordenado <- cbind(dam2 = dam_pred$dam2, tasa_pred_ordenado)
estimaciones_obs <- full_join(theta_dir,
bind_rows(tasa_obs_ordenado, tasa_pred_ordenado))