Repository navigation
Description
Stata has now 4 kinds of weights fweights, aweights, pweights and iweights. Probability weights, pweights, have been added after Stata 12 (which was my first Stata). "U" manual has useful information.
We have weights and freq_weights
My prefered terminology is to be more explicit than Stata, e.g. freq_weights, var_weights and prob_weights. I don't know about what to do with importance weights iweights yet. Maybe for outliers and robust estimation.
We don't impose some of the restriction on weights as Stata (eg. non-integer freq_weights) and we don't normalize var_weights in WLS like Stata does or did for aweights.
current status
- WLS/GLS: uses
weightsforvar_weights - GEE uses
weightsforprob_weightsaccording to docstring - GLM will get
freq_weightsin Glm weights rebased #2835 - stats weightstats uses
weightsforfreq_weights
Implication of weights in models and results
For estimation of the parameters most of the weights can be combined. There are some differences for estimating cov_params, and especially robust cov_params.
freq_weights- they produce identical results as repeating the observations (if freq_weights are integers).
- unclear for now: residuals for diagnostics and impact on leave one observation out statistics.
var_weights- ...
prob_weights- useful for treatment effects estimation and survey adjustments, and correcting for missing at random, MAR, observations
importance_weights- ???
- RLM? robust GLM?
Implementation
- we shouldn't have too many redundant calculations if there are no weights
- adjusting all the postestimation features and options will require work. Add warnings for unchecked things.
- figure out where or when we can combine different weights, and what we need to keep track of when the implications and calculations differ across weights.
issues and PRs
see also issue label topic-weights
- weights: repeat versus mean/variance in LEF family #2840 GLM/LEF weights and aggregation
- ENH: GMM with observation weights, heteroscedasticity #2646 weights in GMM
- SUMM/ENH rare events, unbalanced sample, matching, weights, tail #2701 SUMM for several applications of weights
- ...
Activity
josef-pkt commentedon Mar 29, 2016
(searching for "weights" has currently 96 open issues and PRs.)
josef-pkt commentedon Oct 6, 2016
an issue that showed up somewhere when adding weights to GLM in the robust sandwich covariance calculations:
rescaled variables versus explicit weights: for second moment we use square root(weights) transformed variables as in WLS.
However, when we want to calculate a weighted mean, then we need the weights itself and not the square root of weights. Keeping weights separate instead of going the WLS transformation route will avoid ambiguities about weights versus sqrt weights.
The literature on outlier robust covariance calculations avoid including the transformation in the weights, so it's just
wmean = sum(weights * x) / sum(weights)andwcov = (x.T * weights).dot(x) / (sum(weights) - ddof)R weighted covariance assumes weights <= 1 and uses (1 - sum(weights**2) in the denominator https://stat.ethz.ch/R-manual/R-devel/library/stats/html/cov.wt.html (as in numpy issue, IIRC)
In the uniform weighted case, this assumes
w_i = 1 / nobs.Frequency weights and internal weight normalization in Stata assume
sum(weights)is nobs (number of actual observations)josef-pkt commentedon Jul 19, 2017
similar argument for Stata type of weights in Julias
https://discourse.julialang.org/t/usage-of-different-types-of-weights/4780
josef-pkt commentedon May 10, 2023
https://en.wikipedia.org/wiki/Weighted_arithmetic_mean
has weighted mean and it's standard error for several versions of weights.
Note: fixed weights that are independent of sampling and sample distribution are just linear combination of random variables.
The estimate for the variance of the underlying random variables is not affected by weights.
This is similar to new "weights" in get_prediction, where variance of the underlying parameter estimates is not affected by the weights.
see also https://stats.stackexchange.com/questions/252162/se-of-weighted-mean
latest answer uses also statsmodels weightstats
also relevant for cov_type computation #2829