gold_plot: Plot PDF or CDF

Description Usage Arguments Details Value Examples

Description

Plots the posterior mean PDF or CDF based on the output from gold.

Usage

1
2
gold_plot(gold_output, type = "pdf", burnin = NA, cri = FALSE,
  data = FALSE, interact = FALSE)

Arguments

gold_output

The list returned by gold containing the density estimate results.

type

The type of desired graph (see details).

burnin

The desired burnin to discard from the results. If no values is entered, the default is half the number of iterations.

cri

An option to include credible intervals.

data

An option to include data in the graph (see details).

interact

An option to make the plots interactive.

Details

The form of the density whose paramters are estimated in gold is below:

f(x) =

exp(g(x)) / (\int_{0}^{1} exp(g(u)) du)

where g(x) is an unknown log density.

Given that g(x) is unknown, the normalizing constant is estimated using a weighted average and the set of unknown paramters that recieve a prior is g(x) at a finite set of points.

F(x) =

\int_{0}^{x} exp(g(y)) / (\int_{0}^{1} exp(g(u)) du)

where g(x) is an unknown log density.

Given that g(x) is unknown, the normalizing constant is estimated using a weighted average and the set of unknown paramters that recieve a prior is g(x) at a finite set of points. These weights are also used in the estimate of the integral in the numerator. Options for type

The input from gold can be used to plot a Bayesian estimate of the PDF or the CDF.

Options for cri

Credibal intervals can also be added to the plot of the PDF or CDF.

Options for data

Incoproates the data into the PDF and CDF.

Value

A plot of the PDF or CDF estimate.

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
## --------------------------------------------------------------------------------
## Uniform Distribution
## --------------------------------------------------------------------------------

# First run 'gold' on data sampled from a Uniform(0,1) distribution with 50 data points.
y <- runif(50)
gold_unif <- gold(y, s1 = 1, c1 = 1, s2 = 0.9, c2 = 0.8, MH_N = 20000)

#Plot the PDF with the data and credible intervals
gold_plot(gold_unif, type="pdf", data=TRUE)

#Plot the CDF with the credible intervals and the empirical CDF
gold_plot(gold_unif, type="cdf", cri=TRUE, data=TRUE)

## --------------------------------------------------------------------------------
## Beta Distribution
## --------------------------------------------------------------------------------

# First run 'gold' on data sampled from a Beta(0.5,0.5) distribution with 300 data points.
y <- rbeta(300, 0.5, 0.5)
gold_arcsin <- gold(y, s1 = 2, c1 = 6, s2 = .2, c2 = 1.5, MH_N = 20000)
#Plot the PDF with the data
gold_plot(gold_arcsin, type="pdf", data=TRUE)

#Plot the CDF with the credible intervals
gold_plot(gold_arcsin, type="cdf", cri=TRUE)

## --------------------------------------------------------------------------------
## Bimodal Distribution
## --------------------------------------------------------------------------------

#Sample 150 random uniforms
U =runif(150)
y = rep(NA,150)
#Sampling from the mixture
for(i in 1:150){
  if(U[i]<.3){
   y[i] = rnorm(1,0,1)
  }else {
   y[i] = rnorm(1,4,1)
  }
}
# First run 'gold' on data sampled from a bimodal distribution with 150 data points.
gold_bimodal <- gold(y, s1 = 1, c1 = 5, s2 = .4, c2 = 3, MH_N = 20000)

#Plot the PDF
gold_plot(gold_bimodal)

#Plot the PDF with credible intervals and a histogram of the data
gold_plot(gold_bimodal, cri=TRUE, data=TRUE)

#Plot the CDF with the empirical CDF
gold_plot(gold_bimodal, type="cdf", data=TRUE)

reykp/BEDr documentation built on May 28, 2019, 8:40 a.m.