Grocer Function
NAME
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 in
(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().
EXAMPLES
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).
AUTHOR
Eric Dubois 2002