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 77 78 79 80 81 82 83 84 85
|
\name{withSE}
\alias{withSE}
\alias{withVCov}
\alias{withVCov.lm}
\alias{vcov.withVCov}
\alias{summary.withVCov}
\alias{summary.withVCov.lm}
\title{Add Alternative Variance Estimates to Models Estimates}
\description{
A simple object-orientation infrastructure to add alternative standard
errors, e.g. sandwich estimates or New-West standard errors to
fitted regression-type models, such as fitted by \code{lm()} or \code{glm()}.
}
\usage{
withSE(object, vcov, \dots)
withVCov(object, vcov, \dots)
\method{withVCov}{lm}(object, vcov, \dots)
\method{summary}{withVCov}(object, \dots)
\method{summary}{withVCov.lm}(object, \dots)
}
\arguments{
\item{object}{a fitted model object}
\item{vcov}{a function that returns a variance matrix estimate, a
given matrix that is such an estimate, or a character string that
identifies a function that returns a variance matrix estimate
(e.g. \code{"HAC"} for \code{vcovHAC}).
}
\item{\dots}{further arguments, passed to \code{vcov()} or, respectively,
to the parent method of \code{summary()} }
}
\details{
Using \code{withVCov()} an alternative variance-covariance matrix is
attributed to a fitted model object. Such a matrix may be produced by
any of the variance estimators provided by the "sandwich" package or
any package that extends it.
\code{withVCov()} has no consequences on how a fitted model itself is
printed or represented, but it does have consequences what standard
errors are reported, when the function \code{summary()} or the function
\code{mtable()} is applied.
\code{withSE()} is a convenience front-end to \code{withVCov()}. It can
be called in the same way as \code{withVCov}, but also allows to specify
the type of variance estimate by a character string that identifies
the function that gives the covariance matrix (e.g. \code{"OPG"} for
\code{vcovOPG}).
}
\value{
\code{withVCov} returns a slightly modified model object: It adds an
attribute named ".VCov" that contains the alternate covaraince matrix
and modifies the class attribute. If e.g. the original model object has class
"lm" then the model object modified by \code{withVCov} has the class
attribute \code{c("withVCov.lm", "withVCov", "lm")}.
}
\examples{
## Generate poisson regression relationship
x <- sin(1:100)
y <- rpois(100, exp(1 + x))
## compute usual covariance matrix of coefficient estimates
fm <- glm(y ~ x, family = poisson)
library(sandwich)
fmo <- withVCov(fm,vcovOPG)
vcov(fm)
vcov(fmo)
summary(fm)
summary(fmo)
mtable(Default=fm,
OPG=withSE(fm,"OPG"),
summary.stats=c("Deviance","N")
)
vo <- vcovOPG(fm)
mtable(Default=fm,
OPG=withSE(fm,vo),
summary.stats=c("Deviance","N")
)
}
|