Description Usage Arguments Value Note Author(s) References Examples
Finds the vector b
minimizing
sum( (y - X %*% b)^2 )
|
subject to b[j] >= 0
for all j
.
1 |
XtX |
Crossproduct matrix |
Xty |
Crossproduct vector |
ntol |
Tolerance for non-negativity. |
The vector b
such that b[j] >= 0
for all j
.
Default non-negativity tolerance: ntol=10*(.Machine$double.eps)*max(colSums(abs(XtX)))*p
.
Nathaniel E. Helwig <helwig@umn.edu>
Bro, R., & De Jong, S. (1997). A fast non-negativity-constrained least squares algorithm. Journal of Chemometrics, 11, 393-401.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | ########## EXAMPLE 1 ##########
X <- matrix(1:100,50,2)
y <- matrix(101:150,50,1)
beta <- solve(crossprod(X))%*%crossprod(X,y)
beta
beta <- fnnls(crossprod(X),crossprod(X,y))
beta
########## EXAMPLE 2 ##########
X <- cbind(-(1:50),51:100)
y <- matrix(101:150,50,1)
beta <- solve(crossprod(X))%*%crossprod(X,y)
beta
beta <- fnnls(crossprod(X),crossprod(X,y))
beta
########## EXAMPLE 3 ##########
X <- matrix(rnorm(400),100,4)
btrue <- c(1,2,0,7)
y <- X%*%btrue + rnorm(100)
fnnls(crossprod(X),crossprod(X,y))
########## EXAMPLE 4 ##########
X <- matrix(rnorm(2000),100,20)
btrue <- runif(20)
y <- X%*%btrue + rnorm(100)
beta <- fnnls(crossprod(X),crossprod(X,y))
crossprod(btrue-beta)/20
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.