<< mcov Single equation regressions nwest >>

Grocer >> Single equation regressions > nls

nls

non linear least squares

CALLING SEQUENCE

[rnls]=nls(eq [,option_1,...,option_n])

PARAMETERS

Input

* 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)

 

Output

* 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)

DESCRIPTION

Provides the non linear least squares estimation of a regression, which is given by the string eq. This string must have the form: 'lhs(y,x1,...,xk, coef1, coef2,..., coefn) = rhs(coef1,x1,...,xk,coef2,..., coefn)'. y,x1,...,xk are respectively the endogenous variable and the exogenous ones. They can be time series or vectors. In the first case, the user can have specified the bounds; if she has not, then they are chosen to cover the longest time span. In the second case, vectors must have the same length. The equation must be the first argument of nls. All other arguments can be given in whatever order. The user can specify the name of the coefficients. In that case, the string 'coef = [namecoef1;namecoef2;...;namecoefn]' must be entered in nls. If the user has not given the names of her coefficients, the function assumes that all variables beginning with the character 'a' are coefficients, that the first one is named a1 and that the following ones are a2,... without any discontinuity: you can name your coefficients a1,a2,a3; but not a1,a2,a4. The user can specify starting values for the maximisation program. In that case, the parameter 'init = [init_1;init_2;...;inti_n]' must be entered in nls. If the user does not give starting values, they are drawn from a normal law. Lastly, the user can give all maxlik() options as in maxlik().

EXAMPLE

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).

AUTHOR

Eric Dubois 2002

Report an issue
<< mcov Single equation regressions nwest >>