nls — non linear least squares
[rnls]=nls(eq [,option_1, ,option_n])
eq = a string representing the equation to estimate
option_i =
- 'coef=[namecoef1;namecoef2; ;namecoefn]' with namecoefi = name of the coefficient # i (default coef=['a1';'a2'; ;'an'])
- 'init=[init1;init2; ;intin] if the user wants to give starting values
- any option of maxlik (see maxlik() for a list)
rnsls= a tlist with
- rnls('meth') = 'nls'
- rnls('beta') = bhat
- rnls('nobs') = nobs
- rnls('nvar') = nvars
- rnls('beta') = bhat
- rnls('resid') = residuals
- rnls('vcovar') = estimated variance-covariance matrix of beta
- rnls('sige') = estimated variance of the residuals
- rnls('sigu') = sum of squared residuals
- rnls('ser') = standard error of the regression
- rnls('tstat') = t-stats
- rnls('pvalue') = pvalue of the betas
- rnls('dw') = Durbin-Watson Statistic
- rnls('prests') = boolean indicating the presence or absence of a time series in the regression
- rnls('namey') = the equation
- rnls('namex') = name of the coefficients
- rnls('bounds') = if there is a timeseries in the regression, the bounds of the regression
- rnls('ropt') = the output tlist from maxlik (see maxlik for the list of arguments)
All these examples use the ts smptr in the database smpt.dat. smptr is an annual timeseries, from 1978 to 1999. 1) r=nls('smptr/lagts(smptr)-1=a1+a2*(lagts(smptr)/lagts(2,smptr)-1-a1)') 2) r=nls('smptr/lagts(smptr)-1=a1+a2*(lagts(smptr)/lagts(2,smptr)-1-a1','coef=[a1 ;a2])' ) 3) r=nls('smptr/lagts(smptr)-1=a1+a2*(lagts(smptr)/lagts(2,smptr)-1-a1)','init=rand(2,1,''normal''') 4) bounds('1980a','1999a'); r=nls('smptr/lagts(smptr)-1=a1+a2*(lagts(smptr)/lagts(2,smptr)-1-a1)') 5) r=nls('smptr/lagts(smptr)-1=a+b*(lagts(smptr)/lagts(2,smptr)-1-a1)','coef=[a;b]' ) 6)[r]=nls('smptr/lagts(smptr)-1=a1+a2*(lagts(smptr)/lagts(2,smptr)-1-a1)','init=[0.5;0.5]','maxit=1000') 7) s=series(smptr) ; s0=s(3:22) ; s1=s(2:21) ; s2=s(1:20) ;r=nls('s0./s1-1=a1+a2*(s1./s2-1-a1)' Examples 1 to 4 are strictly equivalent: they provide the estimation of the equation 'smptr/lagts(smptr)-1=a1+a2*(lagts(smptr)/lagts(2,smptr)-1-a1)' over the period 1980-1999 (note that since there are 2 lags in the equation, the bounds are adjusted to withdraw the first 2 years of smptr), starting with random values (note the double quotes before and the triple quotes after normal). Example 5 does the same as examples 1 to 4, except that the coefficient are named a and b. Example 6 does the same as examples 1 to 4, except that starting values are set to [0.5 ;0.5] and that the maximum # of iterations is set to 1000. Example 7 does the same as examples 1 to 4, except that it uses the vector representation of the ts (trickier, but quicker).