% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/estimators.R
\name{werm_logistic}
\alias{werm_logistic}
\title{Fit a WERM changepoint model with binary logistic loss}
\usage{
werm_logistic(
  X,
  y,
  num_chgpts,
  delta = 1L,
  search_method = "efficient",
  fit_intercept = TRUE,
  max_iter = 100L,
  tol = 1e-05,
  penalty = "l2",
  alpha = 1
)
}
\arguments{
\item{X}{Numeric matrix of shape \verb{(n, p)}. Observations must be in order.}

\item{y}{Integer or factor vector of binary labels (two unique values).}

\item{num_chgpts}{Integer. Number of changepoints to detect.}

\item{delta}{Integer. Minimum gap between candidate changepoints during
search. Default \code{1}. Rule of thumb: \code{max(1L, as.integer(0.05 * nrow(X)))}.}

\item{search_method}{Character. \code{"efficient"} (default) or \code{"brute_force"}.}

\item{fit_intercept}{Logical. Whether each segment model includes an
intercept. Default \code{TRUE}.}

\item{max_iter}{Integer. Maximum L-BFGS-B iterations. Default \code{100}.}

\item{tol}{Numeric. Gradient-norm tolerance. Default \code{1e-5}.}

\item{penalty}{Character. Default \code{"l2"} (prevents divergence on separable
segments). Set \code{"none"} only when segments are not separable.}

\item{alpha}{Numeric. Default \code{1.0}.}
}
\value{
An object of class \code{c("werm_logistic", "werm_fit")}.
Contains all elements from \code{\link[=werm_least_squares]{werm_least_squares()}} plus:
\describe{
\item{\code{classes}}{Character vector of length 2. The two class labels in
sorted order. \code{classes[2]} is the positive class.}
}
}
\description{
Detects \code{num_chgpts} changepoints in ordered binary classification data.
}
\examples{
# Limit BLAS/OpenMP threads so example CPU time stays proportional to
# elapsed time on multicore CRAN machines.
Sys.setenv(
  OMP_NUM_THREADS = "1",
  OPENBLAS_NUM_THREADS = "1",
  MKL_NUM_THREADS = "1",
  BLAS_NUM_THREADS = "1"
)

if (nzchar(Sys.getenv("RETICULATE_PYTHON")) &&
    weightederm_examples_available("WERMLogistic")) {
  set.seed(3)
  n <- 30L; p <- 2L; true_cp <- 15L
  X <- matrix(rnorm(n * p), n, p)
  eta <- c(
    X[1:true_cp, ] \%*\% c(3, -3),
    X[(true_cp + 1L):n, ] \%*\% c(-3, 3)
  )
  y <- rbinom(n, 1L, 1 / (1 + exp(-eta)))
  fit <- werm_logistic(X, y, num_chgpts = 1L, delta = 3L,
                       fit_intercept = FALSE, max_iter = 100L)
  fit$changepoints
  fit$classes
}

}
