Skip to content

ENH: predict with weights, freq_weights and p_weights #3759

Open

Description

@josef-pkt

related:
margins with weights #2696
weighted sum/total #2851

how do we predict a weighted average over the population? similar to POM (potential outcome mean)

triggered by a WLS survey weights question
https://groups.google.com/d/msg/pystatsmodels/ZPVKynMo3ko/iUJcr9GdAwAJ

WLS does not have weights in predict. However, I think because of the linear structure we can just use a weighted average of the exog. But that will not work for nonlinear models, discrete and GLM.

Activity

  1. added this to the 0.10 milestone on Jun 14, 2017
  2. modified the milestones: 0.10, 0.12 on Jan 13, 2020
  3. josef-pkt commented on Jan 13, 2020

    @josef-pkt
    MemberAuthor

    bump as reminder

    Muller, Clemma J., and Richard F. MacLehose. 2014. “Estimating Predicted Probabilities from Logistic Regression: Different Methods Correspond to Different Target Populations.” International Journal of Epidemiology 43 (3): 962–70. https://doi.org/10.1093/ije/dyu029.

    (I have not looked at it and don't kno what it adds to the obvious)

  4. josef-pkt commented on Jan 13, 2020

    @josef-pkt
    MemberAuthor

    It's easy for user to compute a weighted average of predictions (over different exog).
    However, it is not obvious what the standard errors, cov of that weighted mean prediction should be.

    (Can we assume independence of individual predictions?
    The observations might be independent but the parameters are random variables that affect each prediction.)

  5. josef-pkt commented on Feb 18, 2020

    @josef-pkt
    MemberAuthor

    variation on this predicting averages for uniform distribution

    https://stackoverflow.com/questions/60274335/python-equivalent-of-emmeans-r-function
    https://cran.r-project.org/web/packages/emmeans/index.html
    Searle, S. R., F. M. Speed, and G. A. Milliken. 1980. “Population Marginal Means in the Linear Model: An Alternative to Least Squares Means.” The American Statistician 34 (4): 216–21. https://doi.org/10.2307/2684063.

    SAS has something similar

    (aside: Those equal and similar prior weights never made much sense to me. There isn't much in real life where things are uniformly distributed across levels of a categorical variable.
    Even gender is not close to even anymore if we include non-binary gender)

    If we allow for "population" weights in cells or on a grid, then we can compute for arbitrary population distributions, even uniform ones.

    Uniform weights in other packages, like emmeans, might make good test cases.

    https://support.sas.com/resources/papers/proceedings14/SAS060-2014.pdf
    has a simple example of two way salaries of university professors (assistant/full and male/female)
    "The LS-means ignore the sample size information in each group
    and assume a balanced gender distribution in the underlying population."
    even when 90% of professors are male? or in departments where 90% are female?

    Alternative weights could be row total and column total, or weights for subgroups counts in general.

    update emmeans allows for weights and has several predefined weights

    "
    Weights
    If weights is a vector, its length must equal the number of predictions to be averaged to obtain each
    EMM. If a matrix, each row of the matrix is used in turn, wrapping back to the first row as needed.
    When in doubt about what is being averaged (or how many), first call emmeans with weights =
    "show.levels".
    If weights is a string, it should partially match one of the following:
    "equal" Use an equally weighted average.
    "proportional" Weight in proportion to the frequencies (in the original data) of the factor combinations
    that are averaged over.
    "outer" Weight in proportion to each individual factor’s marginal frequencies. Thus, the weights
    for a combination of factors are the outer product of the one-factor margins
    "cells" Weight according to the frequencies of the cells being averaged.
    "flat" Give equal weight to all cells with data, and ignore empty cells.
    "show.levels" This is a convenience feature for understanding what is being averaged over. Instead
    of a table of EMMs, this causes the function
    "

  6. modified the milestones: 0.12, 0.13 on Aug 11, 2020
  7. removed this from the 0.13 milestone on Nov 24, 2023
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