MyNixOS website logo
Description

Cumulative Link Models with 'CmdStanR'.

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

clmstan

Cumulative Link Models with CmdStanR

Overview

clmstan fits cumulative link models (CLMs) for ordinal categorical data using CmdStanR. It supports 11 link functions including standard links (logit, probit, cloglog) and flexible parametric links (GEV, AEP, Symmetric Power).

Models are pre-compiled using the instantiate package for fast execution without runtime compilation.

Documentation

Full documentation is available at: https://t-momozaki.github.io/clmstan/

Installation

Prerequisites

This package requires:

  1. CmdStan - Stan's command-line interface
  2. cmdstanr - R interface to CmdStan (not on CRAN)

Step 1: Install cmdstanr

# Install cmdstanr from r-universe (recommended)
install.packages("cmdstanr",
                 repos = c("https://stan-dev.r-universe.dev",
                           getOption("repos")))

Step 2: Install CmdStan

library(cmdstanr)
install_cmdstan()  # Only needed once

Step 3: Install clmstan

# From CRAN (when available)
install.packages("clmstan")

# From GitHub (development version)
# install.packages("devtools")
devtools::install_github("t-momozaki/clmstan")

Note: During package installation, Stan models are compiled automatically. This may take a few minutes on first install.

Quick Start

library(clmstan)

# Example data
set.seed(123)
n <- 100
x <- rnorm(n)
latent <- 1.0 * x + rlogis(n)
y <- cut(latent, breaks = c(-Inf, -1, 0, 1, Inf), labels = 1:4)
data <- data.frame(y = y, x = x)

# Fit a cumulative link model with logit link
fit <- clm_stan(y ~ x, data = data, link = "logit",
                chains = 4, iter = 2000, warmup = 1000)

# View results
fit$fit$summary(variables = c("beta", "c_transformed", "beta0"))

Supported Link Functions

Standard Links (5)

LinkDistributionUse Case
logitLogisticDefault, proportional odds
probitNormalSymmetric, latent variable interpretation
cloglogGumbel (max)Asymmetric, proportional hazards
loglogGumbel (min)Asymmetric
cauchitCauchyHeavy tails

Flexible Links with Parameters (6)

LinkParameterDescription
tlink$\nu > 0$$t$-distribution, adjustable tail weight
aranda_ordaz$\lambda > 0$Generalized asymmetric link
sp$r > 0$, baseSymmetric Power, adjustable skewness
log_gamma$\lambda \in \mathbb{R}$Continuous symmetric/asymmetric adjustment
gev$\xi \in \mathbb{R}$Generalized Extreme Value
aep$\theta_1, \theta_2 > 0$Asymmetric Exponential Power

Using Flexible Links

# Fixed parameter
fit_t <- clm_stan(y ~ x, data = data, link = "tlink",
                  link_param = list(df = 8))

# Estimate parameter with Bayesian inference
fit_gev <- clm_stan(y ~ x, data = data, link = "gev",
                    link_param = list(xi = "estimate"))

Threshold Structures

StructureDescription
flexibleFree thresholds (default)
equidistantEqual spacing between thresholds
symmetricSymmetric around center
# Equidistant thresholds
fit_equi <- clm_stan(y ~ x, data = data, threshold = "equidistant")

Prior Specification

Default Priors

clmstan uses weakly informative default priors:

ParameterDefault Prior
Regression coefficients ($\beta$)normal(0, 2.5)
Thresholds ($c$)normal(0, 10)
Equidistant spacing ($d$)gamma(2, 0.5)

For link parameters estimated via Bayesian inference:

LinkParameterDefault Prior
tlink$\nu$gamma(2, 0.1)
aranda_ordaz$\lambda$gamma(0.5, 0.5)
sp$r$gamma(0.5, 0.5)
log_gamma$\lambda$normal(0, 1)
gev$\xi$normal(0, 2)
aep$\theta_1, \theta_2$gamma(2, 1)

Custom Priors

Use the prior() function with distribution helpers:

# Tighter prior on regression coefficients
fit <- clm_stan(y ~ x, data = data,
                prior = prior(normal(0, 1), class = "b"))

# Multiple priors
fit <- clm_stan(y ~ x, data = data,
                prior = c(
                  prior(normal(0, 1), class = "b"),
                  prior(normal(0, 5), class = "Intercept")
                ))

Prior for Link Parameters

When estimating link parameters, you can specify custom priors:

# Custom prior for t-link df parameter
fit <- clm_stan(y ~ x, data = data, link = "tlink",
                link_param = list(df = "estimate"),
                prior = prior(gamma(3, 0.2), class = "df"))

# Custom prior for GEV xi parameter
fit <- clm_stan(y ~ x, data = data, link = "gev",
                link_param = list(xi = "estimate"),
                prior = prior(normal(0, 0.5), class = "xi"))

Available Distribution Functions

FunctionParametersExample
normal(mu, sigma)$\mu$: mean, $\sigma$: SDnormal(0, 2.5)
gamma(alpha, beta)$\alpha$: shape, $\beta$: rategamma(2, 0.1)
student_t(df, mu, sigma)$\nu$: df, $\mu$: location, $\sigma$: scalestudent_t(3, 0, 2.5)
cauchy(mu, sigma)$\mu$: location, $\sigma$: scalecauchy(0, 2.5)
flat()noneflat()

Note:flat() creates an improper uniform prior. Use with caution as it may lead to improper posteriors if the data does not provide sufficient information. For thresholds with ordered constraints, Stan's internal transformation provides implicit regularization.

Prior Classes

ClassDescriptionCompatible Distributions
bRegression coefficients ($\beta$)normal, student_t, cauchy, flat
InterceptThresholds ($c$, flexible)normal, student_t, cauchy, flat
c1First threshold ($c_1$, equidistant)normal, student_t, cauchy, flat
cposPositive thresholds (symmetric)normal, student_t, cauchy, flat
dEquidistant spacing ($d$)gamma
dft-link degrees of freedom ($\nu$)gamma
lambda_aoAranda-Ordaz $\lambda$gamma
rSymmetric Power $r$gamma
lambda_lgLog-gamma $\lambda$normal, student_t, cauchy
xiGEV $\xi$normal, student_t, cauchy
theta1, theta2AEP shape ($\theta_1, \theta_2$)gamma

License

MIT.

Metadata

Version

0.1.1

License

Unknown

Platforms (78)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows