| Title: | Cumulative Link Models with 'CmdStanR' |
|---|---|
| Description: | Fits cumulative link models (CLMs) for ordinal categorical data using 'CmdStanR'. Supports various link functions including logit, probit, cloglog, loglog, cauchit, and flexible parametric links such as Generalized Extreme Value (GEV), Asymmetric Exponential Power (AEP), and Symmetric Power. Models are pre-compiled using the 'instantiate' package for fast execution without runtime compilation. Methods are described in Agresti (2010, ISBN:978-0-470-08289-8), Wang and Dey (2011) <doi:10.1007/s10651-010-0154-8>, and Naranjo, Perez, and Martin (2015) <doi:10.1007/s11222-014-9449-1>. |
| Authors: | Tomotaka Momozaki [aut, cre] |
| Maintainer: | Tomotaka Momozaki <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.1 |
| Built: | 2026-05-13 05:42:45 UTC |
| Source: | https://github.com/t-momozaki/clmstan |
Combines multiple prior() objects into a single prior specification list.
## S3 method for class 'clm_prior_spec' c(...)## S3 method for class 'clm_prior_spec' c(...)
... |
|
An object of class "clm_prior_list" containing all prior specifications.
# Combine multiple priors priors <- c( prior(normal(0, 2.5), class = "b"), prior(normal(0, 10), class = "Intercept"), prior(gamma(2, 0.1), class = "df") ) print(priors)# Combine multiple priors priors <- c( prior(normal(0, 2.5), class = "b"), prior(normal(0, 10), class = "Intercept"), prior(gamma(2, 0.1), class = "df") ) print(priors)
Creates a Cauchy distribution object for use with prior().
cauchy(mu = 0, sigma = 1)cauchy(mu = 0, sigma = 1)
mu |
Location parameter. Default: 0 |
sigma |
Scale parameter. Must be positive. Default: 1 |
An object of class "clm_dist" representing a Cauchy distribution.
prior(), normal(), gamma(), student_t()
# Create a Cauchy prior (weakly informative) cauchy(0, 2.5) # Use with prior() prior(cauchy(0, 2.5), class = "b")# Create a Cauchy prior (weakly informative) cauchy(0, 2.5) # Use with prior() prior(cauchy(0, 2.5), class = "b")
Create prior specifications for cumulative link models in clmstan.
Default priors:
Regression coefficients (beta): normal(0, 2.5)
Cutpoints (c): normal(0, 10) for flexible, normal(0, 5) for symmetric
Interval (d): gamma(2, 0.5) for equidistant threshold
Link parameter priors (when estimated):
| Link | Parameter | Default Prior |
| tlink | df | gamma(2, 0.1) |
| aranda_ordaz | lambda | gamma(0.5, 0.5) |
| gev | xi | normal(0, 2) |
| sp | r | gamma(0.5, 0.5) |
| log_gamma | lambda | normal(0, 1) |
| aep | theta1, theta2 | gamma(2, 1) |
clm_prior( beta_sd = NULL, c_sd = NULL, c1_mu = NULL, c1_sd = NULL, d_alpha = NULL, d_beta = NULL, cpos_sd = NULL, df_alpha = NULL, df_beta = NULL, lambda_ao_alpha = NULL, lambda_ao_beta = NULL, lambda_lg_mu = NULL, lambda_lg_sd = NULL, xi_mu = NULL, xi_sd = NULL, r_alpha = NULL, r_beta = NULL, theta1_alpha = NULL, theta1_beta = NULL, theta2_alpha = NULL, theta2_beta = NULL )clm_prior( beta_sd = NULL, c_sd = NULL, c1_mu = NULL, c1_sd = NULL, d_alpha = NULL, d_beta = NULL, cpos_sd = NULL, df_alpha = NULL, df_beta = NULL, lambda_ao_alpha = NULL, lambda_ao_beta = NULL, lambda_lg_mu = NULL, lambda_lg_sd = NULL, xi_mu = NULL, xi_sd = NULL, r_alpha = NULL, r_beta = NULL, theta1_alpha = NULL, theta1_beta = NULL, theta2_alpha = NULL, theta2_beta = NULL )
beta_sd |
SD for normal prior on regression coefficients. Default: 2.5 (weakly informative) |
c_sd |
SD for normal prior on cutpoints (flexible threshold). Default: 10 |
c1_mu |
Mean for normal prior on first cutpoint (equidistant threshold). Default: 0 |
c1_sd |
SD for normal prior on first cutpoint (equidistant threshold). Default: 10 |
d_alpha |
Gamma shape for interval d (equidistant threshold). Default: 2 |
d_beta |
Gamma rate for interval d (equidistant threshold). Default: 0.5 |
cpos_sd |
SD for half-normal prior on positive cutpoints (symmetric threshold). Default: 5 |
df_alpha |
Gamma shape for tlink df. Default: 2 |
df_beta |
Gamma rate for tlink df. Default: 0.1 |
lambda_ao_alpha |
Gamma shape for aranda_ordaz lambda. Default: 0.5 |
lambda_ao_beta |
Gamma rate for aranda_ordaz lambda. Default: 0.5 |
lambda_lg_mu |
Normal mean for log_gamma lambda. Default: 0 |
lambda_lg_sd |
Normal SD for log_gamma lambda. Default: 1 |
xi_mu |
Normal mean for GEV xi. Default: 0 |
xi_sd |
Normal SD for GEV xi. Default: 2 |
r_alpha |
Gamma shape for SP r. Default: 0.5 |
r_beta |
Gamma rate for SP r. Default: 0.5 |
theta1_alpha |
Gamma shape for AEP theta1. Default: 2 |
theta1_beta |
Gamma rate for AEP theta1. Default: 1 |
theta2_alpha |
Gamma shape for AEP theta2. Default: 2 |
theta2_beta |
Gamma rate for AEP theta2. Default: 1 |
An object of class "clm_prior" containing prior specifications.
# Create a prior object (does not require Stan) my_prior <- clm_prior(beta_sd = 2, c_sd = 5) print(my_prior) ## Not run: # Examples below require CmdStan and compiled Stan models data(wine, package = "ordinal") # Default priors (no customization needed) fit <- clm_stan(rating ~ temp, data = wine, chains = 2, iter = 500, warmup = 250, refresh = 0) # Custom prior for regression coefficients fit2 <- clm_stan(rating ~ temp, data = wine, prior = clm_prior(beta_sd = 1), chains = 2, iter = 500, warmup = 250, refresh = 0) ## End(Not run)# Create a prior object (does not require Stan) my_prior <- clm_prior(beta_sd = 2, c_sd = 5) print(my_prior) ## Not run: # Examples below require CmdStan and compiled Stan models data(wine, package = "ordinal") # Default priors (no customization needed) fit <- clm_stan(rating ~ temp, data = wine, chains = 2, iter = 500, warmup = 250, refresh = 0) # Custom prior for regression coefficients fit2 <- clm_stan(rating ~ temp, data = wine, prior = clm_prior(beta_sd = 1), chains = 2, iter = 500, warmup = 250, refresh = 0) ## End(Not run)
Fit a Cumulative Link Model using CmdStanR
clm_stan( formula, data, link = "logit", base = "logit", threshold = "flexible", link_param = NULL, prior = NULL, chains = 4, iter = 2000, warmup = NULL, ... )clm_stan( formula, data, link = "logit", base = "logit", threshold = "flexible", link_param = NULL, prior = NULL, chains = 4, iter = 2000, warmup = NULL, ... )
formula |
A formula specifying the model (response ~ predictors) |
data |
A data frame containing the variables in the formula |
link |
Link function. One of "logit" (default), "probit", "cloglog", "loglog", "cauchit", "tlink", "gev", "aep", "sp", "aranda_ordaz", "log_gamma" |
base |
Base distribution for SP link. One of "logit" (default), "probit", "cloglog", "loglog", "cauchit", "tlink". Ignored for other link functions. |
threshold |
Threshold structure. One of "flexible" (default), "equidistant", "symmetric" |
link_param |
A list of link parameters. For flexible links, values can be:
|
prior |
Prior specification. Can be either:
|
chains |
Number of MCMC chains (default: 4) |
iter |
Total iterations per chain (default: 2000) |
warmup |
Warmup iterations per chain. If NULL (default), uses floor(iter/2) |
... |
Additional arguments passed to cmdstanr::sample() |
An object of class "clmstan"
## Not run: # Fit a proportional odds model library(ordinal) data(wine) fit <- clm_stan(rating ~ temp + contact, data = wine, link = "logit") print(fit) # Fit with t-link (fixed df) fit_t <- clm_stan(rating ~ temp, data = wine, link = "tlink", link_param = list(df = 8)) # Fit with GEV link (estimate xi) fit_gev <- clm_stan(rating ~ temp, data = wine, link = "gev", link_param = list(xi = "estimate")) ## End(Not run)## Not run: # Fit a proportional odds model library(ordinal) data(wine) fit <- clm_stan(rating ~ temp + contact, data = wine, link = "logit") print(fit) # Fit with t-link (fixed df) fit_t <- clm_stan(rating ~ temp, data = wine, link = "tlink", link_param = list(df = 8)) # Fit with GEV link (estimate xi) fit_gev <- clm_stan(rating ~ temp, data = wine, link = "gev", link_param = list(xi = "estimate")) ## End(Not run)
The clmstan class represents a fitted cumulative link model.
It contains the CmdStanR fit object and additional metadata.
The CmdStanMCMC object from cmdstanr
The model formula
The original data frame
The link function used
The base distribution (for SP link)
The threshold structure
Link parameter settings (for flexible links)
TRUE if link parameters were estimated (Bayesian inference), FALSE if they were fixed at user-specified values
Number of response categories (cached from data)
Number of observations (extracted from data for efficiency)
Number of predictors (extracted from design matrix)
Returns posterior point estimates (mean or median) for all model parameters.
## S3 method for class 'clmstan' coef(object, type = c("mean", "median"), ...)## S3 method for class 'clmstan' coef(object, type = c("mean", "median"), ...)
object |
A clmstan object |
type |
Type of point estimate: "mean" (default) or "median" |
... |
Additional arguments (ignored) |
A named numeric vector with:
Threshold coefficients (e.g., "1|2", "2|3", ...)
Regression coefficients (variable names from formula)
## Not run: fit <- clm_stan(rating ~ temp, data = wine) coef(fit) coef(fit, type = "median") ## End(Not run)## Not run: fit <- clm_stan(rating ~ temp, data = wine) coef(fit) coef(fit, type = "median") ## End(Not run)
Provides a summary of MCMC convergence diagnostics including HMC-specific diagnostics (divergences, treedepth, E-BFMI) and general convergence measures (Rhat, ESS).
diagnostics(object, ...) ## S3 method for class 'clmstan' diagnostics( object, detail = FALSE, rhat_threshold = 1.01, ess_threshold = 400, ... )diagnostics(object, ...) ## S3 method for class 'clmstan' diagnostics( object, detail = FALSE, rhat_threshold = 1.01, ess_threshold = 400, ... )
object |
A clmstan object |
... |
Additional arguments (ignored) |
detail |
Logical. If TRUE, show full parameter-level diagnostics table. If FALSE (default), show only summary and any problematic parameters. |
rhat_threshold |
Threshold for flagging high Rhat values. Default 1.01. |
ess_threshold |
Threshold for flagging low ESS values. Default 400. |
The function checks for the following issues:
Divergences: Number of divergent transitions (ideally 0)
Treedepth: Transitions hitting max treedepth (efficiency issue)
E-BFMI: Energy Bayesian Fraction of Missing Information (values < 0.3 indicate problems)
Rhat: Potential scale reduction factor (values > 1.01 indicate lack of convergence)
ESS: Effective sample size for bulk and tail (low values indicate high autocorrelation)
Invisibly returns a list containing:
hmc: HMC diagnostics from CmdStanMCMC$diagnostic_summary()
convergence: Data frame of per-parameter Rhat and ESS values
issues: Logical indicating whether any issues were detected
## Not run: fit <- clm_stan(rating ~ temp, data = wine) diagnostics(fit) diagnostics(fit, detail = TRUE) ## End(Not run)## Not run: fit <- clm_stan(rating ~ temp, data = wine) diagnostics(fit) diagnostics(fit, detail = TRUE) ## End(Not run)
Computes autocorrelation function (ACF) values for MCMC chains and returns them in a tidy data frame format.
extract_acf(object, pars = NULL, lags = 20, ...)extract_acf(object, pars = NULL, lags = 20, ...)
object |
A clmstan object |
pars |
Character vector of parameter names. If NULL (default), uses beta, c_transformed (except first), and beta0. |
lags |
Maximum number of lags to compute. Default is 20. |
... |
Additional arguments (ignored) |
The ACF measures how correlated each draw is with previous draws in the same chain. High autocorrelation at many lags indicates slow mixing and the need for more samples or reparameterization.
Ideally, ACF should drop to near zero within a few lags. Persistent high autocorrelation suggests the sampler is exploring the posterior slowly.
A data frame with columns:
parameter: Parameter name
chain: Chain number
lag: Lag value (0, 1, 2, ...)
acf: Autocorrelation value
## Not run: fit <- clm_stan(rating ~ temp, data = wine) acf_df <- extract_acf(fit) head(acf_df) # Plot ACF for specific parameters library(ggplot2) acf_df |> dplyr::filter(parameter == "beta[1]") |> ggplot(aes(x = lag, y = acf, color = factor(chain))) + geom_line() + geom_hline(yintercept = 0, linetype = "dashed") ## End(Not run)## Not run: fit <- clm_stan(rating ~ temp, data = wine) acf_df <- extract_acf(fit) head(acf_df) # Plot ACF for specific parameters library(ggplot2) acf_df |> dplyr::filter(parameter == "beta[1]") |> ggplot(aes(x = lag, y = acf, color = factor(chain))) + geom_line() + geom_hline(yintercept = 0, linetype = "dashed") ## End(Not run)
Returns expected category probabilities for each observation.
This is equivalent to predict(object, type = "probs", summary = TRUE).
## S3 method for class 'clmstan' fitted( object, newdata = NULL, summary = TRUE, robust = FALSE, probs = c(0.025, 0.975), ndraws = NULL, ... )## S3 method for class 'clmstan' fitted( object, newdata = NULL, summary = TRUE, robust = FALSE, probs = c(0.025, 0.975), ndraws = NULL, ... )
object |
A |
newdata |
Optional data frame for prediction. If |
summary |
Logical. If |
robust |
Logical. If |
probs |
Numeric vector of probabilities for quantiles.
Default is |
ndraws |
Number of posterior draws to use. If |
... |
Additional arguments (currently ignored). |
If summary = TRUE (default): A data frame with N rows and
columns for each category probability (P[Y=1], P[Y=2], etc.).
If summary = FALSE: An S x N x K array of probability draws.
predict.clmstan(), posterior_predict.clmstan()
Creates a flat (improper uniform) distribution object for use with prior().
A flat prior assigns equal probability density to all values, which is
improper (does not integrate to 1) but can be used when the likelihood
provides sufficient information for identification.
flat()flat()
An object of class "clm_dist" representing a flat distribution.
Flat priors are supported for:
Regression coefficients (class "b")
Threshold classes ("Intercept", "c1", "cpos")
Using flat priors may lead to improper posteriors if the likelihood does not provide sufficient information. For thresholds with ordered constraints, Stan's internal transformation provides implicit regularization.
prior(), normal(), student_t(), cauchy()
# Create a flat prior for regression coefficients prior(flat(), class = "b") # Flat prior for thresholds (flexible) prior(flat(), class = "Intercept")# Create a flat prior for regression coefficients prior(flat(), class = "b") # Flat prior for thresholds (flexible) prior(flat(), class = "Intercept")
Creates a gamma distribution object for use with prior().
gamma(alpha, beta)gamma(alpha, beta)
alpha |
Shape parameter of the gamma distribution. Must be positive. |
beta |
Rate parameter of the gamma distribution. Must be positive. |
An object of class "clm_dist" representing a gamma distribution.
This function masks base::gamma(). To use the base gamma function,
use base::gamma() explicitly.
prior(), normal(), student_t(), cauchy()
# Create a gamma prior gamma(2, 0.1) # Use with prior() for degrees of freedom prior(gamma(2, 0.1), class = "df")# Create a gamma prior gamma(2, 0.1) # Use with prior() for degrees of freedom prior(gamma(2, 0.1), class = "df")
Check if object is clmstan
is.clmstan(x)is.clmstan(x)
x |
An object to test |
TRUE if x is a clmstan object
clmstan supports the following link functions for cumulative link models:
Standard links (no additional parameters):
"logit" - Logistic (proportional odds model)
"probit" - Normal (latent variable interpretation)
"cloglog" - Complementary log-log (proportional hazards)
"loglog" - Log-log (Gumbel minimum)
"cauchit" - Cauchy (heavy tails)
Flexible links (with additional parameters):
"tlink" - Student-t (df > 0)
df = Inf: equals probit
df < 3: increasingly heavy tails; df > 30 is nearly normal
"aranda_ordaz" - Aranda-Ordaz asymmetric (lambda > 0)
lambda = 1: equals logit
lambda -> 0: approaches cloglog
"gev" - Generalized extreme value (shape parameter xi)
xi = 0: Gumbel (equals loglog)
xi < 0: Weibull (short tail)
xi > 0: Frechet (heavy tail)
"sp" - Symmetric power (r > 0, base distribution)
r = 1: equals base distribution
0 < r < 1: positively skewed
r > 1: negatively skewed
"log_gamma" - Log-gamma (lambda)
lambda = 0: equals probit
lambda > 0 or < 0: asymmetric
"aep" - Asymmetric exponential power (theta1 > 0, theta2 > 0)
alpha = 0.5 fixed for identifiability
theta1 = theta2: symmetric distribution
theta = 2: Gaussian kernel (but NOT equal to probit due to scaling)
theta < 2: heavy tails (leptokurtic)
theta > 2: light tails (platykurtic)
Flexible link parameters can be either fixed or estimated (inferred).
Fixed parameters: Specify a numeric value
clm_stan(y ~ x, link = "tlink", link_param = list(df = 8)) clm_stan(y ~ x, link = "gev", link_param = list(xi = 0)) # equals loglog clm_stan(y ~ x, link = "aep", link_param = list(theta1 = 2, theta2 = 2)) # symmetric
Estimated parameters: Use "estimate" (with default prior)
clm_stan(y ~ x, link = "tlink", link_param = list(df = "estimate")) clm_stan(y ~ x, link = "gev", link_param = list(xi = "estimate"))
Custom priors: Combine "estimate" with prior argument
clm_stan(y ~ x, link = "gev",
link_param = list(xi = "estimate"),
prior = prior(normal(0, 0.3), class = "xi"))
When using "estimate", the following default priors are used:
| Link | Parameter | Default Prior | Notes |
| tlink | df | gamma(2, 0.1) | Mode around 10, allows heavy tails |
| aranda_ordaz | lambda | gamma(0.5, 0.5) | Centered near 1 (logit) |
| gev | xi | normal(0, 2) | Weakly informative, Wang & Dey (2011) |
| sp | r | gamma(0.5, 0.5) | Centered near 1 (base distribution) |
| log_gamma | lambda | normal(0, 1) | Centered at 0 (probit) |
| aep | theta1 | gamma(2, 1) | Mode at 1, symmetric at theta1=theta2 |
| aep | theta2 | gamma(2, 1) | Mode at 1, symmetric at theta1=theta2 |
The Symmetric Power link uses a symmetric base distribution F_0,
specified via the base argument. Supported bases:
base = "logit": Logistic base (default)
base = "probit": Normal base
base = "cauchit": Cauchy base
base = "tlink": Student-t base (requires df)
Note: Li et al. (2019) define F_0 as a CDF "whose corresponding PDF is symmetric about 0".
Computes approximate leave-one-out cross-validation (LOO-CV) for a fitted cumulative link model using Pareto smoothed importance sampling (PSIS).
## S3 method for class 'clmstan' loo(x, ..., r_eff = NULL, cores = getOption("mc.cores", 1), save_psis = FALSE)## S3 method for class 'clmstan' loo(x, ..., r_eff = NULL, cores = getOption("mc.cores", 1), save_psis = FALSE)
x |
A |
... |
Additional arguments passed to |
r_eff |
A vector of relative effective sample sizes for each observation,
or |
cores |
The number of cores to use for parallel computation.
Defaults to |
save_psis |
If |
The function extracts the log-likelihood matrix (log_lik) computed in
the generated quantities block of the Stan model and passes it to
loo.
Pareto k diagnostics: Observations with high Pareto k values
(k > 0.7) indicate potential problems with the LOO approximation for those
observations. Use plot() on the returned object to visualize the
Pareto k values.
Model comparison: Use loo_compare to compare
multiple models. Models with higher elpd_loo are preferred.
An object of class c("psis_loo", "loo") containing:
estimates: A matrix with columns Estimate and SE
for elpd_loo, p_loo, and looic.
pointwise: A matrix with pointwise contributions.
diagnostics: A list with Pareto k values and effective
sample sizes for each observation.
waic.clmstan for WAIC computation,
loo for details on the LOO algorithm,
loo_compare for model comparison.
## Not run: fit <- clm_stan(rating ~ temp, data = wine) loo_result <- loo(fit) print(loo_result) plot(loo_result) # Compare two models fit1 <- clm_stan(rating ~ temp, data = wine, link = "logit") fit2 <- clm_stan(rating ~ temp, data = wine, link = "probit") loo::loo_compare(loo(fit1), loo(fit2)) ## End(Not run)## Not run: fit <- clm_stan(rating ~ temp, data = wine) loo_result <- loo(fit) print(loo_result) plot(loo_result) # Compare two models fit1 <- clm_stan(rating ~ temp, data = wine, link = "logit") fit2 <- clm_stan(rating ~ temp, data = wine, link = "probit") loo::loo_compare(loo(fit1), loo(fit2)) ## End(Not run)
Creates a normal distribution object for use with prior().
normal(mu = 0, sigma = 1)normal(mu = 0, sigma = 1)
mu |
Mean of the normal distribution. Default: 0 |
sigma |
Standard deviation of the normal distribution. Must be positive. Default: 1 |
An object of class "clm_dist" representing a normal distribution.
prior(), gamma(), student_t(), cauchy()
# Create a normal prior normal(0, 2.5) # Use with prior() prior(normal(0, 2.5), class = "b")# Create a normal prior normal(0, 2.5) # Use with prior() prior(normal(0, 2.5), class = "b")
Produces diagnostic plots using the bayesplot package.
## S3 method for class 'clmstan' plot( x, type = c("trace", "dens", "hist", "areas", "intervals", "acf"), pars = NULL, ... )## S3 method for class 'clmstan' plot( x, type = c("trace", "dens", "hist", "areas", "intervals", "acf"), pars = NULL, ... )
x |
A clmstan object |
type |
Type of plot: "trace" (default), "dens", "hist", "areas", "intervals", or "acf" (autocorrelation). |
pars |
Character vector of parameter names to plot. If NULL, plots beta, c_transformed (except first), and beta0. |
... |
Additional arguments passed to bayesplot functions.
For "acf" type, you can use |
A ggplot object
## Not run: fit <- clm_stan(rating ~ temp, data = wine) plot(fit) # trace plots plot(fit, type = "dens") # density plots plot(fit, type = "intervals") # credible intervals plot(fit, type = "acf") # autocorrelation plots plot(fit, pars = "beta") # only beta parameters ## End(Not run)## Not run: fit <- clm_stan(rating ~ temp, data = wine) plot(fit) # trace plots plot(fit, type = "dens") # density plots plot(fit, type = "intervals") # credible intervals plot(fit, type = "acf") # autocorrelation plots plot(fit, pars = "beta") # only beta parameters ## End(Not run)
Draws from the posterior predictive distribution. For each posterior sample, a predicted category is sampled from the categorical distribution with the predicted probabilities.
posterior_predict.clmstan(object, newdata = NULL, ndraws = NULL, ...)posterior_predict.clmstan(object, newdata = NULL, ndraws = NULL, ...)
object |
A |
newdata |
Optional data frame for prediction. If |
ndraws |
Number of posterior draws to use. If |
... |
Additional arguments (currently ignored). |
An integer matrix of dimension S x N containing predicted categories (1 to K), where S is the number of posterior draws and N is the number of observations.
predict.clmstan(), fitted.clmstan()
Generates predictions from a fitted cumulative link model.
## S3 method for class 'clmstan' predict( object, newdata = NULL, type = c("class", "probs"), summary = TRUE, robust = FALSE, probs = c(0.025, 0.975), ndraws = NULL, ... )## S3 method for class 'clmstan' predict( object, newdata = NULL, type = c("class", "probs"), summary = TRUE, robust = FALSE, probs = c(0.025, 0.975), ndraws = NULL, ... )
object |
A |
newdata |
Optional data frame for prediction. If |
type |
Type of prediction:
|
summary |
Logical. If |
robust |
Logical. If |
probs |
Numeric vector of probabilities for quantiles.
Default is |
ndraws |
Number of posterior draws to use. If |
... |
Additional arguments (currently ignored). |
Depending on type and summary:
type = "class", summary = TRUE: A data frame with columns
Estimate (mean/median predicted class), Est.Error (SD),
quantile columns, and Class (modal predicted category).
type = "class", summary = FALSE: An S x N integer matrix
of predicted categories (1 to K), where S is the number of
posterior draws and N is the number of observations.
type = "probs", summary = TRUE: A data frame with columns
for each category probability (P[Y=1], P[Y=2], etc.).
type = "probs", summary = FALSE: An S x N x K array of
predicted probabilities.
fitted.clmstan() for expected probabilities,
posterior_predict.clmstan() for posterior predictive samples.
Print method for clm_dist objects
## S3 method for class 'clm_dist' print(x, ...)## S3 method for class 'clm_dist' print(x, ...)
x |
A clm_dist object |
... |
Additional arguments (ignored) |
Invisibly returns the input clm_dist object.
Print method for clm_prior objects
## S3 method for class 'clm_prior' print(x, ...)## S3 method for class 'clm_prior' print(x, ...)
x |
A clm_prior object |
... |
Additional arguments (ignored) |
Invisibly returns the input clm_prior object.
Print method for clm_prior_list objects
## S3 method for class 'clm_prior_list' print(x, ...)## S3 method for class 'clm_prior_list' print(x, ...)
x |
A clm_prior_list object |
... |
Additional arguments (ignored) |
Invisibly returns the input clm_prior_list object.
Print method for clm_prior_spec objects
## S3 method for class 'clm_prior_spec' print(x, ...)## S3 method for class 'clm_prior_spec' print(x, ...)
x |
A clm_prior_spec object |
... |
Additional arguments (ignored) |
Invisibly returns the input clm_prior_spec object.
Print method for clmstan objects
## S3 method for class 'clmstan' print(x, ...)## S3 method for class 'clmstan' print(x, ...)
x |
A clmstan object |
... |
Additional arguments (ignored) |
Invisibly returns x
Print method for summary.clmstan objects
## S3 method for class 'summary.clmstan' print(x, ...)## S3 method for class 'summary.clmstan' print(x, ...)
x |
A summary.clmstan object |
... |
Additional arguments (ignored) |
Invisibly returns x
Specify prior distributions for model parameters using distribution functions.
prior(prior, class = "b", coef = "")prior(prior, class = "b", coef = "")
prior |
A distribution object created by |
class |
The parameter class. Valid classes are:
|
coef |
Optional coefficient name (for future extension). |
An object of class "clm_prior_spec" representing the prior specification.
normal(), gamma(), student_t(), cauchy(), clm_prior()
# Specify a normal prior for regression coefficients prior(normal(0, 2.5), class = "b") # Specify a gamma prior for degrees of freedom prior(gamma(2, 0.1), class = "df") # Combine multiple priors c( prior(normal(0, 2.5), class = "b"), prior(normal(0, 10), class = "Intercept") )# Specify a normal prior for regression coefficients prior(normal(0, 2.5), class = "b") # Specify a gamma prior for degrees of freedom prior(gamma(2, 0.1), class = "df") # Combine multiple priors c( prior(normal(0, 2.5), class = "b"), prior(normal(0, 10), class = "Intercept") )
Creates a Student-t distribution object for use with prior().
student_t(df = 3, mu = 0, sigma = 1)student_t(df = 3, mu = 0, sigma = 1)
df |
Degrees of freedom. Must be positive. Default: 3 |
mu |
Location parameter. Default: 0 |
sigma |
Scale parameter. Must be positive. Default: 1 |
An object of class "clm_dist" representing a Student-t distribution.
prior(), normal(), gamma(), cauchy()
# Create a Student-t prior with heavy tails student_t(3, 0, 2.5) # Use with prior() prior(student_t(3, 0, 2.5), class = "b")# Create a Student-t prior with heavy tails student_t(3, 0, 2.5) # Use with prior() prior(student_t(3, 0, 2.5), class = "b")
Summary method for clmstan objects
## S3 method for class 'clmstan' summary(object, probs = c(0.025, 0.5, 0.975), digits = 3, ...)## S3 method for class 'clmstan' summary(object, probs = c(0.025, 0.5, 0.975), digits = 3, ...)
object |
A clmstan object |
probs |
Quantile probabilities for credible intervals |
digits |
Number of significant digits for display |
... |
Additional arguments (ignored) |
An object of class "summary.clmstan" containing:
coefficients: Posterior summary for regression coefficients
thresholds: Posterior summary for threshold parameters
beta0: Posterior summary for intercept
link_params: Posterior summary for link parameters (full model only)
model_info: Model metadata (formula, link, threshold, K, N, P)
Get supported link functions
supported_links(type = c("all", "standard", "flexible"))supported_links(type = c("all", "standard", "flexible"))
type |
Character string specifying which links to return:
|
A character vector of supported link function names
supported_links() supported_links("standard") supported_links("flexible")supported_links() supported_links("standard") supported_links("flexible")
Get supported threshold structures
supported_thresholds()supported_thresholds()
A character vector of supported threshold structure names
supported_thresholds()supported_thresholds()
Computes the Widely Applicable Information Criterion (WAIC) for a fitted cumulative link model.
## S3 method for class 'clmstan' waic(x, ...)## S3 method for class 'clmstan' waic(x, ...)
x |
A |
... |
Additional arguments (currently ignored). |
WAIC is an alternative to LOO-CV that is asymptotically equivalent to leave-one-out cross-validation. However, LOO-CV with PSIS is generally preferred because:
It provides useful diagnostics (Pareto k values)
It is more robust in finite samples
It has been shown to be more reliable in practice
For most purposes, loo.clmstan is recommended over WAIC.
An object of class c("waic", "loo") containing:
estimates: A matrix with columns Estimate and SE
for elpd_waic, p_waic, and waic.
pointwise: A matrix with pointwise contributions.
loo.clmstan for LOO-CV (recommended),
waic for details on WAIC computation,
loo_compare for model comparison.
## Not run: fit <- clm_stan(rating ~ temp, data = wine) waic_result <- waic(fit) print(waic_result) ## End(Not run)## Not run: fit <- clm_stan(rating ~ temp, data = wine) waic_result <- waic(fit) print(waic_result) ## End(Not run)