[R] Help using Hmisc / Latex
Frank E Harrell Jr
f.harrell at vanderbilt.edu
Thu Aug 26 16:08:39 CEST 2004
Sorry about non-indenting of quoted text - I haven't figured out a good
way to answer mail when receiving messages in digest mode -FH
--------------------------------------------------------------------
I'm afraid you need to modify your approach. You're trying to pass latex an
lm object, which latex doesn't know how to handle. Also, latex isn't
supposed to produce a full .tex file; it generates just a "core" that's
loaded into a "shell" when you run dvi.
Here's an example of how you might use it appropriately:
l <- latex(summary(lm(b ~ a, data.frame(a = 1:5, b = 1:5)))$coefficients)
d <- dvi(l)
d
If you want the full .tex file, you can read the console output after
running dvi(l) to find out where the .tex tempfile lives and copy it over to
someplace usable. Obviously, you'll have to tweak the row and column names
as well as the rounding to suit your preferences.
If you're just looking for graphical output--not necessarily a .tex file--I
have a function grid.table, now being rolled into a package I will soon
release, which uses grid to place a data frame (neatly) on the graphics
device. You could then wrap the command around a pdf(), postscript() or any
other device to produce an appropriate display. Let me know if you'd like me
to send over my working version of the binaries.
Kevin
-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Joao Pedro W. de
Azevedo
Sent: Wednesday, August 25, 2004 4:02 AM
To: R-help at stat.math.ethz.ch
Subject: [R] Help using Hmisc / Latex
Dear R users,
I'm trying to automatically generate a *.tex file with the output of an OLS
estimation. Some people suggested to use the latex function on the Hmisc
package. I'm having a bit of trouble to properly specify this function (I'm
not a very experienced R user). Below you will find an example, of what I'm
doing.
## Annette Dobson (1990) "An Introduction to Generalized Linear Models".
## Page 9: Plant Weight Data.
summary(lm.D90 <- lm(weight ~ group - 1))# omitting intercept
out <- latex(lm.D90)
latex(out, model1, file="")
When I run this code, I get an output which does not attend my needs.
First, I could not figure out how to print the variable names. Second I'm
not sure how I can select only the coefficients and the std. errors to be
inserted on the output. Third, I was wondering if there is any way I can
automatically generate significance level indicators next to either the
coefficients or the std erros. Forth, is there any way I can aumtomaticaly
insert some of model fitting statistics? Fifth, is it possible to specify
this function to save the std. error under the coefficient?
I'm sure this are quite basic questions, but my attempts to fiddle with the
parameters in the model took me nowhere.
Many thanks once again,
Joao Pedro
-------------------------------------------------------------------------
Good comments Kevin - thanks. Joao to get full latex support you can
use library(Design)'s ols function in place of lm. This is for getting
the fitted model in algebraic form, with factoring out of interaction
terms, simplification of natural splines, etc.
In linux I use a little shell script to view LaTeX code fragments:
~/bin harrelfe:cat latexfxdvi
echo -e
"\\\documentclass{article}\n\\\usepackage{setspace,relsize,ctable,longtable}\n\\\begin{document}\n"
| cat - $1.tex > /tmp/$$.tex
echo "\\end{document}" > /tmp/$$.tmp
pushd /tmp
cat $$.tex $$.tmp > $$2.tex
latex "\scrollmode\input" $$2
xdvi $$2 &
popd
This assumes you have setspace, relsize, ctable installed. These are the
most frequently used non-standard latex packages called for by Hmisc.
--
Frank E Harrell Jr Professor and Chair School of Medicine
Department of Biostatistics Vanderbilt University
More information about the R-help
mailing list