Description Usage Arguments Details Value Examples
Plots the posterior mean PDF or CDF based on the output from gold
.
1 2 |
gold_output |
The list returned by |
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. |
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.
"pdf"
: The density, f(x), is calculated at a grid overlayed with the data at each iteration to produce the results in the graph (DEFAULT).
"cdf"
: The CDF, F(x), is calculated at a grid overlayed with the data at each iteration. The CDF at each grid point and data point is then averaged across the iterations to produce the results in the graph.
Options for cri
Credibal intervals can also be added to the plot of the PDF or CDF.
"FALSE"
: No credible intervals lines are plotted (DEFAULT).
"TRUE"
: Credible interval lines are plotted in red on the PDF or CDF. These are calculated by taking the 0.025th and 0.975th quantiles of the iterations from gold
after burnin.
Options for data
Incoproates the data into the PDF and CDF.
"FALSE"
: The data is not included (DEFAULT).
"TRUE"
: If the PDF is plotted, a histogram is overlayed with the density estimate. If the CDF is plotted, the empirical CDF is overlayed with the gold
CDF estimate.
A plot of the PDF or CDF estimate.
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.