detect_sepcols: Identify separation columns

View source: R/detect_sepcols.R

detect_sepcolsR Documentation

Identify separation columns

Description

This function identifies the columns in a design matrix/structure vector matrix that are responsible for separation. It calls lower level functions if given an argument or chooses based on the response type.

Usage

detect_sepcols(
  y,
  X,
  S,
  rational = FALSE,
  model = c("bcl", "b", "cl", "acl", "sl", "osm"),
  backend = c("rcdd", "ROI"),
  solver = NULL
)

sepcols(
  y,
  X,
  S,
  rational = FALSE,
  model = c("bcl", "b", "cl", "acl", "sl", "osm"),
  backend = c("rcdd", "ROI"),
  solver = NULL
)

separation_columns(..., rational, backend, solver)

## S3 method for class 'factor'
separation_columns(
  y,
  X,
  rational = FALSE,
  backend = c("rcdd", "ROI"),
  solver = NULL,
  ...
)

## Default S3 method:
separation_columns(
  y,
  X,
  rational = FALSE,
  backend = c("rcdd", "ROI"),
  solver = NULL,
  ...
)

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

## S3 method for class 'formula'
separation_columns(
  formula,
  data,
  model = c("bcl", "b", "cl", "acl", "osm", "sl"),
  rational = FALSE,
  contrasts = NULL,
  backend = c("rcdd", "ROI"),
  solver = NULL,
  ...
)

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

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

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

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

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

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

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

Arguments

y

a categorical outcome vector. Can be binary, categorial or ordinal. Works best if it is an ordered or unordered factor appropriate for the model to be fitted but can also be numeric, boolean or character. If y is not a factor, it is treated as a nominal (categorical) outcome. with the alphanumerically lowest value being the reference.

X

a design matrix, e.g. generated via a call to model.matrix. This means we expect that X already contains the desired contrasts for factors (e.g., dummies) and any other expanded columns (e.g., for polynominals).

S

a matrix of structure vectors. If given y, X and model are ignored.

rational

should rational arithmetic be used

model

model string. One of "bcl", "b", "cl", "acl", "osm", "sl".

backend

which backend to use for the linear program. Can be "rcdd" (default and only option for rational=TRUE) or "ROI".

solver

the solver to be used in the backend. Defaults to "DualSimplex" for "rcdd" and the first LP solver returned by 'ROI_applicable_solver()' for "ROI".

...

arguments for the generic: For pre-fit y, X with y a vector of type factor, character, logical, numeric or integer. This is the y argument of sepcols. In this case one also needs to supply the argument X and optional but recommended a model. One can also supply a matrix S, in which case we treat it as the S argument to sepcols. For post-fit this can currently be an object of class glm, polr, clm, osm or nnet.

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.

data

Either a standard data frame, list or environment (or object coercible by as.data.frame to a data frame) containing 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, the entries are either integer numbers or ratios of integer numbers, e.g. "1", or "-234/19008". This is checked internally; see the Details for what happens when this structure is discovered.

contrasts

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

object

model object

Details

separation_columns is S3 generic. 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 low-level function sepcols with it.

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/matrix given as rational numbers in the rcdd definition this is recognized but the formula does not get expanded and is taken literally, so e.g. variables in formula must match exactly with the column names in data, or factors need to be converted to dummies before that (wouldn't be possible in the rational format in any other way anyway).

Examples

data(qcsepdato)

# pre fit
y<-factor(qcsepdato$y, ordered=TRUE)
X<-cbind("(Intercept)"=1,qcsepdato[,2:ncol(qcsepdato)])
separation_columns(y=y, X=X) 

# post fit
if (require('clustord')) {
m1 <- clustord::osm(y~x1+x2, data = qcsepdato)
separation_columns(m1)
}

divoRce documentation built on April 28, 2026, 3:01 a.m.