| Title: | Implements Pseudo-R2D2 Prior for Ordinal Regression |
| Version: | 1.0.2 |
| Description: | Implements the pseudo-R2D2 prior for ordinal regression from the paper "Pseudo-R2D2 prior for high-dimensional ordinal regression" by Yanchenko (2025) <doi:10.1007/s11222-025-10667-x>. In particular, it provides code to evaluate the probability distribution function for the cut-points, compute the log-likelihood, calculate the hyper-parameters for the global variance parameter, find the distribution of McFadden's coefficient-of-determination, and fit the model in 'rstan'. Please cite the paper if you use these codes. |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.2 |
| Biarch: | true |
| Depends: | R (≥ 3.5.0) |
| Imports: | extraDistr (≥ 1.10.0), GIGrvg (≥ 0.8), LaplacesDemon (≥16.1.6), methods, Rcpp (≥ 0.12.0), RcppParallel (≥ 5.0.1),rstan (≥ 2.18.1), rstantools (≥ 2.4.0) |
| LinkingTo: | BH (≥ 1.66.0), Rcpp (≥ 0.12.0), RcppEigen (≥ 0.3.3.3.0),RcppParallel (≥ 5.0.1), rstan (≥ 2.18.1), StanHeaders (≥2.18.0) |
| SystemRequirements: | GNU make |
| Suggests: | knitr, rmarkdown, ggplot2, dplyr |
| VignetteBuilder: | knitr |
| NeedsCompilation: | yes |
| Packaged: | 2025-12-17 08:05:17 UTC; ericyanchenko |
| Author: | Eric Yanchenko [aut, cre] |
| Maintainer: | Eric Yanchenko <eyanchenko@aiu.ac.jp> |
| Repository: | CRAN |
| Date/Publication: | 2025-12-17 09:10:02 UTC |
The 'R2D2ordinal' package.
Description
This package implements the methods from "Pseudo-R2D2 prior for high-dimensional ordinal regression" by Eric Yanchenko.
Author(s)
Maintainer: Eric Yanchenkoeyanchenko@aiu.ac.jp
PDF of cut-points
Description
This function computes the value of theprobability density function for the cut-points. Thedistribution is induced by a Dirichlet distributionon the prior probabilities of the response.
Usage
dcut(tau, W, alpha, log = FALSE)Arguments
tau | cut-points |
W | global variance |
alpha | concentration parameters for prior probabilities of Y |
log | logical; if TRUE, returns log pdf |
Value
value of pdf at tau
Examples
tau = c(-Inf, -1, 1, Inf) # set cut pointsW = 1 # set value of global variancealpha = c(1,1,1) #concentration parametersdcut(tau, W, alpha, log=FALSE)Find optimal GIG parameters for W prior
Description
This function finds the optimal GIG parameters for the prior on Wwhich induces a beta prior distribution on McFadden's R2.
Usage
find_param( a, b, n, K, alpha = rep(2, K), nsims = 1000, nreps = 5, no_cores = 10)Arguments
a | hyper-parameter of prior for R2 ~ Beta(a,b) |
b | hyper-parameter of prior for R2 ~ Beta(a,b) |
n | number of observations |
K | number of response categories |
alpha | prior hyper-parameters for prior Dirichlet distribution on response probabilities |
nsims | number of times to simulate data |
nreps | number of times to run the algorithm (default = 5) |
no_cores | number of cores to parallelize data-generation process |
Value
Optimal GIG parameters
Examples
a = 1b = 5n = 100K = 3find_param(a, b, n, K, no_cores=1)Log-Likelihood for ordinal regression
Description
This function evaluates the log-likelihoodof the response for a given value of the parameters.
Usage
llike(Y, W, tau)Arguments
Y | ordinal response |
W | global variance |
tau | cut-points |
Value
value of log-likelihood at Y, W and tau
Examples
set.seed(1234)K = 3 # number of response categoriesY = sample(1:K, 10, replace=TRUE) # generate responsesW = 1 tau = c(-Inf, -1, 1, Inf) # set parameter valuesllike(Y, W, tau)Ordinal regression in Stan with R2D2 prior
Description
This function carries out a Bayesian ordinal regression modelin Stan using the proposed psuedo-R2D2 prior
Usage
ord_r2d2( x, y, K, a = 1, b = 10, hyper = NULL, alpha = rep(2, K), xi0 = 1, nsims = 1000, nreps = 5, no_cores = 10, progress = FALSE, ...)Arguments
x | covariate matrix |
y | response variables |
K | number of response categories |
a | hyper-parameter of prior for R2 ~ Beta(a,b) |
b | hyper-parameter of prior for R2 ~ Beta(a,b) |
hyper | hyper-parameters for W prior |
alpha | prior hyper-parameters for prior Dirichlet distribution on response probabilities |
xi0 | prior hyper-parameters for prior Dirichlet distribution of variance allocation parameters phi |
nsims | number of times to simulate data |
nreps | number of times to run the algorithm (default = 5) |
no_cores | number of cores to parallelize data-generation process |
progress | logical. if TRUE, shows the progress bars from the posterior sampling. |
... | optional hyper-parameters for Stan fitting |
Value
Stan model fit
Examples
# X are covariates, Y are responses, K is number of response categories# This example will yield low R2 values as the response are independent of the covariates.set.seed(1234)n = 100p = 5X = matrix(rnorm(n*p), nrow = n, ncol=p)K = 3Y = sample(1:K, 100, replace=TRUE)a = 1b = 5# Pre-computed hyperparametersfit <- ord_r2d2(X, Y, K, hyper=c(0.002, 0.989, 1.013), no_cores=1)out <- rstan::extract(fit)# Plot histogram of posterior Whist(out$W, xlab="W")Posterior distribution of McFadden's R2
Description
This function finds the posterior distribution ofMcFadden's R2 given the posterior samples from a Stan model fit
Usage
r2_mc(Y, out)Arguments
Y | ordinal response |
out | posterior samples from R2D2 model fit in Stan |
Value
Posterior samples from McFadden's R2
Examples
# Obtain output from ord_r2d2() model fitset.seed(1234)# X are covariates, Y are responses, K is number of response categories# This example will yield low R2 values as the response are independent of the covariates.n = 100p = 5X = matrix(rnorm(n*p), nrow = n, ncol=p)K = 3Y = sample(1:K, 100, replace=TRUE)a = 1b = 5# Pre-computed hyperparametersfit <- ord_r2d2(X, Y, K, hyper=c(0.002, 0.989, 1.013), no_cores=1)out <- rstan::extract(fit)# Plot histogram of posterior R2hist(r2_mc(Y, out), xlab="R2")