plot_sequential: Plot Sequential Analysis

Description Usage Arguments Details Author(s) Examples

View source: R/plot_sequential.R

Description

Function for plotting the posterior probabilities of the hypotheses sequentially.

Usage

1
plot_sequential(x, thin = 1, cores = 1, ...)

Arguments

x

object of class "ab". Note that the "ab" object needs to contain sequential data.

thin

allows the user to skip every kth data point for plotting, where the number k is specified via thin. For instance, in case thin = 2, only every second element of the data is displayed.

cores

number of cores used for the computations.

...

further arguments

Details

The plot shows the posterior probabilities of the hypotheses as a function of the total number of observations across the experimental and control group. On top of the plot, probability wheels (see also prob_wheel) visualize the prior probabilities of the hypotheses and the posterior probabilities of the hypotheses after taking into account all available data.

N.B.: This plot has been designed to look good in the following format: In inches, 530 / 72 (width) by 400 / 72 (height); in pixels, 530 (width) by 400 (height).

Author(s)

Quentin F. Gronau

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
50
51
52
53
54
55
56
57
58
59
### 1.

# synthetic sequential data (observations alternate between the groups)
# note that the cumulative number of successes and trials need to be provided
data <- list(y1 = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 3, 4, 4),
             n1 = c(1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10),
             y2 = c(0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9),
             n2 = c(0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10))

# conduct Bayesian A/B test with default settings
ab <- ab_test(data = data)
print(ab)


# produce sequential plot of posterior probabilities of the hypotheses
# (using recommended width and height values for saving to file)
cairo_pdf(file.path(tempdir(), "test_plot.pdf"),
          width = 530 / 72, height = 400 / 72)
plot_sequential(ab)
dev.off()


### 2.

# synthetic sequential data (observations alternate between the groups)
# this time provided in the alternative format
data2 <- data.frame(outcome = c(1, 1, 0, 1, 0, 1, 0, 1, 0, 1,
                                0, 1, 0, 1, 1, 1, 1, 1, 1, 0),
                    group = rep(c(1, 2), 10))

# conduct Bayesian A/B test with default settings
ab2 <- ab_test(data = data2)
print(ab2)


# produce sequential plot of posterior probabilities of the hypotheses
# (using recommended width and height values for saving to file)
cairo_pdf(file.path(tempdir(), "test_plot2.pdf"),
          width = 530 / 72, height = 400 / 72)
plot_sequential(ab2)
dev.off()


## Not run: 
### 3.
data(seqdata)

# conduct Bayesian A/B test with default settings
ab3 <- ab_test(data = seqdata)
print(ab3)

# produce sequential plot of posterior probabilities of the hypotheses
# (using recommended width and height values for saving to file)
cairo_pdf(file.path(tempdir(), "test_plot3.pdf"),
          width = 530 / 72, height = 400 / 72)
plot_sequential(ab3, thin = 4)
dev.off()

## End(Not run)

Example output

Bayesian A/B Test Results:

 Bayes Factors:

 BF10: 3.061789
 BF+0: 5.92393
 BF-0: 0.2614742

 Prior Probabilities Hypotheses:

 H+: 0.25
 H-: 0.25
 H0: 0.5

 Posterior Probabilities Hypotheses:

 H+: 0.7237
 H-: 0.0319
 H0: 0.2443
png 
  2 
Bayesian A/B Test Results:

 Bayes Factors:

 BF10: 3.061789
 BF+0: 6.016505
 BF-0: 0.2579291

 Prior Probabilities Hypotheses:

 H+: 0.25
 H-: 0.25
 H0: 0.5

 Posterior Probabilities Hypotheses:

 H+: 0.7271
 H-: 0.0312
 H0: 0.2417
png 
  2 
Bayesian A/B Test Results:

 Bayes Factors:

 BF10: 0.2767214
 BF+0: 0.4942612
 BF-0: 0.05811472

 Prior Probabilities Hypotheses:

 H+: 0.25
 H-: 0.25
 H0: 0.5

 Posterior Probabilities Hypotheses:

 H+: 0.1936
 H-: 0.0228
 H0: 0.7836
png 
  2 

abtest documentation built on Nov. 22, 2021, 9:07 a.m.