[R] using latex() in R for Unix

Paul Johnson pauljohn32 at gmail.com
Fri May 5 06:26:58 CEST 2006


This thread piqued my interest in how to use Hmisc latex() to produce
the tables that I actually want, rather than the ones that come out by
default.  Actually, I'd be glad to use R2HTML or any other tool if I
can make the output suit my taste.

 Here's a small working example that does not require any special libraries.


x <- rnorm(100)
y <- rnorm(100)
 mylm <- lm(y~x)
 Estimates <- cbind(coef(mylm), sqrt(diag(vcov(mylm))))
 colnames(Estimates) <- c("OLS estimate","std. error")
 rownames(Estimates) <- c("Intercept","Education")
 latex(Estimates,file="/home/pauljohn/test4.tex",digits=4)

That creates the top part of the table like I want it, except there
are no stars on the standard errors.

I want to add the diagnostic information, sample size, the R-square,
and root mean square error:

sumobj <- summary(mylm)
## tedious pasting alert:
sumStat <- paste("N=  ",sum(sumobj$df[-1]), ", R^2 =", 
sumobj$r.squared, ", RMSE = ", sumobj$sigma)

# The following does not have the desired effect because it creates
and appends a whole new table

latex(sumStat, file="/home/pauljohn/test4.tex", append=T)

How can I "snug up" sumStat right at the end of the table?

pj


On 4/5/06, Frank E Harrell Jr <f.harrell at vanderbilt.edu> wrote:
> Peter Dalgaard wrote:
> > "Brian Quinif" <bquinif at gmail.com> writes:
> >
> >
> >>Yes, Peter, I do mean the later() function from the Hmsic package.
> >>Below is a reproducible example.  Also, does anyone know how to stop R
> >>from automatically running LaTeX on the file produced by latex()
> >
> >
> > The last bit is easy. It's the print method that does that, so just
> > don't print. E.g.
> >
> >  invisible(latex(....))
>
> Or do w <- latex(.., file='...')
>
> Frank
> >
>
>
> --
> Frank E Harrell Jr   Professor and Chair           School of Medicine
>                       Department of Biostatistics   Vanderbilt University
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>


--
Paul E. Johnson
Professor, Political Science
1541 Lilac Lane, Room 504
University of Kansas




More information about the R-help mailing list