R: Weighted Median, Quantiles or Variance

weighted.median {spatstat} | R Documentation

## Weighted Median, Quantiles or Variance

### Description

Compute the median, quantiles or variance of a set of numbers which have weights associated with them.

### Usage

    weighted.median(x, w, na.rm = TRUE)

    weighted.quantile(x, w, probs=seq(0,1,0.25), na.rm = TRUE)

    weighted.var(x, w, na.rm = TRUE)

### Arguments

`x` | Data values. A vector of numeric values, for which the median or quantiles are required.
`w` | Weights. A vector of nonnegative numbers, of the same length as `x`.
`probs` | Probabilities for which the quantiles should be computed. A numeric vector of values between 0 and 1.
`na.rm` | Logical. Whether to ignore `NA` values.

### Details

The `i`th observation `x[i]` is treated as having a weight proportional to `w[i]`.

The weighted median is a value `m` such that the total weight of data to the left of `m` is equal to half the total weight. If there is no such value, linear interpolation is performed.

### Value

A numeric value or vector.

### Author(s)

Adrian Baddeley Adrian.Baddeley@curtin.edu.au.

### See Also

`quantile`, `median`.

### Examples

      x <- 1:20
      w <- runif(20)
      weighted.median(x, w)
      weighted.quantile(x, w)
      weighted.var(x, w)

[Package spatstat version 1.54-0 Index]