Learn R Programming

fMultivar (version 220.10063)

EquationsModelling: Equations Modelling

Description

A collection and description of easy to use functions to perform fits of systems of regression equations. The underlying functions are those from the contributed R-package systemfit written by Jeff D. Hamann and Arne Henningsen. The package offers functions for fitting linear structural equations using Ordinary Least Squares (OLS), Weighted Least Squares (WLS), Seemingly Unrelated Regression (SUR), Two-Stage Least Squares (2SLS), Weighted Two-Stage Least Squares (W2SLS) or Three-Stage Least Squares (3SLS). The wrapper fullfills the naming conventions of Rmetrics, returns a S4 object named fEQNS, and allows for timeSeries objects as input. In addition a S-Plus like FinMetrics function SUR is made available. The Models Based on 'systemfit' Include: ll{ "OLS" Ordinary Least Square Modelling, "WLS" Weighted Least Square Modelling, "SUR" Seemingly Unrelated Regression, "2SLS" Two-Stage Least Squares, "W2SLS" Weighted Two-Stage Least Squares, "3SLS" Three-Stage Least Squares. } Further Functions and Methods are: ll{ print S3 Print method for objects of class 'fEQNS', summary S3 Summary method for objects of class 'fEQNS', predict S3 Predict method for objects of class 'fEQNS'. } S-Plus like Finmetrics Function: ll{ SUR A S-PLUS like function for "SUR" models. } Note, that the contributed R package systemfit is required! If the package systemfit is not installed on your computer or not availalble for your operating system, then you can load it as builtin function calling the internal Rmetrics function systemfitBuiltin().

Usage

eqnsFit(formulas, data = list(), method = c("OLS", "WLS", "SUR", "2SLS", 
	"W2SLS", "3SLS", "W3SLS"), title = NULL, description = NULL, ...)

## S3 method for class 'fEQNS':
predict(object, newdata = object@data, se.fit = FALSE, 
    se.pred = FALSE, interval = "none", ci = 0.95, \dots)

## S3 method for class 'fEQNS':
print(x, \dots)
## S3 method for class 'fEQNS':
summary(object, \dots)

## S3 method for class 'fEQNS':
coef(object, \dots)
## S3 method for class 'fEQNS':
fitted(object, \dots)
## S3 method for class 'fEQNS':
residuals(object, \dots)
## S3 method for class 'fEQNS':
vcov(object, \dots)

SUR(formulas, data = list(), ...)

systemfitBuiltin(builtin = "/fMultivar/demo/funSystemfit.R")

Arguments

builtin
a character string giving the path and name of the systemfit builtin package. By default "/fMultivar/demo/funSystemfit.R".
ci
[predict] - the confidence interval, by default 0.95.
formulas
[eqnsFit] - the list of formulas describing the system of equations.
data
[eqnsFit] - the input data set in form of a data.frame or timeSeries object.
description
[eqnsFit] - a character string which allows for a brief description.
interval
[predict] - Type of interval calculation, one of "none", "confidence", or "prediction".
method
[eqnsFit] - a character string describing the desired method, one of: "OLS", "WLS", "SUR", "2SLS", "W2SLS", "3SLS", or "W3SLS".
newdata
[predict] - a new input data set in form of a data.frame or timeSeriesto be predicted.
object
[predict][summary] - [coef][fitted][residuals][vcov] - an object of class fEQNS.
se.fit
[predict] - a logical, should the standard error of the fitted values be returned?
se.pred
[predict] - a logical, should the standard error of the prediction be returned?
title
[eqnsFit] - a character string which allows for a project title.
x
[plot][print] - an object of class fEQNS.
...
[systemFit] - additional optional arguments to be passed to the underlying function systemfit for the "OLS", "WLS", "SUR", "2SLS", "W2SLS", "3SLS", or "W3SLS" method. These include: eqnlabels - an optiona

