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:
"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:
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:
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().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")systemfit
builtin package. By default "/fMultivar/demo/funSystemfit.R".data.frame or
timeSeries object."none",
"confidence", or "prediction"."OLS", "WLS", "SUR", "2SLS",
"W2SLS", "3SLS", or "W3SLS".data.frame or
timeSeriesto be predicted.fEQNS.fEQNS.systemfit for the "OLS", "WLS", "SUR", "2SLS",
"W2SLS", "3SLS", or "W3SLS" method.
These include:
eqnlabels -
an optionaeqnsFit returns an object of class "fEQNS"
with the following slots:data.frame or a
timeSeries object.systemfit package."OLS", "WLS", "SUR", "2SLS",
"W2SLS", "3SLS", or "W3SLS".@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:fEQNS. A
one-column data frame of all estimated coefficients.fEQNS.fEQNS.fEQNS.fEQNS.@fit$fit are:TX.b.b.b.b.bt.rcov.systemfit.eq are:k only if there are
restrictions that are not cross-equation).b.b.b.b.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".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}'$lm,
regFit.## 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 SURRun the code above in your browser using DataLab