You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ENH: predict with weights, freq_weights and p_weights #3759
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.
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.)
(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.
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
"
Activity
josef-pkt commentedon Jan 13, 2020
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)
josef-pkt commentedon Jan 13, 2020
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.)
josef-pkt commentedon Feb 18, 2020
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
"