This package implements the Bayesian quantile ordinal model described in (Rahman, 2016) using rstan
.
devtools::install_github("pedroaraujo9/qordstan", ref = 'main')
The gen_data_example
function returns a list with a data.frame
containing the simulated data and the true model parameters values.
Example Generating data with 1000 observations, 5 categories, 0.3 quantile and 4 covariates:
example_data = gen_data_example(n = 1000, k = 5, q = 0.3, p = 4)
The model can be fitted with the function qord_fit
:
model_fit = qord_fit(y ~ X1 + X2 + X3 + X4, q = 0.3,
data = example_data$example_df,
iter = 1000, verbose = F)
The function returns a qordstan
object. We can access the original stanfit
object, WAIC, posterior samples, etc.
Summarizing the results:
summary(model_fit)
The beta and gamma true values are in the example_data object:
example_data[c("b", 'gamma')]
We can also get a posterior predictive sample from the model and choose between the latent variable z_i or the observed response y_i:
#sampling y_i
pred = predict(model_fit)
#bar plot for of the posterior predictive sample of the first observation
pred[,1] %>% table() %>% barplot()
-
Mohammad Arshad Rahman "Bayesian Quantile Regression for Ordinal Models," Bayesian Analysis, Bayesian Anal. 11(1), 1-24, (March 2016).
-
Stan Development Team (2020). “RStan: the R interface to Stan.” R package version 2.21.2, http://mc-stan.org/.