I have coeftest
class object that I coded for some purposes that lm
class cannot achieve, but I need to export the object in the way as xtable
(lm
) does. Any idea would be appreciated!
I think this could help you out:
library(AER) # I think coeftest() belongs to this package.
library(Hmisc)
latex(coeftest(model), digits=5)
Where model
is the linear model estimated by lm()
. latex()
is a function from Hmisc
package which is more general than xtable
.
If this is not what you are looking for, then provide some data and the expected result so that we can figure it out.
library(stargazer)
stargazer(model, se=coeftest(model), report=vcs)
model is the linear model. stargazer is, at least in my experience, more general than latex() from Hmisc.
Alternatively, if you want to use xtable, could write down a small function:
library(lmtest)
library(xtable)
xtable.coeftest <- function (x, caption = NULL, label = NULL, align = NULL, digits = NULL,
display = NULL, ...)
{
class(x) <- "matrix"
li<-list(coef=x)
return(xtable:::xtable.summary.lm(li, caption = caption, label = label,
align = align, digits = digits, display = display))
}
example(coeftest)
xtable(coeftest(fm))
It is admittedly not the most elegant (there are two issues, one that it is difficult ot convert a coeftest object, second that xtable.summary.lm uses x$coef instead of coef(x)) but it works!