[R] Some matrix and sandwich questions

Michael Ash mash at econs.umass.edu
Tue Oct 30 14:34:37 CET 2007


Dear R-help,

I have a four-part question about regression, matrices, and sandwich package.


1) In the sandwich package, I would like to better understand the
meat() function.
>From the bread() documentation, for a simple OLS regression, bread() returns

(1/n * X'X)^(-1)

That is, for a simple regression (per the documentation on bread()):
MyLM <- lm(y ~ x)
bread(MyLM)
solve(crossprod(cbind(1, x))) * length(y)
(The last two terms above produce the same output, the matrix described above.)

In terms of the basic data matrix and coefficients, what does meat()
return for a simple OLS regression?  (I don't know the term "empirical
estimating functions" from the documentation of meat(). Is this the
score vector set equal to zero?)


2) Is there an easy way to convert the right-hand side of a formula
into the X matrix used for the regresssion:

lm( y ~ x + factor(i) )

Is there an easy way to get a matrix like this:

X = cbind(vector of 1's, x, matrix of 1's and 0's for the dummy
variables based on i)

Obviously one could construct this by hand, but it seems as if "the X
used for the  regression" would be useful.



3) Is there an easy way, e.g., based on crossprod(), to compute a
weighted cross-product of a matrix with itself or of two matrices:

X'WX

X'WY

where W is a diagonal weighting matrix?
(This would be similar to the "matrix accum" commands in Stata if that
gives any useful guidance regarding the desired entity.)


4) Is there a straightforward way to implement the computation of the
variance covariance matrix for two-step estimation per Murphy and
Topel (1985)?  That aim is the underlying reason for questions
(1)-(3).


Thank you very much for your consideration.

Best,
Michael

--
Michael Ash, Associate Professor
  of Economics and Public Policy
Department of Economics and CPPA
University of Massachusetts
Amherst, MA 01003
Tel +1-413-545-6329 Fax +1-413-545-2921
Email mash at econs.umass.edu
http://people.umass.edu/maash



More information about the R-help mailing list