Question: Common Odds Ratio - R Udf
0
zx87549.4k wrote:

If you kindly paste `SNP1,5220,26,0,810,30,1` as input on this website, it gives out Armitage's trend test common odds ratio of `Odds_ratio=8.568`. At the bottom of the page they explain what it means as below:

``````Common odds ratio:    (Case_12*Control_11/N01 + Case_22*Control_12/N12 + 4*(Case_22*Control_11/N02))/
(Case_11*Control_12/N01 + Case_12*Control_22/N12 + 4*(Case_22*Control_11*Case_11*Control_22)**0.5/N02)
``````

Question: I am trying to make an R function, but not sure what N01, N12, N02 mean? Or do you know of an existing R function that would give the same result?

So far, before making it into a function, I am trying to break down the formula so I can get the same result as in the website:

``````d <- structure(c(5220L, 810L, 26L, 30L, 0L, 1L),
.Dim = 2:3,
.Dimnames = structure(
list(
caco = c("0", "1"),
snp1 = c("CC", "CT", "TT")),
.Names = c("caco","snp1")),
class = "table")
# snp1
# caco   CC   CT   TT
# 0 5220   26    0
# 1  810   30    1

#Assign Variables
Control_11 <- d[1,1]
Control_12 <- d[1,2]
Control_22 <- d[1,3]
Case_11 <- d[2,1]
Case_12 <- d[2,2]
Case_22 <- d[2,3]

#Doesn't work - OR=5986.03
# N01 <- Control_11 + Case_11
# N12 <- Control_12 + Case_12
# N02 <- Control_22 + Case_22

#Doesn't work - OR=214.8141
# N01 <- (Control_11 + Case_11)*2 + Control_12 + Case_12
# N12 <- Control_12 + Case_12
# N02 <- (Control_22 + Case_22)*2 + Control_12 + Case_12

#Return OR - Correct OR should be 8.568
(Case_12*Control_11/N01
+ Case_22*Control_12/N12
+ 4*(Case_22*Control_11/N02))/
(Case_11*Control_12/N01
+ Case_12*Control_22/N12
+ 4*(Case_22*Control_11*Case_11*Control_22)**0.5/N02)
``````

EDIT: Tried following, close but not the same result:

``````#Doesn't work - OR=7.59501 - Probably rounding?
N01 <- Case_11 + Case_12 + Case_22
N02 <- Control_11 + Control_12 + Control_22
N12 <- N01 + N02
``````
R • 2.9k views
modified 7.1 years ago • written 7.1 years ago by zx87549.4k

Have you contacted the developers to ask for source or at least a top-level description of their work? If their research is reproducible, they should be able to provide (pseudo) code to show how the analysis works.

Contacted them today to explain what N01, N02, N12 variables mean. If I hear anything I will update this post.

1
zx87549.4k wrote:

Found the solution, the formula was adopted from Peter D. Sasieni - "From Genotypes to Genes: Doubling the Sample Size" (Biometrics 1997). There was inconsistency how the variables were named on the paper and on the adopted website.

Here is the working `R` function:

``````udf_CommonOddsRatio <- function(d)
{
# Armitage's trend test - common odds ratio
# http://ihg.gsf.de/cgi-bin/hw/hwa2.pl
#
# Peter D. Sasieni - "From Genotypes to Genes: Doubling the Sample Size"
# (Biometrics 1997)
#
# Example data - class=table
# d <- structure(c(5220L, 810L, 26L, 30L, 0L, 1L),
#                .Dim = 2:3,
#                .Dimnames = structure(
#                  list(
#                    caco = c("0", "1"),
#                    snp1 = c("CC", "CT", "TT")),
#                  .Names = c("caco","snp1")),
#                class = "table")
# snp1
# caco   CC   CT   TT
# 0 5220   26    0
# 1  810   30    1

#Assign Variables
Control_11 <- d[1,1]
Control_12 <- d[1,2]
Control_22 <- d[1,3]
Case_11 <- d[2,1]
Case_12 <- d[2,2]
Case_22 <- d[2,3]

N01 <- Case_11 + Control_11 + Case_12 + Control_12
N02 <- Case_11 + Control_11 + Case_22 + Control_22
N12 <- Case_12 + Control_12 + Case_22 + Control_22

#Return OR
return(
(Case_12*Control_11/N01
+ Case_22*Control_12/N12
+ 4*(Case_22*Control_11/N02))/
(Case_11*Control_12/N01
+ Case_12*Control_22/N12
+ 4*(Case_22*Control_11*Case_11*Control_22)**0.5/N02)
)
}
``````