oneill: O'Neill's entropy.

View source: R/oneill_leibovici_entropy.R

oneillR Documentation

O'Neill's entropy.

Description

This function computes O'Neill's entropy for a data matrix (see O'Neill et al, 1988).

Usage

oneill(
  data,
  win = spatstat.geom::owin(xrange = c(0, ncol(data)), yrange = c(0, nrow(data))),
  plotout = T
)

Arguments

data

A data matrix, can be numeric, factor, character, ...

win

Optional, an object of class owin, the observation window for data plotting

plotout

Logical. Default to TRUE, produces an informative plot as part of the function output.

Details

O'Neill's entropy index is based on the transformed variable Z, identifying couples of realizations of the variable of interest:

H_O(Z)=\sum p(z_r|C) \log(1/p(z_r|C))

where z_r=(x_i, x_{i'}) is a generic couple of realizations of the study variable X. The conditioning on C for grid data means that only contiguous couples are considered, i.e. couples of pixels sharing a border. All contiguous couples of realizations of the variable of interest are counted and their relative frequencies are used to compute the index. The maximum value for O'Neill's entropy is \log(I^2) where I is the number of categories of X. The relative version of O'Neill's entropy is obtained by dividing the entropy value by its maximum, and is useful for comparison across datasets with a different number of categories. The function is able to work with grids containing missing data, specified as NA values. All NAs are ignored in the computation and only couples of non-NA observations are considered.

Value

a list of four elements:

  • oneill O'Neill's entropy

  • range the theoretical range of O'Neill's entropy, from 0 to \log(I^2)

  • rel.oneill O'Neill's relative entropy

  • probabilities a table with absolute frequencies and estimated probabilities (relative frequencies) for all couple categories

Moreover, a plot of the dataset is produced.

Examples

#numeric data, square grid
data=matrix(sample(1:5, 100, replace=TRUE), nrow=10)
oneill(data)
#plot data
plot(as.im(data, W=square(nrow(data))),
     col=grDevices::gray(seq(1,0,length.out=length(unique(c(data))))),
     main="", ribbon=TRUE)

#character data, rectangular grid
data=matrix(sample(c("a","b","c"), 300, replace=TRUE), nrow=30)
oneill(data)
#plot data
plot(as.im(data, W=owin(xrange=c(0,ncol(data)), yrange=c(0,nrow(data)))),
     col=terrain.colors(length(unique(c(data)))),
     main="", ribbon=TRUE)

#data with missing values
data=matrix(sample(1:5, 100, replace=TRUE), nrow=10)
data=rbind(rep(NA, ncol(data)), data, rep(NA, ncol(data)))
oneill(data)


SpatEntropy documentation built on Nov. 17, 2023, 5:10 p.m.