| 1 |
\name{withSE} |
| 2 |
\alias{withSE} |
| 3 |
\alias{withVCov} |
| 4 |
\alias{withVCov.lm} |
| 5 |
\alias{vcov.withVCov} |
| 6 |
\alias{summary.withVCov} |
| 7 |
\alias{summary.withVCov.lm} |
| 8 |
\title{Add Alternative Variance Estimates to Models Estimates} |
| 9 |
\description{ |
| 10 |
A simple object-orientation infrastructure to add alternative standard |
| 11 |
errors, e.g. sandwich estimates or New-West standard errors to |
| 12 |
fitted regression-type models, such as fitted by \code{lm()} or \code{glm()}. |
| 13 |
} |
| 14 |
\usage{ |
| 15 |
|
| 16 |
withSE(object, vcov, \dots) |
| 17 |
|
| 18 |
withVCov(object, vcov, \dots) |
| 19 |
|
| 20 |
\method{withVCov}{lm}(object, vcov, \dots) |
| 21 |
|
| 22 |
\method{summary}{withVCov}(object, \dots) |
| 23 |
\method{summary}{withVCov.lm}(object, \dots) |
| 24 |
} |
| 25 |
\arguments{ |
| 26 |
\item{object}{a fitted model object} |
| 27 |
\item{vcov}{a function that returns a variance matrix estimate, a |
| 28 |
given matrix that is such an estimate, or a character string that |
| 29 |
identifies a function that returns a variance matrix estimate |
| 30 |
(e.g. \code{"HAC"} for \code{vcovHAC}). |
| 31 |
} |
| 32 |
\item{\dots}{further arguments, passed to \code{vcov()} or, respectively, |
| 33 |
to the parent method of \code{summary()} } |
| 34 |
} |
| 35 |
\details{ |
| 36 |
Using \code{withVCov()} an alternative variance-covariance matrix is |
| 37 |
attributed to a fitted model object. Such a matrix may be produced by |
| 38 |
any of the variance estimators provided by the "sandwich" package or |
| 39 |
any package that extends it. |
| 40 |
|
| 41 |
\code{withVCov()} has no consequences on how a fitted model itself is |
| 42 |
printed or represented, but it does have consequences what standard |
| 43 |
errors are reported, when the function \code{summary()} or the function |
| 44 |
\code{mtable()} is applied. |
| 45 |
|
| 46 |
\code{withSE()} is a convenience front-end to \code{withVCov()}. It can |
| 47 |
be called in the same way as \code{withVCov}, but also allows to specify |
| 48 |
the type of variance estimate by a character string that identifies |
| 49 |
the function that gives the covariance matrix (e.g. \code{"OPG"} for |
| 50 |
\code{vcovOPG}). |
| 51 |
} |
| 52 |
\value{ |
| 53 |
\code{withVCov} returns a slightly modified model object: It adds an |
| 54 |
attribute named ".VCov" that contains the alternate covaraince matrix |
| 55 |
and modifies the class attribute. If e.g. the original model object has class |
| 56 |
"lm" then the model object modified by \code{withVCov} has the class |
| 57 |
attribute \code{c("withVCov.lm", "withVCov", "lm")}. |
| 58 |
} |
| 59 |
\examples{ |
| 60 |
## Generate poisson regression relationship |
| 61 |
x <- sin(1:100) |
| 62 |
y <- rpois(100, exp(1 + x)) |
| 63 |
## compute usual covariance matrix of coefficient estimates |
| 64 |
fm <- glm(y ~ x, family = poisson) |
| 65 |
|
| 66 |
library(sandwich) |
| 67 |
fmo <- withVCov(fm,vcovOPG) |
| 68 |
vcov(fm) |
| 69 |
vcov(fmo) |
| 70 |
|
| 71 |
summary(fm) |
| 72 |
summary(fmo) |
| 73 |
|
| 74 |
mtable(Default=fm, |
| 75 |
OPG=withSE(fm,"OPG"), |
| 76 |
summary.stats=c("Deviance","N") |
| 77 |
) |
| 78 |
|
| 79 |
vo <- vcovOPG(fm) |
| 80 |
|
| 81 |
mtable(Default=fm, |
| 82 |
OPG=withSE(fm,vo), |
| 83 |
summary.stats=c("Deviance","N") |
| 84 |
) |
| 85 |
} |