6.17. pypfilt.stats

pypfilt.stats.cov_wt(x, wt, cor=False)

Estimate the weighted covariance or correlation matrix.

Equivalent to cov.wt(x, wt, cor, center=TRUE, method="unbiased") as provided by the stats package for R.

Parameters:
  • x – A 2-D array; columns represent variables and rows represent observations.
  • wt – A 1-D array of observation weights.
  • cor – Whether to return a correlation matrix instead of a covariance matrix.
Returns:

The covariance matrix (if cor=False) or the correlation matrix (if cor=True).

pypfilt.stats.avg_var_wt(x, weights, biased=True)

Return the weighted average and variance (based on a Stack Overflow answer).

Parameters:
  • x – A 1-D array of values.
  • weights – A 1-D array of normalised weights.
  • biased – Use a biased variance estimator.
Returns:

A tuple that contains the weighted average and weighted variance.

Raises:

ValueError – if x or weights are not one-dimensional, or if x and weights have different dimensions.

pypfilt.stats.qtl_wt(x, weights, probs)

Equivalent to wtd.quantile(x, weights, probs, normwt=TRUE) as provided by the Hmisc package for R.

Parameters:
  • x – A 1-D array of values.
  • weights – A 1-D array of weights.
  • probs – The quantile(s) to compute.
Returns:

The array of weighted quantiles.

Raises:

ValueError – if x or weights are not one-dimensional, or if x and weights have different dimensions.

pypfilt.stats.cred_wt(x, weights, creds)

Calculate weighted credible intervals.

Parameters:
  • x – A 1-D array of values.
  • weights – A 1-D array of weights.
  • creds (List(int)) – The credible interval(s) to compute (0..100, where 0 represents the median and 100 the entire range).
Returns:

A dictionary that maps credible intervals to the lower and upper interval bounds.

Raises:

ValueError – if x or weights are not one-dimensional, or if x and weights have different dimensions.