Value

  • Fit: Parameter Estimation The function eqnsFit returns an object of class "fEQNS" with the following slots:
  • @callthe matched function call.
  • @datathe input data in form of a data.frame or a timeSeries object.
  • @descriptiona character string which allows for a brief project description.
  • @fita summary of the results as a list returned from the underlying functions from the systemfit package.
  • @formulasthe list of formulas describing the system of equations.
  • @methoda character string describing the desired method, one of: "OLS", "WLS", "SUR", "2SLS", "W2SLS", "3SLS", or "W3SLS".
  • @titlea character string which allows for a project title.
  • The @fit slot is a list with entries returned from the underlying fitting function. The function returns a list of class code{systemfit}. The list contains one special object: eq. This object is also a list and contains one object for each estimated equation. These objects are of the class systemfit.equation and contain the results that belong only to the regarding equation. The objects of the class systemfit and systemfit.equation have the following components (the elements of the latter are marked with an asterisk ($*$)): The major elements of the list are:
  • coefthe coefficients from an object of class fEQNS. A one-column data frame of all estimated coefficients.
  • confintthe confidence intervals of the coefficients of one equation from an object of class fEQNS.
  • fittedthe fitted values of all equations from an object of class fEQNS.
  • residualsthe residuals from an object of class fEQNS.
  • vcovthe variance covariance matrix of all coefficients from an object of class fEQNS.
  • The remaining elements of the slot @fit$fit are:
  • methodestimation method.
  • gnumber of equations.
  • ntotal number of observations.
  • ktotal number of coefficients.
  • kitotal number of linear independent coefficients.
  • dfdegrees of freedom of the whole system.
  • iternumber of iteration steps.
  • bvector of all estimated coefficients.
  • btcoefficient vector transformed by TX.
  • seestimated standard errors of b.
  • tt values for b.
  • pp values for b.
  • bcovestimated covariance matrix of b.
  • btcovcovariance matrix of bt.
  • rcovestimated residual covariance matrix.
  • drcovdeterminant of rcov.
  • rcovestresidual covariance matrix used for estimation, only "SUR" and "3SLS".
  • rcorestimated residual correlation matrix.
  • olsr2System OLS R-squared value.
  • mcelr2McElroys R-squared value for the system, only "SUR" and "3SLS".
  • yvector of all (stacked) endogenous variables.
  • xmatrix of all (diagonally stacked) regressors.
  • hmatrix of all (diagonally stacked) instrumental variables, only "2SLS" and "3SLS".
  • datadata frame of the whole system including instruments.
  • R.restrthe restriction matrix.
  • q.restrthe restriction vector.
  • TXmatrix used to transform the regressor matrix.
  • maxitermaximum number of iterations.
  • toltolerance level indicating when to stop the iteration.
  • rcovformulaformula to calculate the estimated residual covariance matrix.
  • formula3slsformula for calculating the "3SLS" estimator.
  • probdfsyssystem degrees of freedom to calculate prob values?
  • single.eq.sigmadifferent $\sigma^2$s for each single equation?
  • solvetoltolerance level when inverting a matrix or calculating a determinant.
  • The elements of the class systemfit.eq are:
  • eqa list that contains the results that belong to the individual equations.
  • eqnlabel*the equation label of the i-th equation (from the labels list).
  • formula*model formula of the i-th equation.
  • inst*instruments of the i-th equation, only 2SLS and 3SLS.
  • n*number of observations of the i-th equation.
  • k*number of coefficients/regressors in the i-th equation (including the constant).
  • ki*number of linear independent coefficients in the i-th equation (including the constant differs from k only if there are restrictions that are not cross-equation).
  • df*degrees of freedom of the i-th equation.
  • b*estimated coefficients of the i-th equation.
  • se*estimated standard errors of b.
  • t*t values for b.
  • p*p values for b.
  • covb*estimated covariance matrix of b.
  • y*vector of endogenous variable (response values) of the i-th equation.
  • x*matrix of regressors (model matrix) of the i-th equation.
  • h*matrix of instrumental variables of the i-th equation, only "2SLS" and "3SLS".
  • data*data frame (including instruments) of the i-th equation.
  • fitted*vector of fitted values of the i-th equation.
  • residuals*vector of residuals of the i-th equation.
  • ssr*sum of squared residuals of the i-th equation.
  • mse*estimated variance of the residuals (mean of squared errors) of the i-th equation.
  • s2*estimated variance of the residuals ($\hat{\sigma}^2$) of the i-th equation.
  • rmse*estimated standard error of the residulas (square root of mse) of the i-th equation.
  • s*estimated standard error of the residuals ($\hat{\sigma}$) of the i-th equation.
  • r2*R-squared (coefficient of determination).
  • adjr2*adjusted R-squared value.
  • S3 Methods: The output from the S3 summary method prints the results in form of a detailed report together with optional plots. The output from the S3 print method prints on object of class fEQNS. The output from the S3 plot method returns some diagnostic plots. S-Plus like SUR Function: The function SUR returns an object of class "fEQNS" with the same slots returned by the function eqnsFit for method "SUR".

