OR_Ref: Reference Analysis of the 2x2 table

Description Usage Arguments Details Value Examples

View source: R/OR_Ref.R

Description

Performs Objective Bayesian analysis on the odds ratio θ of a 2x2 contingency table using the reference prior of Snyder and Sun 2018.

Usage

1
2
OR_Ref(x, conf.int = TRUE, conf.level = 0.95, post.sample = TRUE,
  sampling.depth = 1, num.samples = 1000)

Arguments

x

a 2x2 contingency table in matrix form

conf.int

Should a credible interval be computed using numerical integration?

conf.level

confidence level for the returned credible interval. NOTE: Equal tailed

post.sample

Should Posterior sampling be conducted?

sampling.depth

Depth of sampling. 1 for theta only, 2 to add eta1, 3 to add eta3, 4 to add eta2

num.samples

Number of Posterior Samples

Details

This methdology takes an unstructured 2x2 table of the form

n1 n2
n3 n4

where each ni~Poisson(λi). From this, we primarilly seek to perform inference on the odds ratio θ = λ1λ4/λ2λ3.

The Bayesian reference structure also contains several other nuisance parameters that may be of interest to the researcher. We have

θ = λ1λ4/λ2λ3, η1 = λ1/(λ1+λ3), η2 = λ1+λ3, η3 = λ2/λ1

We first note that despite being “nuisance" parameters, the three ηi have highly informative interpretations. η_1 represents the proportion of negative/positive outcomes in the control/treatment group. η_2 represents the total average number of negative/positive outcomes, and is a parameter that is related to the "scale" of the table. Finally, η_3 represents the relative risk of a positive outcome in the control group.

Value

CI

The Credible interval and median

Theta.Samples

If post.sample = TRUE, the posterior Samples of the odds ratio theta

Eta1.Samples

If post.sample = TRUE and sampling.depth is at least 2, the posterior Samples of η1

Eta2.Samples

If post.sample = TRUE and sampling.depth is 4, the posterior Samples of η2

Eta3.Samples

If post.sample = TRUE and sampling.depth is at least 3, the posterior Samples of η3

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Snyder and Sun (2018), Data were collected to establish a relationship between 
#  mobile phone and laptop operating system types for an undergraduate statistics class.
MyTable <- rbind(c(5,0),
                 c(8,15))
dimnames(MyTable) <-  list(Phone = c("Android", "Iphone"),Computer = c("Windows", "Mac"))
MyTable

# Fisher's exact test yields an infinitely wide interval and no sample estimate                 
fisher.test(MyTable)

# Results from a reference Bayesian Analysis are sensible.
res <- OR_Ref(MyTable,conf.int = TRUE,num.samples = 1000)
res$CI
quantile(res$Theta.Samples,c(.025,.5,.975))

# Agresti (1990, p. 61f; 2002, p. 91) Fisher's Tea Tasting Experiment
# A colleague of Fisher claimed to be able to distinguish if milk or
#  tea was added to a cup first.  She was given 8 cups of
#  tea, in which she was told that four of which had milk added first.  
#  The null hypothesis is that there is no association between the true 
#  order of pouring and the woman's guess, the alternative that there 
#  is a positive association (that the odds ratio is greater than 1).

TeaTasting <-
matrix(c(3, 1, 1, 3),
     nrow = 2,
     dimnames = list(Guess = c("Milk", "Tea"),
     Truth = c("Milk", "Tea")))

fisher.test(TeaTasting, alternative = "greater")
# => p = 0.2429, association could not be established

res <- OR_Ref(TeaTasting,conf.int = FALSE,num.samples = 2500)
sum(res$Theta.Samples>1)/sum(res$Theta.Samples<1)
# Bayes Factor indicates substantial evidence of her ability

# Fisher (1962, 1970), Criminal convictions of like-sex twins
Convictions <-
  matrix(c(2, 10, 15, 3),
         nrow = 2,
         dimnames =
           list(c("Dizygotic", "Monozygotic"),
                c("Convicted", "Not convicted")))
Convictions
fisher.test(Convictions, alternative = "less")
#Fisher's exact test is infinitely wide on log scale.

res <- OR_Ref(Convictions,conf.int = FALSE,num.samples = 5000)
quantile(res$Theta.Samples,c(.025,.5,.975))

John-Snyder/OBayes2by2Table documentation built on Aug. 18, 2019, 3:37 a.m.