EstimateKL: Function to calculate expected KL

Description Usage Arguments Value Examples

View source: R/KLchecker.R

Description

Based on Jhwueng et al. 2014, especially equation 7

Usage

1
2
3
4
EstimateKL(simulator.true.model, true.parameters,
  param.estimator.candidate.model, simulator.candidate.model,
  likelihood.data.with.true.model, likelihoods.data.with.candidate.model, K,
  nrep.outer = 100, nrep.inner = 100)

Arguments

simulator.true.model

Function to create a dataset given vector of true parameters

true.parameters

Vector of parameters to use for simulations

param.estimator.candidate.model

Function to estimate the parameters under a candidate model given an input dataset

simulator.candidate.model

Function to simulate a dataset given vector of estimated parameters

likelihood.data.with.true.model

Function to calculate the log likelihood (not neg log like) of the data under the true model

likelihoods.data.with.candidate.model

Function to calculate the log likelihood (not neg log like) of the data under the candidate model

K

Number of free parameters in candidate model

nrep.outer

Number of outer loops

nrep.inner

Number of inner loops

Value

KL in same space (so multiplied by -2) as AIC

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
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
simulator.true.model <- function(parameters) {
  return(rnorm(n=1000, mean=parameters[1], sd=parameters[2]))
}

true.parameters <- c(1000, 0.12)

param.estimator.candidate.model <- function(x) {
  return(mean(1/x)) #here our candidate is exp
}

simulator.candidate.model <- function(parameters) {
  return(rexp(n=1000, rate=parameters[1]))
}

likelihood.data.with.true.model <- function(data, parameters) {
  return(sum(dnorm(data, mean=parameters[1], sd=parameters[2]), log=TRUE))
}

likelihood.data.with.candidate.model <- function(data) {
  return(sum(dexp(data, rate=param.estimator.candidate.model(data)), log=TRUE))
}

K <- 1

NormVsExp <- EstimateKL(simulator.true.model, true.parameters, param.estimator.candidate.model, simulator.candidate.model, likelihood.data.with.true.model, likelihoods.data.with.candidate.model, K)


simulator.true.model <- function(parameters) {
  return(rnorm(n=1000, mean=parameters[1], sd=parameters[2]))
}

true.parameters <- c(1000, 0.12)

param.estimator.candidate.model <- function(x) {
  return(c(mean(x), sd(x))) #here our candidate is exp
}

simulator.candidate.model <- function(parameters) {
  return(rnorm(n=1000, mean=parameters[1], sd=parameters[2]))
}

likelihood.data.with.true.model <- function(data, parameters) {
  return(sum(dnorm(data, mean=parameters[1], sd=parameters[2]), log=TRUE))
}

likelihood.data.with.candidate.model <- function(data) {
  return(sum(dnorm(data, mean=mean(data), sd=sd(data)), log=TRUE))
}

K <- 2

NormVsNorm <- EstimateKL(simulator.true.model, true.parameters, param.estimator.candidate.model, simulator.candidate.model, likelihood.data.with.true.model, likelihoods.data.with.candidate.model, K)

bomeara/KLchecker documentation built on May 14, 2019, 11:15 a.m.