SHAZAM Community
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Yes, this can be done.

Specifying the equation on the NL command like

EQ Y = a + (b*b)*X

will make the coefficient on X always positive because b*b is always zero or positive.

A SHAZAM PROC (procedure) for two variables might look like this:

* PROC NNLS2
*
* SHAZAM Procedure to perform Non Negative Least Squares for 2 variables
*
* INPUTS:     [YIN]
*             [XIN]
*             [STARTIN]
*
* OUTPUTS:    [BETAOUT]
*
PROC NNLS2

  MATRIX X1_=[XIN](0,1)
  GENR X1_=X1_
  MATRIX X2_=[XIN](0,2)
  GENR X2_=X2_

  NL 1 / NCOEF=[VARSIN] START=[STARTIN] GENRVAR
  EQ [YIN]=(B1_*B1_)*X1_+(B2_*B2_)*X2_
  END

  GENR B11_=B1_*B1_
  GENR B22_=B2_*B2_
  MATRIX [BETAOUT](1,1)=B11_
  MATRIX [BETAOUT](2,1)=B22_

PROCEND

Yes, this can be done.

Specifying The simplest way is to specify the equation on the NL command like

EQ Y = a + (b*b)*X

will make the coefficient on X always positive because b*b is always zero or positive.

A You could also create a SHAZAM procedure using the PROC (procedure) command which for two variables might look like this:

* PROC NNLS2
*
* SHAZAM Procedure to perform Non Negative Least Squares for 2 variables
*
* INPUTS:     [YIN]
*             [XIN]
*             [STARTIN]
*
* OUTPUTS:    [BETAOUT]
*
PROC NNLS2

  MATRIX X1_=[XIN](0,1)
  GENR X1_=X1_
  MATRIX X2_=[XIN](0,2)
  GENR X2_=X2_

  NL 1 / NCOEF=[VARSIN] START=[STARTIN] GENRVAR
  EQ [YIN]=(B1_*B1_)*X1_+(B2_*B2_)*X2_
  END

  GENR B11_=B1_*B1_
  GENR B22_=B2_*B2_
  MATRIX [BETAOUT](1,1)=B11_
  MATRIX [BETAOUT](2,1)=B22_

PROCEND