R language Access Menu

Title Text Both  

Effect size: Odds ratio

Odds ratio is the effect size that can be used for contingency tables. Package epitools has very useful oddsratio function which also analyzes the table to find significant relations. The table tt can be transposed using 't' function for this:

Code:

> tt = with(bwdf, table(race, smoke))
> tt
    smoke
race  0  1
   1 44 52
   2 16 10
   3 55 12

> library(epitools)
> oddsratio(tt)
$data
       smoke
race      0  1 Total
  1      44 52    96
  2      16 10    26
  3      55 12    67
  Total 115 74   189

$measure
    odds ratio with 95% C.I.
race  estimate      lower     upper
   1 1.0000000         NA        NA
   2 0.5342002 0.21199519 1.2909218
   3 0.1880435 0.08589639 0.3862971

$p.value
    two-sided
race     midp.exact   fisher.exact     chi.square
   1             NA             NA             NA
   2 0.164831123518 0.187480644257 0.155337549677
   3 0.000002324535 0.000003668618 0.000003103935

$correction
[1] FALSE

attr(,"method")
[1] "median-unbiased estimate & mid-p exact CI"

The first row and column are taken as baseline for others to compare with. Here, it can be seen that odds ratio for a member of race group 3 to be a smoker is 0.188 (P<0.0001) as compared to race group 1.

The odds ratios and their confidence intervals can be plotted as follows: 
Code:

> library(epitools)
> orr = oddsratio(tt)
> dd = data.frame(orr$measure)
> dd$group = rownames(dd)
> dd
   estimate      lower     upper group
1 1.0000000         NA        NA     1
2 0.5342002 0.21199519 1.2909218     2
3 0.1880435 0.08589639 0.3862971     3

> ggplot(dd, aes(group, estimate))+ geom_point()+ geom_errorbar(aes(ymin=lower, ymax=upper))

Output graph:

                 

The axes can be flipped for a horizontal, forest plot style: 

code:

> ggplot(dd, aes(group, estimate))+ 

    geom_point()+
    geom_errorbar(aes(ymin=lower, ymax=upper))+
    coord_flip()

output graph:

                      

 

 


    Comments & Feedback