check_separation: Check separation

View source: R/generics.R

check_separationR Documentation

Check separation

Description

General separation check function.

Usage

check_separation(object, ...)

## Default S3 method:
check_separation(object, ...)

## S3 method for class 'factor'
check_separation(
  object,
  X,
  model = NULL,
  rational = FALSE,
  quick = FALSE,
  backend = c("rcdd", "ROI"),
  solver = NULL,
  ...
)

## S3 method for class 'logical'
check_separation(
  object,
  X,
  model = NULL,
  rational = FALSE,
  quick = FALSE,
  backend = c("rcdd", "ROI"),
  solver = NULL,
  ...
)

## S3 method for class 'numeric'
check_separation(
  object,
  X,
  model = NULL,
  rational = FALSE,
  quick = FALSE,
  backend = c("rcdd", "ROI"),
  solver = NULL,
  ...
)

## S3 method for class 'integer'
check_separation(
  object,
  X,
  model = NULL,
  rational = FALSE,
  quick = FALSE,
  backend = c("rcdd", "ROI"),
  solver = NULL,
  ...
)

## S3 method for class 'character'
check_separation(
  object,
  X,
  model = NULL,
  rational = FALSE,
  quick = FALSE,
  backend = c("rcdd", "ROI"),
  solver = NULL,
  ...
)

## S3 method for class 'matrix'
check_separation(
  object,
  rational = FALSE,
  quick = FALSE,
  backend = c("rcdd", "ROI"),
  solver = NULL,
  ...
)

## S3 method for class 'formula'
check_separation(
  object,
  data,
  model = NULL,
  rational = FALSE,
  quick = FALSE,
  contrasts = NULL,
  backend = c("rcdd", "ROI"),
  solver = NULL,
  ...
)

## S3 method for class 'osm'
check_separation(
  object,
  rational = FALSE,
  backend = c("rcdd", "ROI"),
  solver = NULL,
  quick = FALSE,
  ...
)

## S3 method for class 'clm'
check_separation(
  object,
  rational = FALSE,
  backend = c("rcdd", "ROI"),
  solver = NULL,
  quick = FALSE,
  ...
)

## S3 method for class 'polr'
check_separation(
  object,
  rational = FALSE,
  backend = c("rcdd", "ROI"),
  solver = NULL,
  quick = FALSE,
  ...
)

## S3 method for class 'multinom'
check_separation(
  object,
  rational = FALSE,
  backend = c("rcdd", "ROI"),
  solver = NULL,
  quick = FALSE,
  ...
)

## S3 method for class 'glm'
check_separation(
  object,
  rational = FALSE,
  backend = c("rcdd", "ROI"),
  solver = NULL,
  quick = FALSE,
  ...
)

## S3 method for class 'bracl'
check_separation(
  object,
  rational = FALSE,
  backend = c("rcdd", "ROI"),
  solver = NULL,
  quick = FALSE,
  ...
)

## S3 method for class 'brmultinom'
check_separation(
  object,
  rational = FALSE,
  backend = c("rcdd", "ROI"),
  solver = NULL,
  quick = FALSE,
  ...
)

Arguments

object

an R object. Supported inputs:

  • Pre-fit (vector): a vector of type factor, character, logical, numeric or integer. In this case one also needs to supply the argument X and, optionally but recommended, a model.

  • Pre-fit (matrix): a matrix of structure vectors.

  • Pre-fit (formula): an object of class "formula" (or one that can be coerced to that class): a symbolic description of the model to be fitted. The details of model specification are given under ‘Details’ in glm. In this case one needs to supply data, with an optional model argument as well.

  • Post-fit: a fitted model object of class glm, polr, clm, osm, brmultinom, bracl, brglm or multinom.

...

further arguments passed to the methods or lower-level functions.

X

a design matrix, e.g. generated via a call to model.matrix. X is expected to already contain the desired contrasts for factors (e.g., dummies) and any other expanded columns (e.g., for polynomials).

model

character string specifying the model class to be fitted. One of:

  • "b" – binary

  • "bcl" – baseline-category link

  • "cl" – cumulative link

  • "acl" – adjacent-category link

  • "sl" – sequential link

  • "os" – ordered stereotype model

If missing or NULL, defaults to "cl" for ordinal y and "bcl" otherwise.

rational

logical; should rational arithmetic be used?

quick

logical; if TRUE, use the quick linear program variant, otherwise the full linear program.

backend

character string specifying the backend for the linear program. One of "rcdd" (default, and the only option when rational = TRUE) or "ROI".

solver

character string specifying the solver used by the backend. Defaults to "DualSimplex" for backend = "rcdd", and to the first LP solver returned by ROI_applicable_solvers for backend = "ROI".

data

either a standard data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which the function is called.

Alternatively, data can be a data frame or matrix containing rational numbers as per the definition in rcdd (i.e. columns are characters, entries are either integer numbers or ratios of integer numbers, e.g. "1" or "-234/19008"). This is checked internally; see ‘Details’ for what happens when this structure is discovered.

contrasts

an optional list. See the contrasts.arg of model.matrix.default. Only effective for standard data frames.

Details

This function checks for (quasi-)complete separation by calling the appropriate low-level functions either with linear program 1 ('quick = FALSE'; default') or linear program 2 ('quick = TRUE').

check_separation is an S3 generic function.

For developers: If a method should be provided for the generic, it is best to have that method create a matrix of structure vectors S and use the generic with the matrix.

The formula method is for standard data frames and formulas that work the same way as when used with glm. It does not support extended formulas, and may not work for functions that do formula processing differently.

For a data frame or matrix given as rational numbers in the rcdd definition, this is recognized but the formula does not get expanded and is taken literally. Consequently:

  • variables in formula must match exactly with the column names in data;

  • factors need to be converted to dummies beforehand (which would not be possible in the rational format in any other way anyway).

Value

A logical, 'TRUE' is separation is detected.

Examples


 # pre fit

## Binary data
data(csepdat1)
outc<-csepdat1$y
desma<-cbind("(Intercept)"=1,csepdat1[,2:ncol(csepdat1)])
check_separation(outc, X = desma, model = "b")

# Nominal data 
# Baseline-category link
data(qcsepdatm)
y<-qcsepdatm$y
X<-cbind(1,qcsepdatm[,2:ncol(qcsepdatm)])
check_separation(y, X = X, model = "bcl")

# Ordinal data
data(qcsepdato)
yo<-qcsepdato$y
Xo<-qcsepdato[,2:ncol(qcsepdato)]

# Sequential link
check_separation(yo, Xo, model = "sl")

# Ordered stereotype
check_separation(yo, Xo, model = "os")

# Adjacent-category link
check_separation(yo, Xo, model= "acl")

# Cumulative link
check_separation(yo, Xo, model = "cl")


# post fit
m1 <- stats::glm(y~x1+x2,data=csepdat1,family=binomial())
check_separation(m1)

divoRce documentation built on Oct. 18, 2026, 5:08 p.m.