[R] Latex problem in Hmisc (3.8-1) and Mac Os X with R 2.11.1
Frank E Harrell Jr
f.harrell at Vanderbilt.Edu
Fri Jun 18 15:19:39 CEST 2010
On 06/18/2010 12:32 AM, moleps islon wrote:
> Dear all,
>
> I did post this more or less identical mail in a follow up to another
> question I posted, but under another heading. I try again, but now
> under the correct header.
>
>
> upon running this code (from the Hmisc library-latex function) I
> believe the call to summary.formula is allright and produces wonderful
> tables, but the latex command results in a correct formatted table but
> where all the numbers and the test columns are wrong. I've pasted in
> both the R code and the resulting latex code annotated with comments
> from the run. Does the same code produce correct cell-entries in other
> installation ?
>
> //M
I could reproduce your problem. We'll get to work on it.
Frank
>
>
>
> library(Hmisc)
>
> options(digits=3)
> set.seed(173)
> sex<- factor(sample(c("m","f"), 500, rep=TRUE))
> age<- rnorm(500, 50, 5)
> treatment<- factor(sample(c("Drug","Placebo"), 500, rep=TRUE))
> symp<- c('Headache','Stomach Ache','Hangnail',
> 'Muscle Ache','Depressed')
> symptom1<- sample(symp, 500,TRUE)
> symptom2<- sample(symp, 500,TRUE)
> symptom3<- sample(symp, 500,TRUE)
> Symptoms<- mChoice(symptom1, symptom2, symptom3, label='Primary Symptoms')
> table (Symptoms)
> table(symptom1,symptom2)
> f<- summary(treatment ~ age + sex + Symptoms, method="reverse", test=TRUE)
> g<- summary(treatment ~ age + sex + symptom1, method="reverse", test=TRUE)
>
> latex(g)
>
>> latex(g,file="")
> % latex.default(cstats, title = title, caption = caption, rowlabel =
> rowlabel, col.just = col.just, numeric.dollar = FALSE,
> insert.bottom = legend, rowname = lab, dcolumn = dcolumn,
> extracolheads = extracolheads, extracolsize = Nsize, ...)
> %
> \begin{table}[!tbp]
> \caption{Descriptive Statistics by treatment\label{g}}
> \begin{center}
> \begin{tabular}{lccc}\hline\hline
> \multicolumn{1}{l}{}&\multicolumn{1}{c}{Drug}&\multicolumn{1}{c}{Placebo}&\multicolumn{1}{c}{Test
> Statistic}\tabularnewline
>
> &\multicolumn{1}{c}{{\scriptsize
> $N=263$}}&\multicolumn{1}{c}{{\scriptsize $N=237$}}&\tabularnewline
> \hline
> age&1&1&4\tabularnewline
> sex~:~m&6&7&2\tabularnewline
> symptom1~:~Depressed&4&3&3\tabularnewline
> ~~~~Hangnail&5&6&1\tabularnewline
> ~~~~Headache&4&2&1\tabularnewline
> ~~~~Muscle~Ache&3&5&1\tabularnewline
> ~~~~Stomach~Ache&2&4&1\tabularnewline
> \hline
> \end{tabular}
>
> \end{center}
>
> \noindent {\scriptsize $a$\ }{$b$\ }{\scriptsize $c$\ } represent the
> lower quartile $a$, the median $b$, and the upper quartile $c$\ for
> continuous variables.\\Numbers after percents are
> frequencies.\\\indent Tests used:\\\textsuperscript{\normalfont
> 1}Wilcoxon test; \textsuperscript{\normalfont 2}Pearson test
> \end{table}
>
>
> ###Then I did another example from Harrell´s "statistical tables and plots...."
>
> rm(list=ls())
>
>
>
> library(Hmisc)
> getHdata(prostate)
> # Variables in prostate had units in ( ) inside variable labels. Move
> # these units of measurements to separate units attributes
> # wt is an exception. It has ( ) in its label but this does not denote units
> # Also make hg have a legal R plotmath expression
> prostate<-upData(prostate, moveUnits=TRUE,units=c(wt="",
> hg="g/100*ml"),labels=c(wt="Weight Index = wt(kg)-ht(cm)+200"))
>
> attach(prostate)
> stage<- factor(stage, 3:4, c("Stage 3","Stage 4"))
> s6<-summary(stage~rx+age+wt+pf+hx+sbp+dbp+ekg+hg+sz+sg+ap+bm,method="reverse",
> overall=TRUE, test=TRUE)
> options(digits=2)
> w<-latex(s6, size="smaller[3]", outer.size="smaller",
> Nsize="smaller",long=TRUE, prmsd=TRUE,
> msdsize="smaller",middle.bold=TRUE, ctable=TRUE)
>
>
> ##This refused to run ( as long as the ctable=T was included), but without it
>
> latex (s6)
>
> ##I do get a nicely formated table, but again the numbers are all wrong... Also
>
> ##latex(s6, long=TRUE, prmsd=TRUE, msdsize="smaller",middle.bold=TRUE)
>
> ##makes no difference from latex(s6) alone with regards to formatting...
>
>
>
> Quite frustrating-Any suggestions??
>
>
> //M
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Frank E Harrell Jr Professor and Chairman School of Medicine
Department of Biostatistics Vanderbilt University
More information about the R-help
mailing list