Re: [R] Plot odds ratios on log scale

2009-12-21 Thread Marc Schwartz

On Dec 21, 2009, at 2:54 PM, Rice, Terri wrote:


Hi,

I have the following table of odds ratios (or), lower limits(ll) and  
upper limits(ul), which I would like to plot as horizontal lines  
beginning at the lower limit, ending at the upper limits and with a  
dot at the odds ratio on an x-axis on a log10 scale. The y axis  
would be the study sites.


From what I can figure out, it looks like the plotCI function will  
do everything except give me an x-axis that is on a log10 scale and  
I can't get the logaxis function in the log10 package to work.


Study   or  ll  ul  order
UCSF0.7 0.550.891
MDA 0.760.710.932
UK  0.680.510.893
Mayo0.5 0.280.874

Thanks for any suggestions!

Terri




Terri,

You can build your own easily, using plot() and then either arrows()  
or segments() to create the CI boundary lines. Just use 'log = x' in  
the call to plot to create the log scaled x axis.


Presuming that your data above are contained in a data frame called  
'DF':


 DF
  Study   or   ll   ul order
1  UCSF 0.70 0.55 0.89 1
2   MDA 0.76 0.71 0.93 2
3UK 0.68 0.51 0.89 3
4  Mayo 0.50 0.28 0.87 4


# Get the range of values for the x axis
xlim - with(DF, range(or - ll, or + ul))

 xlim
[1] 0.05 1.69

# Plot the points. set the range of the x axis and set to log10 scale
plot(order ~ or, data = DF, xlim = xlim, pch = 19, log = x)

# Add the CI's
with(DF, arrows(or - ll, order, or + ul, order, code = 3, angle = 90))

See ?arrows for help on the options for formatting the lines.

Alternatively, since it appears you are doing a meta-analysis of  
sorts, you might want to look at the metaplot() and forestplot()  
functions in Thomas Lumley's 'rmeta' package on CRAN.


HTH,

Marc Schwartz

__
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.


Re: [R] Plot odds ratios on log scale

2009-12-21 Thread Ted Harding
On 21-Dec-09 21:19:27, Marc Schwartz wrote:
 On Dec 21, 2009, at 2:54 PM, Rice, Terri wrote:
 Hi,
 I have the following table of odds ratios (or), lower limits(ll) and  
 upper limits(ul), which I would like to plot as horizontal lines  
 beginning at the lower limit, ending at the upper limits and with a  
 dot at the odds ratio on an x-axis on a log10 scale. The y axis  
 would be the study sites.

 From what I can figure out, it looks like the plotCI function will  
 do everything except give me an x-axis that is on a log10 scale and  
 I can't get the logaxis function in the log10 package to work.

 Study   or  ll  ul  order
 UCSF0.7 0.550.891
 MDA 0.760.710.932
 UK  0.680.510.893
 Mayo0.5 0.280.874

 Thanks for any suggestions!

 Terri
 
 Terri,
 You can build your own easily, using plot() and then either arrows()  
 or segments() to create the CI boundary lines. Just use 'log = x' in 
 the call to plot to create the log scaled x axis.
 
 Presuming that your data above are contained in a data frame called  
 'DF':
 
   DF
Study   or   ll   ul order
 1  UCSF 0.70 0.55 0.89 1
 2   MDA 0.76 0.71 0.93 2
 3UK 0.68 0.51 0.89 3
 4  Mayo 0.50 0.28 0.87 4
 
 
# Get the range of values for the x axis
 xlim - with(DF, range(or - ll, or + ul))
 
   xlim
 [1] 0.05 1.69
 
# Plot the points. set the range of the x axis and set to log10 scale
 plot(order ~ or, data = DF, xlim = xlim, pch = 19, log = x)
 
# Add the CI's
 with(DF, arrows(or - ll, order, or + ul, order, code = 3, angle = 90))
 
 See ?arrows for help on the options for formatting the lines.
 
 Alternatively, since it appears you are doing a meta-analysis of  
 sorts, you might want to look at the metaplot() and forestplot()  
 functions in Thomas Lumley's 'rmeta' package on CRAN.
 
 HTH,
 Marc Schwartz

While Marc was posting the above, I was working out an example
on just those lines! It is simply an illustration of how one
can proceed. Often, it is worth while constructing one's plot
by hand, since then you can cook things exactly as you want
them (Haute Cuisine), rather than get served with what's been
prepared (Pizza Bar, even if it is a high-quality one).

