5.18. pypfilt.stats¶
-
pypfilt.stats.
cov_wt
(x, wt, cor=False)¶ Estimate the weighted covariance matrix, based on a NumPy pull request.
Equivalent to
cov.wt(x, wt, cor, center=TRUE, method="unbiased")
as provided by thestats
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 (or 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 – The data points.
- weights – The normalised weights.
- biased – Use a biased variance estimator.
Returns: A tuple that contains the weighted average and weighted variance.
-
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 – The numerical data.
- weights – The weight of each data point.
- probs – The quantile(s) to compute.
Returns: The array of weighted quantiles.
-
pypfilt.stats.
cred_wt
(x, weights, creds)¶ Calculate weighted credible intervals.
Parameters: - x – The numerical data.
- weights – The weight of each data point.
- creds (List(int)) – The credible interval(s) to compute (
0..100
, where0
represents the median and100
the entire range).
Returns: A dictionary that maps credible intervals to the lower and upper interval bounds.