[R] Coverage Probability

hubinho hubinho at hotmail.com
Mon Mar 19 17:55:10 CET 2012


I'm allready this far. I have a function which is calculating the lower (l)
and upper (u) limit for a confidence interval for the odds ratio.

For example for 5 simulated 2x2 tables the upper and lower limits are:

> u
[1] 2.496141 7.436524 8.209161 4.313587 3.318612
> l
[1] -0.9718608  1.1000713  1.5715373  0.1135158 -0.2700517

With (l[1]; u[1]) being the confidence interval for the odds ratio for the
first simulated table and so on.

Now I want to compute the coverage probability. For that I've created a
function which is return 1 if the odds ratio is in the interval and 0 if it

cover <- function(theta, u, l){
if(theta >= l && theta   <= u){z=1}
if(theta < l || theta   > u){z=0}; return(z)

This works but unfortunately not if I want to summarize the function and
divide it with the sample size to get the coverage probability.

I tried it this way

for(for(x in 1:5) {a = (sum(cover(theta, u[x], l[x]))/5; return(a)}

Maybe someone can help me. Thank you

View this message in context: http://r.789695.n4.nabble.com/Coverage-Probability-tp4485511p4485511.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list