View source: R/InvDistWeighting.R
invDistWeighting | R Documentation |
A function to calculate inverse distance weights associated with a vector of weights.
invDistWeighting(x, a = 0, ...)
x |
A numeric vector containing a set of distances. |
a |
A numeric value for the distance exponent (default |
... |
Any further arguments to be ignored by the function. |
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
.
A numeric vector containing a set of weights summing to 1.
A numeric value.
Guillaume Guénard [aut, cre] (<https://orcid.org/0000-0003-0761-3072>), Pierre Legendre [ctb] (<https://orcid.org/0000-0002-3838-3305>)
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.