Learn R Programming

cirls: Constrained Iteratively Reweighted Least Squares

The package cirls provides routines to fit Generalized Linear Models (GLM) with coefficients subject to linear constraints, through a constrained iteratively reweighted least-squares algorithm.

Installation

The easiest way to install the cirls package is to install it from CRAN


install.packages("cirls")

Although not recommended, the development version can be installed from GitHub using the devtools package as

devtools::install_github("PierreMasselot/cirls")

Usage

The central function of the package is cirls.fit meant to be passed through the method argument of the glm function. The user is also expected to pass a either constraint matrix or a list of constraint matrices through the Cmat argument, and optionally lower and upper bound vectors lb and ub.

The package also contains dedicated methods to extract the variance-covariance matrix of the coefficients vcov. cirls as well as confidence intervals confint.cirls.

The example below show how to use the package to perform nonnegative regression. See ?cirls.fit for more comprehensive examples.

# Simulate predictors and response with some negative coefficients
set.seed(111)
n <- 100
p <- 10
betas <- rep_len(c(1, -1), p)
x <- matrix(rnorm(n * p), nrow = n)
y <- x %*% betas + rnorm(n)

# Define constraint matrix
Cmat <- diag(p)

# Fit GLM by CIRLS
res <- glm(y ~ x, method = cirls.fit, Cmat = list(x = Cmat))
coef(res)

# Obtain vcov and confidence intervals
vcov(res)
confint(res)

References

To come

Copy Link

Version

Install

install.packages('cirls')

Monthly Downloads

479

Version

0.3.1

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Pierre Masselot

Last Published

September 12th, 2024

Functions in cirls (0.3.1)

cirls.fit

Constrained Iteratively Reweighted Least-Squares
check_cmat

Check constraint matrix irreducibility
cirls.control

Parameters controlling CIRLS fitting
coef_simu

Simulate coefficients, calculate Confidence Intervals and Variance-Covariance Matrix for a cirls object.