Here is ths code:

## Construct the dataframe
X-rbind(
c(0.7,0.55,0.89,1),
c(0.76,0.71,0.93,2),
c(0.68,0.51,0.89,3),
c(0.5,0.28,0.87,4)
)
colnames(X)-c(OR,LL,UL,Order)
rownames(X)-c(UCSF,MDA,UK,Mayo)
Xdf-as.data.frame(X)

## Construct the plot
plot(Xdf$OR, (5-Xdf$Order), pch=20, log=x,
 xlim=c(0.2,1), ylim=c(0.5,4.5),
 axes=FALSE, frame.plot=TRUE,
 xlab=OR with Confidence Limits, ylab=Order)
at.x - 0.2*(1:5)
axis(1,at=at.x,labels=formatC(at.x,format=fg))
for(i in (1:4)){
  y - (5-Xdf$Order[i])
  lines(c(Xdf$LL[i],Xdf$UL[i]),c(y,y))
  text(0.2,i,labels=as.character(y),pos=4)
  text(0.21,y,labels=rownames(Xdf)[i],pos=4)
}

## Especially see ?plot and ?plot.default for details

Ted.


E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
Fax-to-email: +44 (0)870 094 0861
Date: 21-Dec-09   Time: 22:13:40
-- XFMail --

__
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.


Re: [R] Plot odds ratios on log scale

2009-12-21 Thread Richard M. Heiberger

Please look at the aedotplot, in which we plot four variables:
A effect, B effect, relative risk, and CI on the relative risk.

It should be easily modified to plot the odds ratios.

## install.packages(HH)  ## if you don't have it yet.

library(aedotplot)
example(aedotplot)

__
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.


Re: [R] Plot odds ratios on log scale

2009-12-21 Thread Marc Schwartz

On Dec 21, 2009, at 4:13 PM, Ted Harding wrote:


On 21-Dec-09 21:19:27, Marc Schwartz wrote:

On Dec 21, 2009, at 2:54 PM, Rice, Terri wrote:

Hi,
I have the following table of odds ratios (or), lower limits(ll) and
upper limits(ul), which I would like to plot as horizontal lines
beginning at the lower limit, ending at the upper limits and with a
dot at the odds ratio on an x-axis on a log10 scale. The y axis
would be the study sites.


From what I can figure out, it looks like the plotCI function will
do everything except give me an x-axis that is on a log10 scale and
I can't get the logaxis function in the log10 package to work.


Study   or  ll  ul  order
UCSF0.7 0.550.891
MDA 0.760.710.932
UK  0.680.510.893
Mayo0.5 0.280.874

Thanks for any suggestions!

Terri


Terri,
You can build your own easily, using plot() and then either arrows()
or segments() to create the CI boundary lines. Just use 'log = x'  
in

the call to plot to create the log scaled x axis.

Presuming that your data above are contained in a data frame called
'DF':


DF

  Study   or   ll   ul order
1  UCSF 0.70 0.55 0.89 1
2   MDA 0.76 0.71 0.93 2
3UK 0.68 0.51 0.89 3
4  Mayo 0.50 0.28 0.87 4


# Get the range of values for the x axis
xlim - with(DF, range(or - ll, or + ul))


xlim

[1] 0.05 1.69

# Plot the points. set the range of the x axis and set to log10 scale
plot(order ~ or, data = DF, xlim = xlim, pch = 19, log = x)

# Add the CI's
with(DF, arrows(or - ll, order, or + ul, order, code = 3, angle =  
90))


See ?arrows for help on the options for formatting the lines.

Alternatively, since it appears you are doing a meta-analysis of
sorts, you might want to look at the metaplot() and forestplot()
functions in Thomas Lumley's 'rmeta' package on CRAN.

HTH,
Marc Schwartz


While Marc was posting the above, I was working out an example
on just those lines! It is simply an illustration of how one
can proceed. Often, it is worth while constructing one's plot
by hand, since then you can cook things exactly as you want
them (Haute Cuisine), rather than get served with what's been
prepared (Pizza Bar, even if it is a high-quality one).


snip

I nominate Ted's comments above for inclusion in the fortunes package.

Now...to the kitchen...that made me hungry... :-)

Regards,

Marc

__
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.