[R] plotting RR, 95% CI as table and figure in same plot
David Atkins
datkins at u.washington.edu
Mon Apr 19 18:29:48 CEST 2010
Hi all--
I am in the process of helping colleagues write up a ms in which we fit
zero-inflated Poisson models. I would prefer plotting the rate ratios
and 95% CI (as I've found Gelman and others convincing about plotting
tables...), but our journals usually like the numbers themselves.
Thus, I'm looking at a recent JAMA article in which both numbers and
dotplot of RR and 95% CI are presented and wondering about best way to
do this in R.
Essentially, the plot has 3 columns: variable names, RR and 95% CI, and
dotplot of the same.
Using the bioChemists data in the pscl package and errbar function in
Hmisc package, the code below is in the right direction... but still
pretty ugly.
Wondering if folks would have alternative suggestions about how to go
about this, or pointers on cleaning up the code below (eg, I know there
are many functions for plotting errbars/CI).
[And, obviously, there are somethings that would be straightforward to
clean-up such as supplying better variable names, etc., just wanted to
see if there were better overall suggestions before getting too far on
this route.]
Thanks in advance.
cheers, Dave
library(Hmisc)
library(pscl)
## data
data("bioChemists", package = "pscl")
fm_pois <- glm(art ~ ., data = bioChemists, family = poisson)
summary(fm_pois)
### pull out rate-ratios and 95% CI
rr <- exp(cbind(coef(fm_pois), confint(fm_pois)))
rr
### round to 2 decimal places
rr <- round(rr, 2)
### plot
par(mfrow=c(1,3))
plot(0, type = "n", xlim=c(0,2), ylim=c(1,6),
axes = FALSE, ylab=NULL, xlab=NULL)
text(row.names(rr), x = 1, y = 1:6)
plot(0, type = "n", xlim=c(0,2), ylim=c(1,6),
axes = FALSE, ylab=NULL, xlab=NULL)
text(paste(rr[,1], " [", rr[,2], ", ", rr[,3], "]", sep = ""), x = 1, y
= 1:6)
errbar(x = factor(row.names(rr)),
y = rr[,1], yplus = rr[,3],
yminus = rr[,2])
abline(v = 1, lty =2)
--
Dave Atkins, PhD
Research Associate Professor
Department of Psychiatry and Behavioral Science
University of Washington
datkins at u.washington.edu
Center for the Study of Health and Risk Behaviors (CSHRB)
1100 NE 45th Street, Suite 300
Seattle, WA 98105
206-616-3879
http://depts.washington.edu/cshrb/
(Mon-Wed)
Center for Healthcare Improvement, for Addictions, Mental Illness,
Medically Vulnerable Populations (CHAMMP)
325 9th Avenue, 2HH-15
Box 359911
Seattle, WA 98104?
206-897-4210
http://www.chammp.org
(Thurs)
More information about the R-help
mailing list