Details

Ordinary Least Squares (OLS) estimates are biased and inconsistent when endogenous variables appear as regressors in other equations in the system. Furthermore, one observes that the errors of a set of related regression equations are often correlated. Then the efficiency of the estimates can in many cases be improved including the correlations into the parameter estimation procedure. The function eqnaFit provides several methods which can produce consistent and asymptotically efficient estimates for systems of regression equations. The variables in a system of equations can be characterized by four types. These include Endogenous Variables which are the variables determined by the system, Exogenous Variables which are independent variables that do not depend on any of the endogenous variables in the system, Predetermined Variables which include both the exogenous variables and lagged endogenous variables, which are past values of endogenous variables determined at previous time periods, and Instrumental Variables which are are predetermined variables used in obtaining predicted values for the current period endogenous variables by a first-stage regression. The use of instrumental variables characterizes estimation methods such as two-stage least squares and three-stage least squares. Instrumental variables estimation methods substitute these first-stage predicted values for endogenous variables when they appear as regressors in model equations. Technical Details: 'systemfit' The matrix TX transforms the regressor matrix ($X$) by $X^{*} = X *$ TX. Thus, the vector of coefficients is now $b =$ TX $\cdot b^{*}$, where $b$ is the original (stacked) vector of all coefficients and $b^{*}$ is the new coefficient vector that is estimated instead. Thus, the elements of vector $b$ are $b_i = \sum_j TX_{ij} \cdot b^{*}_j$. The TX matrix can be used to change the order of the coefficients and also to restrict coefficients (if TX has less columns than it has rows). However restricting coefficients by the TX matrix is less powerfull and flexible than the restriction by providing the R.restr matrix and the q.restr vector. The advantage of restricting the coefficients by the TX matrix is that the matrix that is inverted for estimation gets smaller by this procedure, while it gets larger if the restrictions are imposed by R.restr and q.restr. If iterated (WLS, SUR, W2SLS or 3SLS estimation with maxit>1), the convergence criterion is $\sqrt{ \sum_i (b_{i,g} - b_{i,g-1})^2 \left/ \sum_i b_{i,g-1}^2 \right. }$ < tol. Here, $b_{i,g}$ is the ith coefficient of the g-th iteration step. The formula to calculate the estimated covariance matrix of the residuals, $\hat{\Sigma}$, can be one of the following, see Judge et al., 1985, p. 469: if rcovformula=0: $\hat{\sigma}_{ij} = (\hat{e}_i' \hat{e}_j) / T$; if rcovformula=1: $\hat{\sigma}_{ij} = (\hat{e}_i' \hat{e}_j) / \sqrt{(T - k_i)*(T - k_j)}$; if rcovformula=2: $\hat{\sigma}_{ij} = (\hat{e}_i' \hat{e}_j) / (T - k_i - k_j + tr[(X_i'X_i)^{-1}X_i'X_j(X_j'X_j)^{-1}X_j'X_i]$. If $k_i = k_j$, formula 1 and 2 are equal and yield an unbiased estimator for the residual covariance matrix. If $k_i \neq k_j$, only formula 2 yields an unbiased estimator for the residual covariance matrix, but it is not neccessarily positive semidefinit and its inverse is not an unbiased estimator for the inverse of the residual covariance matrix. Thus, it is doubtful whether formula 2 is really superior to formula 1, see Theil, 1971, p. 322. The formulas to calculate the 3SLS estimator lead to identical results if the same instruments are used in all equations. If different instruments are used in the different equations, only the GMM-3SLS estimator, "GMM" and the 3SLS estimator proposed by Schmidt (1990), "Schmidt" are consistent, whereas "GMM" is efficient relative to "Schmidt", see Schmidt, 1990. Prediction: The variance of the fitted values, used to calculate the standard errors of the fitted values and the confidence interval, is calculated by $Var[E[y^0]-\hat{y}^0]=x^0 \; Var[b] \; {x^0}'$ an the variances of the predicted values, used to calculate the standard errors of the predicted values and the prediction intervals, is calculated by $Var[y^0-\hat{y}^0]=\hat{\sigma}^2+x^0 \; Var[b] \; {x^0}'$

