Fits a set of structural nonlinear equations using Ordinary Least Squares (OLS), Seemingly Unrelated Regression (SUR), TwoStage Least Squares (2SLS), ThreeStage Least Squares (3SLS).
1 2 3 4  nlsystemfit( method="OLS", eqns, startvals,
eqnlabels=c(as.character(1:length(eqns))), inst=NULL,
data=list(), solvtol=.Machine$double.eps,
maxiter=1000, ... )

method 
the estimation method, one of "OLS", "SUR", "2SLS", "3SLS". 
eqns 
a list of structural equations to be estimated. 
startvals 
a list of starting values for the coefficients. 
eqnlabels 
an optional list of character vectors of names for the equation labels. 
inst 
onesided model formula specifying instrumental variables or a list of onesided model formulas if different instruments should be used for the different equations (only needed for 2SLS, 3SLS and GMM estimations). 
data 
an optional data frame containing the variables in the model. By default the variables are taken from the environment from which nlsystemfit is called. 
solvtol 
tolerance for detecting linear dependencies in the columns
of X in the 
maxiter 
the maximum number of iterations for the 
... 
arguments passed to 
The nlsystemfit function relies on nlm
to perform the
minimization of the objective functions and the qr
set
of functions.
A system of nonlinear equations can be written as:
ε_{t} = q( y_t, x_t, θ )
z_{t} = Z( x_t )
where ε_{t} are the residuals from the y observations and the function evaluated at the coefficient estimates.
The objective functions for the methods are:
Method  Instruments  Objective Function  Covariance of θ 
OLS  no  r'r  (X(diag(S)^{1}\bigotimes I)X)^{1} 
SUR  no  r'(diag(S)_{OLS}^{1}\bigotimes I)r  (X(S^{1}\bigotimes I)X)^{1} 
2SLS  yes  r'(I \bigotimes W)r  (X(diag(S)^{1}\bigotimes I)X)^{1} 
3SLS  yes  r'(S_{2SLS}^{1} \bigotimes W)r  (X(diag(S)^{1}\bigotimes W)X)^{1} 
where, r is a column vector for the residuals for each equation, S is variancecovariance matrix between the equations (\hat{σ}_{ij} = (\hat{e}_i' \hat{e}_j) / √{(T  k_i)*(T  k_j)}), X is matrix of the partial derivates with respect to the coefficients, W is a matrix of the instrument variables Z(Z'Z)^{1}Z, Z is a matrix of the instrument variables, and I is an nxn identity matrix.
The SUR and 3SLS methods requires two solutions. The first solution for the SUR is an OLS solution to obtain the variancecovariance matrix. The 3SLS uses the variancecovatiance from a 2SLS solution, then fits all the equations simultaneously.
The user should be aware that the function is VERY sensative to
the starting values and the nlm function may not converge. The nlm
function will be called with the typsize
argument set the
absolute values of the starting values for the OLS and 2SLS
methods. For the SUR and 3SLS methods, the typsize
argument is
set to the absolute values of the resulting OLS and 2SLS coefficient
estimates from the nlm result structre. In addition, the starting
values for the SUR and 3SLS methods are obtained from the OLS and 2SLS
coefficient estimates to shorten the number of iterations. The number of
iterations reported in the summary are only those used in the last
call to nlm, thus the number of iterations in the OLS portion of the
SUR fit and the 2SLS portion of the 3SLS fit are not included.
nlsystemfit
returns a list of the class nlsystemfit.system
and
contains all results that belong to the whole system.
This list contains one special object: "eq". It is a list and contains
one object for each estimated equation. These objects are of the class
nlsystemfit.equation
and contain the results that belong only to the
regarding equation.
The objects of the class nlsystemfit.system
and
nlsystemfit.equation
have the following components (the elements of
the latter are marked with an asterisk (*)):
eq 
a list object that contains a list object for each equation. 
method 
estimation method. 
resids 
an n \times g matrix of the residuals. 
g 
number of equations. 
n 
total number of observations. 
k 
total number of coefficients. 
b 
vector of all estimated coefficients. 
se 
estimated standard errors of 
t 
t values for 
p 
p values for 
bcov 
estimated covariance matrix of 
rcov 
estimated residual covariance matrix. 
drcov 
determinant of 
rcovest 
residual covariance matrix used for estimation (only SUR and 3SLS). 
rcor 
estimated residual correlation matrix. 
nlmest 
results from the nlm function call 
solvetol 
tolerance level when inverting a matrix or calculating a determinant. 
## elements of the class nlsystemfit.eq
eq 
a list that contains the results that belong to the individual equations. 
eqnlabel* 
the equation label of the ith equation (from the labels list). 
formula* 
model formula of the ith equation. 
n* 
number of observations of the ith equation. 
k* 
number of coefficients/regressors in the ith equation. 
df* 
degrees of freedom of the ith equation. 
b* 
estimated coefficients of the ith equation. 
se* 
estimated standard errors of 
t* 
t values for 
p* 
p values for 
covb* 
estimated covariance matrix of 
predicted* 
vector of predicted values of the ith equation. 
residuals* 
vector of residuals of the ith equation. 
ssr* 
sum of squared residuals of the ith equation. 
mse* 
estimated variance of the residuals (mean of squared errors) of the ith equation. 
s2* 
estimated variance of the residuals (\hat{σ}^2) of the ith equation. 
rmse* 
estimated standard error of the residulas (square root of mse) of the ith equation. 
s* 
estimated standard error of the residuals (\hat{σ}) of the ith equation. 
r2* 
Rsquared (coefficient of determination). 
adjr2* 
adjusted Rsquared value. 
Jeff D. Hamann jeff.hamann@forestinformatics.com
Gallant, R. H. (1987) Nonlinear Equation Estimation, John Wiley and Sons, 610 pp.
SAS Institute (1999) SAS/ETS User's Guide, Version 8, Cary NC: SAS Institute 1546 pp.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24  library( systemfit )
data( ppine )
hg.formula < hg ~ exp( h0 + h1*log(tht) + h2*tht^2 + h3*elev + h4*cr)
dg.formula < dg ~ exp( d0 + d1*log(dbh) + d2*hg + d3*cr + d4*ba )
labels < list( "height.growth", "diameter.growth" )
inst < ~ tht + dbh + elev + cr + ba
start.values < c(h0=0.5, h1=0.5, h2=0.001, h3=0.0001, h4=0.08,
d0=0.5, d1=0.009, d2=0.25, d3=0.005, d4=0.02 )
model < list( hg.formula, dg.formula )
model.ols < nlsystemfit( "OLS", model, start.values, data=ppine, eqnlabels=labels )
print( model.ols )
model.sur < nlsystemfit( "SUR", model, start.values, data=ppine, eqnlabels=labels )
print( model.sur )
model.2sls < nlsystemfit( "2SLS", model, start.values, data=ppine,
eqnlabels=labels, inst=inst )
print( model.2sls )
model.3sls < nlsystemfit( "3SLS", model, start.values, data=ppine,
eqnlabels=labels, inst=inst )
print( model.3sls )

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.
All documentation is copyright its authors; we didn't write any of that.