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
REF/ENH: extend cov_type to work with weights #2829
(starting a separate issue for this) #2805 implements frequency weights for GLM, but it doesn't work for robust covariances
one issue is restrictive assumption for nobs, k_params, see #2827 but doesn't apply for HC
debugging HC0 for GLM Poisson:
using _get_sandwich_arrays(results)
hessian looks correct, relative difference approximately 0.002 (numerical noise ?)
xu, i.e. scoreobs looks also fine, one is the repeat (group sum) version of the other in replicated sample.
but xu.T @ xu differs by a large amount
Thinking incorrectly:
xu has the weights. so xu **2 has the weights in squares.
we need sqrt(weights) -> check weighted covariance in stats
WLS.whiten uses sqrt(weights), so xu = wexog * wresid has weights not square weights.
(but score_obs uses exog and also just has weights ???)
time for some math
in any case: if I divide xu by sqrt(weights) (or sqrt(exposure)), then the two versions agree at 3e-11
We run again into the fundamental difference across different definitions of weights.
freq_weights are additive in mean and variance.
weighted average (linear combination of random variables) has weights square in covariance calculations compared to mean calculations.
(same problem and "thinko" I ran into in weight_stats)
Just another piece: I just realized that for simple variance calculations we might mean different things when weighting, one source of the confusion.
a average cov i.e. sum_i w_i * x_i * x_i' weighted average of outer product of x
(co)variance of the weighted mean or average (i.e. sem): mean = sum_i w_i * x_i is a linear combination of random variables, so variance of this sum uses squared coefficients V(mean) = sum_i w_i**2 * V(x_i), simple sum assumes independence.
If w_i = 1, then those coincide but not for varying weights.
"You better watch out, you better not cry, because ...`
related: #3335 probability weights for complex surveys
cov(score) with weights is also needed for some measures to check information matrix equality and amount of misspecification #6516 (comment)
related
score_factor and score_obs have iweights included.
If we want to compute autocorrelation, then we shouldn't include freq_weights in the computation.
Correlation across observations doesn't really make sense in model with freq_weights if it is intepreted as aggregating observations with identical data.
It might work if weights are constant for correlated observations, e.g. cluster weights instead of observation weights.
maybe a serial correlation example that makes sense
Each period we survey a random number of individuals about an issue, without individual specific explanatory variables, we can just aggregate them, and e.g. count how many say yes and how many say no. i.e. freq_weights for individuals with same answer
What's the relevant correlation computation for cov(score)?
Exposure #2831 will work similarly as freq_weights, i.e. we have a exogenously given random number of exposed in each period.
scaling score_obs by var_weights sounds fine for correlation, analogously to WLS, That just removes unequal variances and computes correlation instead of covariance.
(1)
What's the meaning of correlation across observations if freq_weights represent combined samples?
AFAICS, it does not make sense, i.e. we need individual observations to compute correlation.
This would mean raising an exception for freq_weights plus correlation robust cov_type.
(2)
Using freq_weights for prob_weights, e.g. survey_weights, inverse propability/propensity weighting or outlier robustness weighting.
Observations still represent basic unit, so correlation between observations still makes sense.
However, we need to handle different weights across units/observations. (AFAIR, I did the math once for that, but don't remember).
One possibility, treat it as a generic M-estimator ignoring the weights interpretation, and just use generic formulas for sandwiches for M-estimators (cov(score), hessian).
If we want to distinguish cases (1) and (2), then we need another weight category, similar to Stata's pweights. #4234
As in Stata, it would not affect parameter estimates nor nonrobust and HC cov_types, (Stata switches default cov_type to HC1).
But it would affect interpretation of correlation and provide a way to derive those cov_types.
possible name gen_weights for generic weighting of observations.
Related:
What should be nobs for freq_weights and gen_weights? relevant mainly for df_resid, and maybe robust information criteria.
In contrast to Stata we do not normalize the user provided weights.
nobs = sum(freq_weights)
This means that the user can control how many observations are represented by the data.
In RLM, df_resid = number of observations(rows) - number of parameters
standard definition independent of weight. However, weights are just a computational tool in IRLS and are implied by objective function. Those are not user provided freq or gen weights. RLM.fit does not have explicit use_t option, so I guess we only have normal and chisquare distribution in hypothesis tests, and consequently, nobs, df_resid plays only a minor role for inference. However, df_resid is explicitly use in cov_params computation (IIRC, small sample correction in the original Huber article).
I don't know what definition of nobs/df_resid are used in the survey literature and robust literature (with exog outlier weights).
I found El Asri et al. while browsing articles for weights, survey weights for #9070
This includes cluster robust cov_type with individual weights.
It looks like generic weights, not a specific interpretation like var_weights and freq_weights
Activity
josef-pkt commentedon Dec 26, 2016
Just another piece: I just realized that for simple variance calculations we might mean different things when weighting, one source of the confusion.
sum_i w_i * x_i * x_i'weighted average of outer product of xsem):mean = sum_i w_i * x_iis a linear combination of random variables, so variance of this sum uses squared coefficientsV(mean) = sum_i w_i**2 * V(x_i), simple sum assumes independence.If
w_i = 1, then those coincide but not for varying weights."You better watch out, you better not cry, because ...`
related: #3335 probability weights for complex surveys
josef-pkt commentedon Dec 9, 2020
cov(score) with weights is also needed for some measures to check information matrix equality and amount of misspecification
#6516 (comment)
related
score_factor and score_obs have iweights included.
If we want to compute autocorrelation, then we shouldn't include freq_weights in the computation.
Correlation across observations doesn't really make sense in model with freq_weights if it is intepreted as aggregating observations with identical data.
It might work if weights are constant for correlated observations, e.g. cluster weights instead of observation weights.
maybe a serial correlation example that makes sense
Each period we survey a random number of individuals about an issue, without individual specific explanatory variables, we can just aggregate them, and e.g. count how many say yes and how many say no. i.e. freq_weights for individuals with same answer
What's the relevant correlation computation for cov(score)?
Exposure #2831 will work similarly as freq_weights, i.e. we have a exogenously given random number of exposed in each period.
scaling score_obs by var_weights sounds fine for correlation, analogously to WLS, That just removes unequal variances and computes correlation instead of covariance.
josef-pkt commentedon May 9, 2023
bump
correlation robust cov_type, cluster, hac, panel
(1)
What's the meaning of correlation across observations if freq_weights represent combined samples?
AFAICS, it does not make sense, i.e. we need individual observations to compute correlation.
This would mean raising an exception for freq_weights plus correlation robust cov_type.
(2)
Using freq_weights for prob_weights, e.g. survey_weights, inverse propability/propensity weighting or outlier robustness weighting.
Observations still represent basic unit, so correlation between observations still makes sense.
However, we need to handle different weights across units/observations. (AFAIR, I did the math once for that, but don't remember).
One possibility, treat it as a generic M-estimator ignoring the weights interpretation, and just use generic formulas for sandwiches for M-estimators (cov(score), hessian).
If we want to distinguish cases (1) and (2), then we need another weight category, similar to Stata's pweights.
#4234
As in Stata, it would not affect parameter estimates nor nonrobust and HC cov_types, (Stata switches default cov_type to HC1).
But it would affect interpretation of correlation and provide a way to derive those cov_types.
possible name
gen_weightsfor generic weighting of observations.Related:
What should be
nobsfor freq_weights and gen_weights? relevant mainly for df_resid, and maybe robust information criteria.In contrast to Stata we do not normalize the user provided weights.
nobs = sum(freq_weights)
This means that the user can control how many observations are represented by the data.
In RLM, df_resid = number of observations(rows) - number of parameters
standard definition independent of weight. However, weights are just a computational tool in IRLS and are implied by objective function. Those are not user provided freq or gen weights.
RLM.fitdoes not have explicituse_toption, so I guess we only have normal and chisquare distribution in hypothesis tests, and consequently, nobs, df_resid plays only a minor role for inference. However, df_resid is explicitly use in cov_params computation (IIRC, small sample correction in the original Huber article).I don't know what definition of nobs/df_resid are used in the survey literature and robust literature (with exog outlier weights).
josef-pkt commentedon Nov 25, 2023
I found El Asri et al. while browsing articles for weights, survey weights for #9070
This includes cluster robust cov_type with individual weights.
It looks like generic weights, not a specific interpretation like var_weights and freq_weights
El Asri, M., D. Blanke, and E. Gabriel. “Weighted M-Estimators for Multivariate Clustered Data.” Statistics & Probability Letters 112 (May 1, 2016): 26–34. https://doi.org/10.1016/j.spl.2016.01.016.