References

Greene W.H., (1993); Econometric Analysis, Second Edition, Macmillan. Greene W.H., (2002); Econometric Analysis Fifth Edition, Prentice Hall. Judge G.G., Griffiths W.E., Hill R.C, L�tkepohl H., Lee T.C., (1985); The Theory and Practice of Econometrics, Second Edition, Wiley. Kmenta J., (1997); Elements of Econometrics, Second Edition, University of Michigan Publishing. Schmidt P., (1990); Three-Stage Least Squares with different Instruments for different equations, Journal of Econometrics 43, p. 389--394. Theil H., (1971); Principles of Econometrics, Wiley, New York.

See Also

lm, regFit.

Examples

Run this code
## SOURCE("fMultivar.B3-EquationsModelling")

## Note, "systemfit" is required:
   SYSTEMFIT = require(systemfit)
   if (SYSTEMFIT) {
   
## Examples from the 'systemfit' Package:
   data(kmenta)
   
## OLS Estimations:   
   formulas = list(demand = q ~ p + d, supply = q ~ p + f + a )
   FITOLS = eqnsFit(formulas, data = kmenta)
   FITOLS
   
## OLS Estimation with 2 Restrictions:
   Rrestr <- matrix(0, 2, 7)
   qrestr <- matrix(0, 2, 1)
   Rrestr[1,3] =  1
   Rrestr[1,7] = -1
   Rrestr[2,2] = -1
   Rrestr[2,5] =  1
   qrestr[2,1] =  0.5
   FITOLS2 = eqnsFit(formulas, data = kmenta, R.restr = Rrestr, 
     q.restr = qrestr)
   FITOLS2
   
## Iterated SUR Estimation:
   FITSUR = eqnsFit(formulas, data = kmenta, method = "SUR", maxit = 100)
   FITSUR
   # Coefficients, Fitted Values, Residuals and Variance-Covariance Matrix:
   # Call by Method:
   coef(FITSUR)
   fitted(FITSUR)
   residuals(FITSUR)
   vcov(FITSUR)

## 2SLS Estimation:
   inst = ~ d + f + a
   FIT2SLS = eqnsFit(formulas, data = kmenta, method = "2SLS", inst = inst)
   FIT2SLS
   # Coefficients, Fitted Values, Residuals and Variance-Covariance Matrix:
   # Call by Slot:
   FIT2SLS@fit$coef
   FIT2SLS@fit$fitted
   FIT2SLS@fit$residuals
   FIT2SLS@fit$vcov

## 2SLS Estimation with Different Instruments in Each Equation:
   insts = list( ~ d + f, ~ d + f + a)
   FIT2SLS2 = eqnsFit(formulas, data = kmenta, method = "2SLS", inst = insts)
   FIT2SLS2

## 3SLS Estimation with GMM-3SLS Formula:
   instruments = ~ d + f + a
   FIT3SLS = eqnsFit(formulas, data = kmenta, method = "3SLS", 
   	 inst = instruments, formula3sls = "GMM")
   FIT3SLS
   
   } # if (SYSTEMFIT)
   
## SEE ALSO:
   # Demo File: xmpEqnsGrunfeld.R
   # Estimation of Grunfeld's Model Data with OLS and SUR

Run the code above in your browser using DataLab