Hello R users, I have several problems with the functions summary.formula and latex in package Hmisc. Here an example :
#### library(Hmisc) sex <- factor(sample(c("m","f", "?"), 50, rep=TRUE)) age <- rnorm(50, 50, 5) treatment <- factor(sample(c("Drug","Placebo"), 50, rep=TRUE)) symp <- c('Headache','Stomach Ache','Hangnail', 'Muscle Ache','Depressed') symptom1 <- sample(symp, 50,TRUE) symptom2 <- sample(symp, 50,TRUE) symptom3 <- sample(symp, 50,TRUE) Symptoms <- mChoice(symptom1, symptom2, symptom3, label='Primary Symptoms') f <- summary(treatment ~ age + sex + Symptoms, method="reverse", test=TRUE) print(f, digits = 5, pdig = 2, pctdig = 3, eps = 0.5, prmsd = F) print(f, digits = 5, pdig = 2, pctdig = 3, eps = 0.5, prmsd = T) latex(f, long = T, pdig = 2, pctdig = 3, eps = 0.5, prmsd = F, file = "") ### Here the problems : - The first print(f, ...) doesn't replace all p-value <0.5 by "P<0.5" : +----------------------------+-------------------------+-------------------------+-----------------------------+ | |Drug |Placebo | Test | | |(N=31) |(N=19) |Statistic | +----------------------------+-------------------------+-------------------------+-----------------------------+ |age | 45.926/48.750/54.019| 47.344/50.728/53.696| F=0.9 d.f.=1,48 P<0.5 | +----------------------------+-------------------------+-------------------------+-----------------------------+ |sex : ? | 25.806% ( 8) | 26.316% ( 5) | Chi-square=0.3 d.f.=2 P=0.86| +----------------------------+-------------------------+-------------------------+-----------------------------+ | f | 38.710% (12) | 31.579% ( 6) | | +----------------------------+-------------------------+-------------------------+-----------------------------+ | m | 35.484% (11) | 42.105% ( 8) | | +----------------------------+-------------------------+-------------------------+-----------------------------+ |Primary Symptoms : Depressed| 41.935% (13) | 63.158% (12) | Chi-square=2.12 d.f.=1 P<0.5| +----------------------------+-------------------------+-------------------------+-----------------------------+ | Hangnail | 48.387% (15) | 42.105% ( 8) |Chi-square=0.19 d.f.=1 P=0.67| +----------------------------+-------------------------+-------------------------+-----------------------------+ | Stomach Ache | 45.161% (14) | 68.421% (13) | Chi-square=2.57 d.f.=1 P<0.5| +----------------------------+-------------------------+-------------------------+-----------------------------+ | Muscle Ache | 54.839% (17) | 26.316% ( 5) | Chi-square=3.89 d.f.=1 P<0.5| +----------------------------+-------------------------+-------------------------+-----------------------------+ | Headache | 51.613% (16) | 36.842% ( 7) | Chi-square=1.03 d.f.=1 P<0.5| +----------------------------+-------------------------+-------------------------+-----------------------------+ - The second print(f, ..., prmsd = T) has the same problem for p-value. There is also 4 decimals in the first line instead of 3 : +----------------------------+------------------------------------------+------------------------------------------+------------------------------------+ | |Drug |Placebo | Test | | |(N=31) |(N=19) |Statistic | +----------------------------+------------------------------------------+------------------------------------------+------------------------------------+ |age |45.9263/48.7501/54.0194 49.1817+/- 5.2751|47.3436/50.7276/53.6963 51.1313+/- 5.5868| F=0.9 d.f.=1,48 P<0.5 | +----------------------------+------------------------------------------+------------------------------------------+------------------------------------+ |sex : ? | 25.806% ( 8) | 26.316% ( 5) | Chi-square=0.3 d.f.=2 P=0.86 | +----------------------------+------------------------------------------+------------------------------------------+------------------------------------+ | f | 38.710% (12) | 31.579% ( 6) | | +----------------------------+------------------------------------------+------------------------------------------+------------------------------------+ | m | 35.484% (11) | 42.105% ( 8) | | +----------------------------+------------------------------------------+------------------------------------------+------------------------------------+ |Primary Symptoms : Depressed| 41.935% (13) | 63.158% (12) | Chi-square=2.12 d.f.=1 P<0.5 | +----------------------------+------------------------------------------+------------------------------------------+------------------------------------+ | Hangnail | 48.387% (15) | 42.105% ( 8) | Chi-square=0.19 d.f.=1 P=0.67| +----------------------------+------------------------------------------+------------------------------------------+------------------------------------+ | Stomach Ache | 45.161% (14) | 68.421% (13) | Chi-square=2.57 d.f.=1 P<0.5 | +----------------------------+------------------------------------------+------------------------------------------+------------------------------------+ | Muscle Ache | 54.839% (17) | 26.316% ( 5) | Chi-square=3.89 d.f.=1 P<0.5 | +----------------------------+------------------------------------------+------------------------------------------+------------------------------------+ | Headache | 51.613% (16) | 36.842% ( 7) | Chi-square=1.03 d.f.=1 P<0.5 | +----------------------------+------------------------------------------+------------------------------------------+------------------------------------+ - In the latex(f, ...), only the first-line p-value is replaced by "< 0.5", and the quantiles for age have too much decimal : % 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{f}} \begin{center} \begin{tabular}{lccc}\hline\hline \multicolumn{1}{l}{}& \multicolumn{1}{c}{Drug}& \multicolumn{1}{c}{Placebo}& \multicolumn{1}{c}{Test Statistic} \\ &\multicolumn{1}{c}{{\scriptsize $N=31$}}&\multicolumn{1}{c}{{\scriptsize $N=19$}}&\\ \hline age&{\scriptsize 45.92627049~}{48.75014585 }{\scriptsize 54.01942542} &{\scriptsize 47.34358486~}{50.72757132 }{\scriptsize 53.69634575} &$ F_{1,48}=0.9 ,~ P<0.5 ^{1} $\\ sex&&&$ \chi^{2}_{2}=0.3 ,~ P=0.859 ^{2} $\\ ~~~~?&25.806\%~{\scriptsize~(~8)}&26.316\%~{\scriptsize~(~5)}&\\ ~~~~f&38.710\%~{\scriptsize~(12)}&31.579\%~{\scriptsize~(~6)}&\\ ~~~~m&35.484\%~{\scriptsize~(11)}&42.105\%~{\scriptsize~(~8)}&\\ Primary~Symptoms&&&\\ ~~~~Depressed&41.935\%~{\scriptsize~(13)}&63.158\%~{\scriptsize~(12)}&$ \chi^{2}_{1}=2.12 ,~ P=0.145 ^{2} $\\ ~~~~Hangnail&48.387\%~{\scriptsize~(15)}&42.105\%~{\scriptsize~(~8)}&$ \chi^{2}_{1}=0.19 ,~ P=0.665 ^{2} $\\ ~~~~Stomach~Ache&45.161\%~{\scriptsize~(14)}&68.421\%~{\scriptsize~(13)}&$ \chi^{2}_{1}=2.57 ,~ P=0.109 ^{2} $\\ ~~~~Muscle~Ache&54.839\%~{\scriptsize~(17)}&26.316\%~{\scriptsize~(~5)}&$ \chi^{2}_{1}=3.89 ,~ P=0.049 ^{2} $\\ ~~~~Headache&51.613\%~{\scriptsize~(16)}&36.842\%~{\scriptsize~(~7)}&$ \chi^{2}_{1}=1.03 ,~ P=0.309 ^{2} $\\ \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: $^{1}$Wilcoxon test; $^{2}$Pearson test \end{table} I would like to understand : - why does option 'pctdig' affect both percentages and quantiles in the 'print' command (pctdig : 'number of digits to the right of the decimal place for *printing percentages*. The default is zero, so percents will be rounded to the nearest percent'); - how can I change the number of decimal for continuous variables in the 'latex' command ? - why doesn't option 'eps' affect all p-value ? I've just discover these wonderfull functions. Thank you to Frank Harrell for this package. DH [[alternative HTML version deleted]] ______________________________________________ R-help@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.