Learn R Programming

SSBtools (version 1.7.5)

LSfitNonNeg: Non-negative regression fits with a sparse overparameterized model matrix

Description

Assuming z = t(x) %*% y + noise, a non-negatively modified least squares estimate of t(x) %*% y is made.

Usage

LSfitNonNeg(x, z, limit = 1e-10, viaQR = FALSE, printInc = TRUE)

Value

A fitted version of z

Arguments

x

A matrix

z

A single column matrix

limit

Lower limit for non-zero fits. Set to NULL or -Inf to avoid the non-zero restriction.

viaQR

Least squares fits obtained using qr when TRUE.

printInc

Printing "..." to console when TRUE.

Author

Øyvind Langsrud

Details

The problem is first reduced by elimination some rows of x (elements of y) using GaussIndependent. Thereafter least squares fits are obtained using solve or qr. Possible negative fits will be forced to zero in the next estimation iteration(s).

Examples

Run this code
set.seed(123)
data2 <- SSBtoolsData("z2")
x <- ModelMatrix(data2, formula = ~fylke + kostragr * hovedint - 1)
z <- Matrix::t(x) %*% data2$ant + rnorm(ncol(x), sd = 3)
LSfitNonNeg(x, z)
LSfitNonNeg(x, z, limit = NULL)

if (FALSE) {
mf <- ~region*mnd + hovedint*mnd + fylke*hovedint*mnd + kostragr*hovedint*mnd
data4 <- SSBtoolsData("sosialFiktiv")
x <- ModelMatrix(data4, formula = mf)
z <- Matrix::t(x) %*% data4$ant + rnorm(ncol(x), sd = 3)
zFit <- LSfitNonNeg(x, z)
}

Run the code above in your browser using DataLab