invDistWeighting: Inverse Distance Weighting

View source: R/InvDistWeighting.R

invDistWeightingR Documentation

Inverse Distance Weighting

Description

A function to calculate inverse distance weights associated with a vector of weights.

Usage

invDistWeighting(x, a = 0, ...)

Arguments

x

A numeric vector containing a set of distances.

a

A numeric value for the distance exponent (default 0).

...

Any further arguments to be ignored by the function.

Details

Particular cases are when a = 0 (the default), whereby all the weights have equal values (1/n, where n is length(x)) and when any d[i] == 0, whereby the weights are non-zero only for the zero-valued distance(s). The weights are equal to w[i] = d[i]^(-a)/S, where S is the sum of d[i]^(-a) for all the i.

Value

A numeric vector containing a set of weights summing to 1.

A numeric value.

Author(s)

Guillaume Guénard [aut, cre] (<https://orcid.org/0000-0003-0761-3072>), Pierre Legendre [ctb] (<https://orcid.org/0000-0002-3838-3305>)

Examples


## Example 1, equal weights (the function's default when a = 0):
d0 <- c(10,1,0.1,0.2,2,20,0.3)
w0 <- invDistWeighting(d0)
w0
sum(w0)

## Example 2, inverse distance (a = 1):
w1 <- invDistWeighting(d0, a=1)
w1
sum(w1)

## Example 3, inverse squared distance (a = 2):
w2 <- invDistWeighting(d0, a=2)
round(w2, 5)
sum(w2)

## A case some of the distances are 0:
d1 <- c(10,0,0.1,0.2,0,20,0.3)
w3 <- invDistWeighting(d1, a=1)  ## or any a != 0
w3
sum(w3)



guenardg/MPSEM documentation built on April 14, 2025, 3:53 p.m.