ord_r2d2 | R Documentation |
This function carries out a Bayesian ordinal regression model in Stan using the proposed psuedo-R2D2 prior
ord_r2d2(
x,
y,
K,
a = 1,
b = 10,
hyper = NULL,
alpha = rep(1, K),
nsims = 1000,
nreps = 5,
no_cores = 10,
progress = FALSE,
...
)
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 |
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 |
Stan model fit
# 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 = 100
p = 5
X = matrix(rnorm(n*p), nrow = n, ncol=p)
K = 3
Y = sample(1:K, 100, replace=TRUE)
a = 1
b = 5
# Pre-computed hyperparameters
fit <- ord_r2d2(X, Y, K, hyper=c(0.002, 0.989, 1.013), no_cores=1)
out <- rstan::extract(fit)
# Plot histogram of posterior W
hist(out$W, xlab="W")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.