harmonicDist: Harmonic Mean Distance

Description Usage Arguments Details Author(s) Examples

View source: R/distanceFunctions.R

Description

Calculates harmonic mean distance between points. Data are subset prior to calculating distances (see details).

Usage

1
2
harmonicDist(dfv, column.nums = 1:ncol(dfv), subset = 1:nrow(dfv),
  S = NULL)

Arguments

dfv

a data frame containing observations in rows and statistics in columns.

column.nums

indexes the columns of the data frame that will be used to calculate harmonic mean distances (all other columns are ignored).

subset

index the rows of the data frame that will be used to calculate the covariance matrix (unless specified manually).

S

the covariance matrix used to normalise the data in the harmonic mean calculation. Leave as NULL to use the ordinary covariance matrix calculated using cov(dfv[subset,column.nums]).

Details

Takes a matrix or data frame as input, with observations in rows and statistics in columns. The parameter "column.nums" is used to select which columns to use in the analysis, all other columns are ignored. The covariance is then calculated on a subset of this data, specified using the parameter "subset" (which defaults to all observations). All distances in the calculation are normalised by multiplying by the inverse of this covariance matrix. Alternatively, this matrix can be specified manually as an additional argument. The harmonic mean distance of a point is calculated as the harmonic mean of the distance between this point and all points in the chosen subset.

Note that this method cannot handle any NA values.

Author(s)

Robert Verity r.verity@imperial.ac.uk

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
## Not run: 
# create a data frame of observations
df <- data.frame(x=rnorm(100),y=rnorm(100))

# calculate harmonic mean distances
distances <- harmonicDist(df)

# use this distance to look for outliers
Q95 <- quantile(distances, 0.95)
which(distances>Q95)

## End(Not run)

NESCent/MINOTAUR documentation built on May 7, 2019, 6:01 p.m.