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)
load(GROCERDIR+'/data/smpt.dat') r=nls('smptr/lagts(smptr)-1=a1+a2*(lagts(smptr)/lagts(2,smptr)-1-a1)') // 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). r=nls('smptr/lagts(smptr)-1=b1+b2*(lagts(smptr)/lagts(2,smptr)-1-b1)','coef=[b1 ;b2])' ) // the same as above, except that the names of the coefficients are not numbered 'a', so must be declared r=nls('smptr/lagts(smptr)-1=a1+a2*(lagts(smptr)/lagts(2,smptr)-1-a1)','init=rand(2,1),''normal''') // the same as above, except that the names of the coefficients are not numbered 'a', so must be declared bounds('1980a','1999a'); r=nls('smptr/lagts(smptr)-1=a1+a2*(lagts(smptr)/lagts(2,smptr)-1-a1)') // same as before except that the bounds are explicitely defined [r]=nls('smptr/lagts(smptr)-1=a1+a2*(lagts(smptr)/lagts(2,smptr)-1-a1)','init=[0.5;0.5]','maxit=1000') // same as before except that starting values are set to [0.5 ;0.5] and that the maximum # of iterations is set to 1000. 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)' // same as before except that it uses the vector representation of the ts (trickier, but quicker). | ![]() | ![]() |