=p11_2
}
bincorr=(p11-p1*p2)/sqrt(p1*(1-p1)*p2*(1-p2))
return(bincorr)
}
For instance, try
sapply(c(0,0.5,1,1.5,3,10,100),function(x) bincorr(x,p1,p2))
to see the range of valid correlations for odds ratios between 0 and
100, with p1 and p2 as above.
Bernhard Klingenberg
Dept
Thank you! Is floating point arithmetic also the reason why
1 %% 0.1
gives the surprising answer 0.1 (because 0.1 cannot be written as a
fraction with denominator a power of 2, e.g. 1%%0.5 correctly gives 0).
This seems to go a bit against the statement in the help for '%%', which
states For
Consider the code:
x - seq(0,1,0.2)
y - seq(0,1,0.01)
cbind(match(y,x),y)
which, surprisingly, doesn't show a match at 0.6! (It gives correct
matches at 0, 0.2, 0.4, 0.8 and 1, though)
In addition,
x[4]==y[61]
yields FALSE. (but x[5]==y[81], the one for 0.8, yields TRUE)
Is this a