Skip to content

SUMM: weights - which kinds #2848

Open
Open

Description

@josef-pkt

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 weights for var_weights
  • GEE uses weights for prob_weights according to docstring
  • GLM will get freq_weights in Glm weights rebased #2835
  • stats weightstats uses weights for freq_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

Activity

  1. josef-pkt commented on Mar 29, 2016

    @josef-pkt
    MemberAuthor

    (searching for "weights" has currently 96 open issues and PRs.)

  2. josef-pkt commented on Oct 6, 2016

    @josef-pkt
    MemberAuthor

    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) and
    wcov = (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)

  3. josef-pkt commented on Jul 19, 2017

    @josef-pkt
    MemberAuthor
  4. josef-pkt commented on May 10, 2023

    @josef-pkt
    MemberAuthor

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions