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.
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
::install_github("PierreMasselot/cirls") devtools
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)
<- 100
n <- 10
p <- rep_len(c(1, -1), p)
betas <- matrix(rnorm(n * p), nrow = n)
x <- x %*% betas + rnorm(n)
y
# Define constraint matrix
<- diag(p)
Cmat
# Fit GLM by CIRLS
<- glm(y ~ x, method = cirls.fit, Cmat = list(x = Cmat))
res coef(res)
# Obtain vcov and confidence intervals
vcov(res)
confint(res)
To come