Wednesday, January 26, 2011

Conditional estimates for OR

When two independent samples from separate population are collected, a product binomial likelihood can be used. However, conditioning on margins, a different formulation is achieved, as follows (shai being population OR):




For shai = 1 under null hypothesis, the above expression is exactly the same as Fisher-Irwin exact test. More simplification reduces the likelihood to this Lc = (n1! n2! m1! m2!) / (N! a! b! c! d!).

Conditional estimates and confidence intervals for OR in R can be calculated as follows:


 > m = matrix(c(a,b,c,d),2,2)
> fisher.test(m, conf.level = 0.95)

        Fisher's Exact Test for Count Data

data:  m 
p-value = 0.01075
alternative hypothesis: true odds ratio is not equal to 1 
95 percent confidence interval:
 1.225596 8.254335 
sample estimates:
odds ratio 
  3.024924 

> # The same point estimate of conditional OR
> # can be obtained by optimization:
> cond.nonc.hyp = function(orhat,a, b,c,d) {
+   n1 = a + b
+   n2 = c + d
+   m1 = a + c
+   m2 = b + d
+   N = n1 + n2
+   al = max(0, m1 - n2)
+   au = min(m1, n1)
+   i = al:au
+   l = (choose(n1, a) * choose(N - n1, m1 - a) * orhat^a) /
+   sum(choose(n1, i) * choose(N - n1, m1 - i) * orhat^i)
+   return(l)
+ }
> orhat = a*d/(b*c) # initial estimate
> cmle  =  optim(orhat,  cond.nonc.hyp,  a = a,  b = b, c = c, d = d,
+   method  =  "BFGS",  control  =  list(fnscale  =  -1), hessian = T)
> cmle$par
[1] 3.024922

No comments:

Post a Comment