The package is currently under development. A working version is already available on CRAN but an up-to-date version is available here. The documentation is also not finished.
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")
The development version can be installed from GitHub using the
devtools
package as
::install_github("PierreMasselot/cirls") devtools
Please check the file NEWS.md for changes in the development version compared to the CRAN one.
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
. Built-in constraints can also be
passed through the constr
formula interface.
The package also contains dedicated methods inference and model selection.
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