/
posterior.R
30 lines (25 loc) · 915 Bytes
/
posterior.R
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
#' Generate the posterior function of the Dirichlet function
#'
#'@param dpobj Fitted Dirichlet Process object
#'@param ind What iteration to draw the posterior function from. Defaults to the last iteration.
#'@return A posterior function f(x).
#'
#'@examples
#'
#'y <- rnorm(10)
#'dp <- DirichletProcessGaussian(y)
#'dp <- Fit(dp, 5)
#'postFuncDraw <- PosteriorFunction(dp)
#'plot(-3:3, postFuncDraw(-3:3))
#'
#'@export
PosteriorFunction <- function(dpobj, ind) UseMethod("PosteriorFunction")
#'@export
PosteriorFunction.dirichletprocess <- function(dpobj, ind) {
post_clusters <- PosteriorClusters(dpobj, ind)
base_function <- function(x, theta) Likelihood(dpobj$mixingDistribution, x, theta)
post_func <- weighted_function_generator(base_function,
post_clusters$weights,
post_clusters$params)
return(post_func)
}