Further to @bgoodri response, I am seeing the exception referred to above with the following model and data.
data {
int<lower=1> N; // Number of observations
int<lower=1> K; // Number of ordinal categories
int<lower=1, upper=K> y[N]; // Observed ordinals
}
parameters {
ordered[K - 1] c; // (Internal) cut points
}
model {
vector[N] mu = rep_vector(0, N);
target += uniform_lpdf(c | -20, 20);
for(i in 1:N){
target += ordered_logistic_lpmf(y[i] | mu[i], c);
}
}
Compile, generate data and sample.
library(cmdstanr)
library(posterior)
# set_cmdstan_path(<your relevant path for cmdstan>)
file <- file.path("secondary_ord1.stan")
mod <- cmdstan_model(file)
p <- c(0.1, 0.2, 0.4, 0.2, 0.1)
ld <- list()
ld$N <- 100
set.seed(5)
ld$y <- sample(seq_along(p), ld$N, replace = T, prob = p)
table(ld$y)
ld$K <- max(ld$y)
fit <- mod$sample(
data = ld,
seed = 12,
chains = 1,
parallel_chains = 1,
refresh = 1000,
iter_warmup = 2000,
iter_sampling = 10000
)
print(as_draws_df(fit$sampler_diagnostics()))
fit$cmdstan_diagnose()
fit$cmdstan_summary()
dsmpl <- as_draws_df(fit$draws())
cp <- colMeans(dsmpl)[paste0("c[", 1:4, "]")]
rbind(c(sapply(cp, plogis), 1),
cumsum(p))
The cut points seem to be in the ballpark and the diagnostics didn’t raise any flags.
The exception is reported during the warmup phase:
Chain 1 Iteration: 1 / 12000 [ 0%] (Warmup)
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 3 is -16.0042, but should be greater than the previous element, -16.0042 (in '/tmp/Rtmpztzhjw/model-cc9773e22318.stan', line 18, column 4 to column 53)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 3 is -32.9553, but should be greater than the previous element, -32.9553 (in '/tmp/Rtmpztzhjw/model-cc9773e22318.stan', line 18, column 4 to column 53)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -584.811, but should be greater than the previous element, -584.811 (in '/tmp/Rtmpztzhjw/model-cc9773e22318.stan', line 18, column 4 to column 53)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1
Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Chain 1 Exception: ordered_logistic: Cut-points is not a valid ordered vector. The element at 2 is -13.5391, but should be greater than the previous element, -13.5391 (in '/tmp/Rtmpztzhjw/model-cc9773e22318.stan', line 18, column 4 to column 53)
Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Chain 1
Chain 1 Iteration: 1000 / 12000 [ 8%] (Warmup)
Chain 1 Iteration: 2000 / 12000 [ 16%] (Warmup)
And is ok thereafter.
The above was generated using cmdstan cmdstan-2.24.1.
Truncated session info:
> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.1 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0