{"id":18032599,"url":"https://github.com/kthohr/bayesianquantileregression","last_synced_at":"2025-10-23T23:37:27.478Z","repository":{"id":81973034,"uuid":"529444206","full_name":"kthohr/BayesianQuantileRegression","owner":"kthohr","description":"Bayesian Quantile Regression","archived":false,"fork":false,"pushed_at":"2025-03-26T16:44:21.000Z","size":70,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-26T17:42:20.515Z","etag":null,"topics":["bayesian","mcmc","quantile-regression"],"latest_commit_sha":null,"homepage":"https://bqreg.readthedocs.io/en/latest/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kthohr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-27T00:52:17.000Z","updated_at":"2025-03-26T16:44:25.000Z","dependencies_parsed_at":"2024-10-30T10:14:18.355Z","dependency_job_id":"fc7ac128-4458-404c-8882-32769869884b","html_url":"https://github.com/kthohr/BayesianQuantileRegression","commit_stats":{"total_commits":14,"total_committers":1,"mean_commits":14.0,"dds":0.0,"last_synced_commit":"7120258798fc4efe350e32775e433cf2292f7b90"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kthohr%2FBayesianQuantileRegression","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kthohr%2FBayesianQuantileRegression/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kthohr%2FBayesianQuantileRegression/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kthohr%2FBayesianQuantileRegression/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kthohr","download_url":"https://codeload.github.com/kthohr/BayesianQuantileRegression/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247256116,"owners_count":20909240,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bayesian","mcmc","quantile-regression"],"created_at":"2024-10-30T10:14:10.850Z","updated_at":"2025-10-23T23:37:22.433Z","avatar_url":"https://github.com/kthohr.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bayesian Quantile Regression\n\nA light-weight C++ implementation of Bayesian quantile regression using the asymmetric Laplace density representation of the problem, with bindings/wrappers for Python and R.\n\n# Installation\n\nClone the library and pull the necessary submodules:\n\n``` bash\n# clone optim into the current directory\ngit clone https://github.com/kthohr/BayesianQuantileRegression ./BayesianQuantileRegression\n\n# change directory\ncd ./BayesianQuantileRegression\n\n# clone necessary submodules\ngit submodule update --init\n```\n\n## Python wrapper\n\nIf you do not already have Eigen3 and Pybind11, clone and set environment variables:\n\n```bash\n# clone Eigen3\ngit clone https://gitlab.com/libeigen/eigen.git\n\n# clone Pybind11\ngit clone https://github.com/pybind/pybind11.git\n\n# set environment variables\nexport EIGEN_INCLUDE_PATH = \"\u003cpath to this directory\u003e/eigen\"\nexport PYBIND11_INCLUDE_PATH = \"\u003cpath to this directory\u003e/pybind11/include\"\n```\n\n```bash\n# change directory into the Python subdirectory\ncd BayesianQuantileRegression/Python\n\n# install the package\npython3 -m pip install . --user\n```\n\n## R wrapper\n\nFirst install the `RcppEigen` package from R:\n\n```R\ninstall.packages(\"RcppEigen\")\n```\n\nThen install the package from the `R` subdirectory:\n\n```bash\n# change directory into the R subdirectory\ncd BayesianQuantileRegression/R\n\n# install the package\nR CMD INSTALL .\n```\n\n# Example\n\n```python\n# import libraries\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom pybqreg import BayesianQuantileRegression\n\n# generate data\nn = 500\nK = 3\n\nX = np.random.normal(0.0, 1.0, [n, K])\nX[:,0] = np.ones(n)\n\nbeta0 = np.random.uniform(1.0, 2.0, K)\nbeta0[0] = 5.0\n\nY = np.matmul(X, beta0) + np.random.normal(0.0, 1.0, n)\n\n# initialize object\nobj = BayesianQuantileRegression(Y,X)\n\n# set prior pars\nbeta_bar = np.zeros(K)\n\nV0 = np.zeros([K, K])\nnp.fill_diagonal(V0, 1.0/0.001)\n\nprior_shape = 3\nprior_scale = 3\n\nobj.set_prior_params(beta_bar, V0, prior_shape, prior_scale)\n\n# (optional) set the initial draw for beta\nbeta_hat = np.linalg.solve( np.matmul(X.transpose(),X), np.matmul(X.transpose(),Y) )\nobj.set_initial_beta_draw(beta_hat)\n\n# (optional) set the number of OpenMP threads\nobj.set_omp_n_threads(4)\nobj.get_omp_n_threads()\n\n# (optional) set the seed value of the Gibbs sampler RNG\nobj.set_seed_value(1111)\n\n# set the target quantile (tau) and run the Gibbs sampler\ntau = 0.5\nn_burnin_draws = 10000\nn_keep_draws = 10000\n\nbeta_draws, z_draws, sigma_draws = obj.fit(tau, n_burnin_draws, n_keep_draws, 0)\n\nbeta_mean = np.mean(beta_draws, axis = 1)\nbeta_std = np.std(beta_draws, axis = 1)\n\n# plot beta draws\n\nfig, axs = plt.subplots(1, 3, figsize=(15, 5), tight_layout=True)\n\nfor k in range(3):\n    axs[k].hist(beta_draws[k,:], bins = 200)\n\n    axs[k].set_xlim(beta_mean[k] - 3*beta_std[k], beta_mean[k] + 3*beta_std[k])\n\n    axs[k].axvline(beta_mean[k], c = 'r')\n\nplt.show()\n```\n![plot)](docs/source/images/median_quantile_parameter_draws.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkthohr%2Fbayesianquantileregression","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkthohr%2Fbayesianquantileregression","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkthohr%2Fbayesianquantileregression/lists"}