Skip to content

An R package to fit Bayesian quantile regression for Ordinal models with Stan

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

pedroaraujo9/qordstan

Repository files navigation

R-CMD-check Codecov test coverage

qordstan

This package implements the Bayesian quantile ordinal model described in (Rahman, 2016) using rstan.

Installing the package:

devtools::install_github("pedroaraujo9/qordstan", ref = 'main')

Simulating data

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)

Fiting the model

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')]

Predicting

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()

References

  • 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/.

About

An R package to fit Bayesian quantile regression for Ordinal models with Stan

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published