Calculate the posterior mean of an object of class Bolstad. If the
object has a member mean then it will return this value otherwise it
will calculate int_{-∞}^{+∞}θ f(θ|x).dθ using
linear interpolation to approximate the density function and numerical
integration where θ is the variable for which we want to do
Bayesian inference, and x is the data.
Usage
## S3 method for class 'Bolstad'
mean(x, ...)
Arguments
x
An object of class Bolstad
...
Any other arguments. This parameter is currently ignored but it
could be useful in the future to deal with problematic data.
Value
The posterior mean of the variable of inference given the data.
Examples
# The useful of this method is really highlighted when we have a general
# continuous prior. In this example we are interested in the posterior mean of
# an normal mean. Our prior is triangular over [-3, 3]
set.seed(123)
x = rnorm(20, -0.5, 1)
mu = seq(-3, 3, by = 0.001)
mu.prior = rep(0, length(mu))
mu.prior[mu <= 0] = 1 / 3 + mu[mu <= 0] / 9
mu.prior[mu > 0] = 1 / 3 - mu[mu > 0] / 9
results = normgcp(x, 1, density = "user", mu = mu, mu.prior = mu.prior)
mean(results)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(Bolstad)
Attaching package: 'Bolstad'
The following objects are masked from 'package:stats':
IQR, sd, var
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/Bolstad/mean.Bolstad.Rd_%03d_medium.png", width=480, height=480)
> ### Name: mean.Bolstad
> ### Title: Calculate the posterior mean
> ### Aliases: mean.Bolstad
>
> ### ** Examples
>
> # The useful of this method is really highlighted when we have a general
> # continuous prior. In this example we are interested in the posterior mean of
> # an normal mean. Our prior is triangular over [-3, 3]
> set.seed(123)
> x = rnorm(20, -0.5, 1)
> mu = seq(-3, 3, by = 0.001)
> mu.prior = rep(0, length(mu))
> mu.prior[mu <= 0] = 1 / 3 + mu[mu <= 0] / 9
> mu.prior[mu > 0] = 1 / 3 - mu[mu > 0] / 9
> results = normgcp(x, 1, density = "user", mu = mu, mu.prior = mu.prior)
Known standard deviation :1
> mean(results)
[1] -0.3414455
>
>
>
>
>
> dev.off()
null device
1
>