[R] Hmisc summary.formula formats for binary and continuous variables
Frank Harrell
f.harrell at vanderbilt.edu
Sun Mar 27 19:20:02 CEST 2011
If by 35 (10%) you mean that 35 is the numerator, this is not such a good
idea. That's because it emphasizes something that is not a scientific
quantity. A scientific quantity is something that has a meaning outside the
current sample. The numerator is dependent on the denominator.
Regarding the other formatting issue, summary.formula with method='reverse'
is not flexible enough to allow that.
Frank
Kwok, Heemun wrote:
>
> Hello,
> I am using Hmisc summary.formula, latex and Sweave to produce tables for
> publication. Is it possible to change the formats for binary and
> continuous variables? I would prefer to show 35 (10%) and 1.5 (1.2-1.8)
> rather than 10% (35) and 1.2 / 1.5 / 1.8. Here is a simple example:
>
> sex <- factor(sample(c("m","f"), 500, rep=TRUE))
> age <- rnorm(500, 50, 5)
> treatment <- factor(sample(c("Drug","Placebo"),
> 500, rep=TRUE))
>
> s1 <- summary(~sex + age)
> s2 <- summary(treatment ~ sex + age, method="reverse")
> print(s1); print(s2)
>
> Descriptive Statistics (N=500)
>
> +-------+-----------------+
> | | |
> +-------+-----------------+
> |sex : m| 46% (232) |
> +-------+-----------------+
> |age |47.22/50.31/53.37|
> +-------+-----------------+
>
>
>
> Descriptive Statistics by treatment
>
> +-------+-----------------+-----------------+
> | |Drug |Placebo |
> | |(N=257) |(N=243) |
> +-------+-----------------+-----------------+
> |sex : m| 47% (122) | 45% (110) |
> +-------+-----------------+-----------------+
> |age |47.35/50.00/52.68|46.78/50.92/53.97|
> +-------+-----------------+-----------------+
>
> Thanks,
> Heemun
>
>
> -------------------------------------------------
> Heemun Kwok, M.D.
> Research Fellow
> Harbor-UCLA Department of Emergency Medicine
> 1000 West Carson Street, Box 21
> Torrance, CA 90509-2910
> office 310-222-3501, fax 310-212-6101
>
> ______________________________________________
> 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 Harrell
Department of Biostatistics, Vanderbilt University
--
View this message in context: http://r.789695.n4.nabble.com/Hmisc-summary-formula-formats-for-binary-and-continuous-variables-tp3408967p3409563.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list