[R] Simulating n 2x2 tables with the same odds ratio
Petr Savicky
savicky at cs.cas.cz
Fri Mar 9 16:01:17 CET 2012
On Fri, Mar 09, 2012 at 05:37:42AM -0800, hubinho wrote:
> Hello.
>
> I'm looking for a method to simulate n different 2x2 tables having all the
> same odds ratio.
>
> For example.
>
> I need
> 100 tables with odds ratio 1
> 100 tables with odds ratio 2
> 100 tables with odds ratio 3
>
> and so on.
>
> All tables should have the same marginal frequencies.
Hi.
Marginal frequencies together with the odds ratio determine
the matrix uniquely. So, some of the requirements should
be relaxed.
If we start with a matrix
(a, b)
(c, d)
then all matrices with the same marginal frequencies have
the form
(a + t, b - t)
(c - t, d + t)
The odds ratio is
(a+t)(d+t)/(c-t)/(b-t)
which is a strictly increasing function of t and so the equation
(a+t)(d+t)/(c-t)/(b-y) = odds
for a given odds has a unique solution t.
Petr Savicky.
More information about the R-help
mailing list