posteriormean: Find the posterior mean

Description Usage Arguments Examples

View source: R/ultility.R

Description

Find the posterior mean given the observations and the mixing distribution based on the family in the result

Usage

1
2
3
4
5
6
7
posteriormean(x, result, fun = function(x) x)

posteriormean.npnorm(x, result, fun = function(x) x)

posteriormean.npt(x, result, fun = function(x) x)

posteriormean.npnormc(x, result, fun = function(x) x)

Arguments

x

a vector of observations

result

an object of class nspmix

fun

the function to transform the mean. It finds the posterior mean of fun(x). The function fun must be vectorised.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
data = rnorm(500, c(0, 2))
x = makeobject(data, pi0 = 0.5)
r1 = computemixdist(x)
posteriormean(data, r1)
x2 = makeobject(data, pi0 = 0.5, method = "nptll") # equivalent to normal
r2 = computemixdist(x2)
posteriormean(data, r2, fun = function(x) x^2)
data = runif(500, min = -0.5, max = 0.5)
x3 = makeobject(data, method = "npnormcll", beta = 100)
r3 = computemixdist(x3)
posteriormean(data, r3)

xiangjiexue/npfixedcompR documentation built on Jan. 1, 2021, 11:39 p.m.