Logarithmic score and L2 distance between two densities on the simplex (trivariate case).
Logarithmic score and L2 distance between two densities on the simplex (trivariate case).
Computes the Kullback-Leibler divergence and the L2 distance between the "true" density (true.dens) and an estimated density (est.dens).
scores3D(true.dens, est.dens, npoints, eps)
Arguments
true.dens: A npoints*npoints matrix: The reference density, typically the distribution from which data was simulated. Must be a valid density argument to be passed to dgridplot, with equi=FALSE.
est.dens: The estimated density: of the same type as true.dens.
npoints: Number of grid points used to construct the density matrices (see discretize).
eps: Minimum distance from a grid point to the simplex boundary (see discretize).
Returns
A list made of
check.true: The result of the rectangular integration of true.dens. It should be equal to one. If not, re size the grid.
check.true: Idem, replacing true.dens with est.dens.
L2score: The estimated L2 distance.
KLscore: The estimated Kullback-Leibler divergence between the two re-normalized densities, using check.true and check.est as normalizing constants (this ensures that the divergence is always positive).
Details
The integration is made viarect.integrate: The discretization grid corresponding to the two matrices must be constructed with discretize(npoints, eps, equi=FALSE).