getEqualSamples: getEqualSamples

Description Usage Arguments Value Author(s) Examples

Description

Return n equally weighted posterior samples

Usage

1
getEqualSamples(posterior, n = Inf)

Arguments

posterior

Matrix from the output of nested sampling. Should have log weights in column 1, log likelihoods in column 2 and then the parameter values in the remaining column(s).

n

Number of samples from the posterior required. If infinity (the deafult) this will return the maximum number of equally weighted samples generated from the posterior it can. Likewise if n is greater than this maximum number of samples.

Value

A set of equally weighted samples from the inferred posterior distribution.

Author(s)

Lydia Rickett, Matthew Hartley, Richard Morris and Nick Pullen

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
mu <- 1
sigma <- 1
data <- rnorm(100, mu, sigma)

transform <- function(params) {
  tParams = numeric(length=length(params))
  tParams[1] = GaussianPrior(params[1], mu, sigma)
  tParams[2] = UniformPrior(params[2], 0, 2 * sigma)
  return(tParams)
}

llf <- function(params) {
  tParams = transform(params)
  mean = tParams[1]
  sigma = tParams[2]
  n <- length(data)
  ll <- -(n/2) * log(2*pi) - (n/2) * log(sigma**2) - (1/(2*sigma**2)) * sum((data-mean)**2)
  return(ll)
}

prior.size <- 25
tol <- 0.5

ns.results <- nestedSampling(llf, 2, prior.size, transform, tolerance=tol)

getEqualSamples(ns.results$posterior)

babar documentation built on May 1, 2019, 10:18 p.m.