# Nonnegative generalized linear model

Is it possible that all the parameters of a generalized linear model are constrained to be non-negative? If so, when? Any examples?

• Commented Oct 13, 2022 at 2:30

Well, it is certainly possible, but mostly only some coefficients will be restricted. A glm (generalized linear model) have a linear predictor $$\eta(x)=\beta^T x$$ and the parameter vector $$\beta$$ then plays the same role as in linear regression, so restrictions can apply in the same way as with linear regression.

An example is Linear model with constraints on coefficients in terms of ratios, although the method used there with a glm would lead to a nested optimization. Another example is Looking for function to fit sigmoid-like curve, where a monotone spline is fit, which could also be combined with a glm. The non-negativity restrictions there is used to impose monotone increasing, if the same coefficients had been required to be nonpositive the result would have been monotone decreasing.

This last example is an example of shape-restricted splines, there is now an R package (actually multiple) implementing those ideas. cgam implements them in the setting of gam's (generalized additive models), a generalization of glm's. An example from that package's helpfile is:

library(cgam)
data(kyphosis, package="gam")

# regress Kyphosis on Age, Number, and Start under the restrictions:
# "concave", "increasing and concave", and "decreasing and concave"

fit <- cgam(Kyphosis ~ conc(Age) + incr.conc(Number) + decr.conc(Start),
family = binomial(), data = kyphosis)

• I encounter problems where all coefficients are positive in the case when the linear model represents some physical reality where all coefficients are necessarily positive. For instance, if you are mixing different components together, then you can only add but not subtract, Commented Nov 6, 2020 at 17:03
• This is a very weird deja-vu. I do not remember having written that comment yesterday. But I do remember having written it a long time ago. @kjetil do you remember this comment showing up earlier on your post? Commented Nov 8, 2020 at 8:29
• @Sextus Empiricus: I remember it appearing yesterday---can software count wrong? (maybe we soon will see some US court discussion ...) Commented Nov 8, 2020 at 9:58
• Maybe I am confused with this question stats.stackexchange.com/questions/212138 ... But I still can't remember writing that comment. Commented Nov 8, 2020 at 11:37

You can fit GLMs with nonnegativity constraints on the fitted coefficients using the glm.cons function in the zetadiv package : https://rdrr.io/cran/zetadiv/man/glm.cons.html (the p values and confidence intervals are not calculated correctly though - there is no correct closed form solution for them under nonnegativity constraints; bootstrapping would be the way to go). If you would like only some coefficients to have nonnegativity constraints you can use https://cran.r-project.org/web/packages/restriktor/index.html. Or there is the glmnet package, which fits GLMs with LASSO or elastic net regularization (glmnet function), or unregularised GLMs (bigGlm function), which in both cases have the options lower.limits and upper.limits with which you can specify box constraints.

Finally, to fit nonnegative Poisson, binomial and negative binomial GLMs there is http://finzi.psych.upenn.edu/R/library/addreg/html/00Index.html.

Nonnegative identity link Gaussian or Poisson models are used quite a lot in the field of nonnegative matrix factorisation & in signal processing. E.g. if you have a blurred spike train one can deconvolve the signal by regressing the observed blurred signal against a covariate matrix consisting of time-shifted point spread functions, using either a nonnegative identity link Gaussian or Poisson model (depending on the type of noise you have). For identity link Poisson models you really need the nonnegativity constraints - a regular identity link Poisson model without nonnegativity constraints fit using the default glm function in R nearly always blows up...