#' Quantile discretization and transition probability matrix
#'
#' @param x Numeric vector representing the time series.
#' @param n_s Integer, number of states (quantile bins). Default is 15.
#'
#' @return Integer vector of state labels (1 to n_s).
#' @export
#'
#' @examples
#' x <- rnorm(1000)
#' states <- discretize_quantile(x, n_s = 10)
discretize_quantile <- function(x, n_s = 15) {
  if (n_s < 2) stop("n_s must be at least 2")
  probs <- seq(0, 1, length.out = n_s + 1)[-c(1, n_s + 1)]
  qs <- stats::quantile(x, probs = probs, na.rm = TRUE)
  breaks <- c(-Inf, qs, Inf)
  as.integer(cut(x, breaks = breaks, labels = FALSE))
}
