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

1
2
## S3 method for class 'systemfit'
estfun( obj, residFit = TRUE, ... )

Arguments

obj

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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 ) )

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.