ks.dist | R Documentation |
This function compares two distributions (e.g. two frequency spectra) by computing the Kolmogorov-Smirnov distance
ks.dist(spec1, spec2, f = NULL, mel = FALSE,
plot = FALSE, type = "l",
lty = c(1, 2), col = c(2, 4),
flab = NULL, alab = "Cumulated amplitude",
flim = NULL, alim = NULL,
title = TRUE, legend = TRUE, ...)
spec1 |
any distribution, especially a spectrum obtained with |
spec2 |
any distribution, especially a spectrum obtained with
|
f |
sampling frequency of waves used to obtain |
mel |
a logical, if |
plot |
logical, if |
type |
if |
lty |
a vector of length 2 for the line type of |
col |
a vector of length 2 for the colour of |
flab |
title of the frequency axis. |
alab |
title of the amplitude axis. |
flim |
the range of frequency values. |
alim |
range of amplitude axis. |
title |
logical, if |
legend |
logical, if |
... |
other |
The Kolmogorov distance is the maximal distance between the
cumulated spectra. The function returns this distance and the
corresponding frequency. This is an adaptation of the statistic
computed by the non-parametric Kolmogorov-Smirnov test (see ks.test
).
The function returns a list of two items
D |
the Kolomogorov-Smirnov distance |
F |
the frequency (in KHz) where the Kolmogorov-Smirnov distance was found |
There is no p-value associated to the K-S distance.
If no frequency is provided, only the distance D.
Jerome Sueur, improved by Laurent Lellouch
kl.dist
, simspec
,
diffspec
, logspec.dist
, diffcumspec
, itakura.dist
## Comparison of two spectra and plot of the cumulated spectra with the K-S distance
data(tico)
tico1 <- spec(tico, at=0.65, plot=FALSE)
tico2 <- spec(tico, at=1.1, plot=FALSE)
ks.dist(tico1, tico2, plot=TRUE)
## mel scale
require(tuneR)
data(orni)
orni.mel <- melfcc(orni, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE)
orni.mel.mean <- apply(orni.mel$aspectrum, MARGIN=2, FUN=mean)
tico.mel <- melfcc(tico, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE)
tico.mel.mean <- apply(tico.mel$aspectrum, MARGIN=2, FUN=mean)
ks.dist(orni.mel.mean, tico.mel.mean, f=22050, mel=TRUE, plot=TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.