Description Usage Arguments Details Value Author(s) Examples

View source: R/weightedStats.R

Computes the weighted histogram of a set of observations with a given set of weights.

1 |

`x` |
Numeric vector of observed values. |

`breaks` |
Vector of breakpoints for the histogram. |

`weights` |
Numeric vector of weights for the observed values. |

This low-level function computes (but does not plot) the weighted
histogram of a vector of observations `x`

using a given
vector of `weights`

.

The arguments `x`

and `weights`

should be numeric vectors of
equal length. They may include `NA`

or infinite values.

The argument `breaks`

should be a numeric vector whose entries
are strictly increasing. These values define the boundaries between the
successive histogram cells.
The breaks *do not* have to span the range
of the observations.

There are `N-1`

histogram cells, where `N = length(breaks)`

.
An observation `x[i]`

falls in the `j`

th cell if
`breaks[j] <= x[i] < breaks[j+1]`

(for `j < N-1`

)
or
`breaks[j] <= x[i] <= breaks[j+1]`

(for `j = N-1`

).
The weighted histogram value `h[j]`

for the `j`

th cell is
the sum of `weights[i]`

for all observations `x[i]`

that
fall in the cell.

Note that, in contrast to the function `hist`

,
the function `whist`

does not require the breakpoints to span the
range of the observations `x`

. Values of `x`

that fall outside the
range of `breaks`

are handled separately; their total weight
is returned as an attribute of the histogram.

A numeric vector of length `N-1`

containing the
histogram values, where `N = length(breaks)`

.

The return value also has attributes `"low"`

and `"high"`

giving the total weight of all observations that are less than
the lowest breakpoint, or greater than the highest breakpoint,
respectively.

and \rolf

with thanks to Peter Dalgaard.

1 2 3 4 |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.