oss.jsd: Jensen Shannon Divergence

View source: R/oss.jsd.R

oss.jsdR Documentation

Jensen Shannon Divergence

Description

This function calculates the Jensen-Shannon Divergence score between two probability distributions, P and Q. In sampling design for digital soil mapping applications, it can be used to determine the statistical distance between a sample plan and the population from which the sample plan was derived

Usage

oss.jsd(p, q, type = NULL, unit = "log2")

Arguments

p

numeric

q

numeric

type

character Can be one of 'prob' or 'count'.

unit

character Can be one of log base 2 ('log2'), log base 10 ('log10') or natural log ('log').

Value

numeric

Examples

#let us create data for testing, we need 2 probability distributions
prob1 <- c(0.002, 0.020, 0.127, 0.343, 0.362, 0.119, 0.025, 0.002)
prob2<- c(0.001, 0.019, 0.325, 0.145, 0.326, 0.028, 0.153, 0.003)
sum(prob1)
sum(prob2)
barplot(prob1)
barplot(prob2)
# we now run the JS Divergence
# it is a symmetrical test, which means Q|P == P|Q
# if we enter the same distribution as both P and Q, we confirm a score of 0 or no divergence
oss.jsd(p=prob1, q=prob1, type='prob', unit='log2')
# P|Q
oss.jsd(p=prob1, q=prob2, type='prob', unit='log2')
# Q|P
oss.jsd(p=prob2, q=prob1, type='prob', unit='log2')


newdale/onsoilsurvey documentation built on Jan. 5, 2024, 1:35 a.m.