seprows: Identify the rows in the design/structure vector matrix that...

View source: R/seprows.R

separation_rowsR Documentation

Identify the rows in the design/structure vector matrix that cause separation. It calls lower level functions if given an argument or chooses based on the response type.

Description

This function checks which rows in X/Xstar are responsible for separation on any category. The observations need not separate the same categories.

Usage

separation_rows(..., rational)

## S3 method for class 'factor'
separation_rows(y, X, rational = FALSE, ...)

## Default S3 method:
separation_rows(y, X, rational = FALSE, ...)

## S3 method for class 'matrix'
separation_rows(S, rational = FALSE, ...)

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

## S3 method for class 'osm'
separation_rows(object, rational = FALSE, ...)

## S3 method for class 'clm'
separation_rows(object, rational = FALSE, ...)

## S3 method for class 'polr'
separation_rows(object, rational = FALSE, ...)

## S3 method for class 'multinom'
separation_rows(object, rational = FALSE, ...)

## S3 method for class 'glm'
separation_rows(object, rational = FALSE, ...)

## S3 method for class 'bracl'
separation_rows(object, rational = FALSE, ...)

## S3 method for class 'brmultinom'
separation_rows(object, rational = FALSE, ...)

seprows(
  y,
  X,
  S,
  rational = FALSE,
  model = c("bcl", "b", "cl", "acl", "sl", "osm")
)

detect_seprows(
  y,
  X,
  S,
  rational = FALSE,
  model = c("bcl", "b", "cl", "acl", "sl", "osm")
)

Arguments

...

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 seprows. 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 seprows. For post-fit this can currently be an object of class glm, polr, clm, osm or nnet.

rational

should rational arithmetic be used?

y

the categorical outcome variable. Can be binary, categorial or ordinal. Works best if it is an ordered or unordered factor but can also be numeric, boolean or character. If y is not a factor, it is treated as a nominal (categorical) outcome.

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 polynomials).

S

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

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.

model

what model class is intended to be fitted? Can be any of "b" for binary, "bcl" for baseline-category link, "cl" for cumulative link, "acl" for adjacent-category link. "sl" for sequential link, "osm" for ordered stereotype model. If missing it defaults to cumulative link for ordinal y and baseline-category for everything else.

contrasts

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

object

model object

Details

separation_rows 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 seprows 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_rows(y=y,X=X) 


# post fit
if (require('MASS')) {
m1 <- MASS::polr(y~x1+x2, data = qcsepdato)
separation_rows(m1)
}

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

Related to seprows in divoRce...