estfun.systemfit: Extract Gradients of the Objective Function at each...

estfun.systemfitR Documentation

Extract Gradients of the Objective Function at each Observation

Description

Extract the gradients of the objective function with respect to the coefficients evaluated at each observation (‘Empirical Estimating Function’, see estfun).

Usage

## S3 method for class 'systemfit'
estfun( x, residFit = TRUE, ... )

Arguments

x

an object of class systemfit.

residFit

logical. If FALSE, the residuals are calculated based on observed regressors. If TRUE, the residuals are calculated based on fitted regressors. This argument is ignored if no instrumental variable are used.

...

further arguments (currently ignored).

Value

Matrix of gradients of the objective function with respect to the coefficients evaluated at each observation.

Warnings

The sandwich package must be loaded before this method can be used.

In specific estimations with the 3SLS method, not all columns of the matrix returned by the estfun method sum up to zero, which indicates that an inappropriate estimating function is returned. This can be either with argument residFit set to TRUE or with this argument set to FALSE or even in both cases. This problem depends on the formula used for the 3SLS estimation and seems to be related to unbalanced systems and systems where different instruments are used in different equations.

Author(s)

Arne Henningsen

See Also

estfun, systemfit.

Examples

data( "Kmenta" )
eqDemand <- consump ~ price + income
eqSupply <- consump ~ price + farmPrice + trend
system <- list( demand = eqDemand, supply = eqSupply )
inst <- ~ income + farmPrice + trend

## OLS estimation
fitols <- systemfit( system, "OLS", data = Kmenta )

## obtain the estimation function
library( "sandwich" )
estfun( fitols )

## this is only true for OLS models
all.equal( estfun( fitols ),
   unlist( residuals( fitols ) ) * model.matrix( fitols ) )

# each column should sum up to (approximately) zero
colSums( estfun( fitols ) )


## 2SLS estimation
fit2sls <- systemfit( system, "2SLS", inst = inst, data = Kmenta )

## obtain the estimation function
estfun( fit2sls )

## this is only true for 2SLS models
all.equal( estfun( fit2sls ),
   drop( rep( Kmenta$consump, 2 ) -  model.matrix( fit2sls, which = "xHat" ) %*% 
   coef( fit2sls ) ) * model.matrix( fit2sls, which = "xHat" ) )
all.equal( estfun( fit2sls, residFit = FALSE ),
   unlist( residuals( fit2sls ) ) * model.matrix( fit2sls, which = "xHat" ) )

# each column should sum up to (approximately) zero
colSums( estfun( fit2sls ) )
colSums( estfun( fit2sls, residFit = FALSE ) )


## iterated SUR estimation
fitsur <- systemfit( system, "SUR", data = Kmenta, maxit = 100 )

## obtain the estimation function
estfun( fitsur )

## this should be true for SUR and WLS models
all.equal( estfun( fitsur ),
   unlist( residuals( fitsur ) ) * 
   ( ( solve( fitsur$residCovEst ) %x% diag( nrow( Kmenta ) ) ) %*% 
      model.matrix( fitsur ) ), check.attributes = FALSE )

# each column should sum up to (approximately) zero
colSums( estfun( fitsur ) )


## 3SLS estimation
fit3sls <- systemfit( system, "3SLS", inst = inst, data = Kmenta )

## obtain the estimation function
estfun( fit3sls )
estfun( fit3sls, residFit = FALSE )

## this should be true for 3SLS and W2SLS models
all.equal( estfun( fit3sls ),
   drop( rep( Kmenta$consump, 2 ) -  
   model.matrix( fit2sls, which = "xHat" ) %*% coef( fit3sls ) ) * 
   ( ( solve( fit3sls$residCovEst ) %x% diag( nrow( Kmenta ) ) ) %*% 
      model.matrix( fit3sls, which = "xHat" ) ), check.attributes = FALSE )
all.equal( estfun( fit3sls, residFit = FALSE ),
   unlist( residuals( fit3sls ) ) * 
   ( ( solve( fit3sls$residCovEst ) %x% diag( nrow( Kmenta ) ) ) %*% 
      model.matrix( fit3sls, which = "xHat" ) ), check.attributes = FALSE )

# each column should sum up to (approximately) zero
colSums( estfun( fit3sls ) )
colSums( estfun( fit3sls, residFit = FALSE ) )

systemfit documentation built on March 31, 2023, 9:26 p.m.