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
Per observation weigts for stats.weightstats.DescrStatsW #3186
A quick peek at the code also made me think this wouldn't be hard (though not immediately obvious if degrees of freedom would be tricky). Unit tests would be a bit of work, yes. If this goes ahead, I could have a go at providing some numbers.
This requires more thinking or background information before we can add it to correlation calculation.
Currently, the main interpretation for the weights in weightstats is as frequency or case weights. The interpretation of the weights doesn't matter for many things, but it makes a difference in the degrees of freedom calculations (and maybe some other parts).
Having variable specific weight vectors for vectorized univariate measures is theoretically no problem.
However, for multivariate measures where one row is interpreted as an observation, e.g. for correlation or paired t-test, frequency weights don't really make sense. Switching to variance_weights (precision or uncertainty) interpretation, requires that we have proper combination of weights and the correct degrees of freedom.
The basic idea in this case, AFAICS, is that we want to downweight observation where the combined weight reflects a large uncertainty and increase the weights for observations where the combined weight reflects small uncertainty.
I don't know how weights should be combined for one observation (similar question paired t-test with unequal observation specific variances). I'm also a bit doubtful whether the source of uncertainty, measurement error, different sample sizes or heteroscedasticity doesn't affect the calculation or/and interpretation of the overall correlation coefficient.
measurement errors is a different issue, and I don't have an overview.
(repeated measure(ment) models might be helpful, e.g. measurement error as a random effect with one observation per cluster which would give just a mixture distribution with known mixing distribution. The problem is that I looked mostly at mean estimates and I'm not able to quickly figure out second moment estimators from scratch)
e.g. https://www3.nd.edu/~rwilliam/stats2/l21.pdf for the attenuation bias in the correlation estimate with measurement errors. (I got this on my own but I'm not sure my correction of the bias would be correct.)
Based on a simple calculation with normal distribution (*), I think that all variables can be divided by the known variance (observation and variable specific weight) and the correlation can be calculated in the standard way. (assumes demeaned by common mean and identical correlation and the only difference is in variance)
(as a note, mainly for myself:
Hassler, Uwe, and Thorsten Thadewald. 2003. “Nonsensical and Biased Correlation Due to Pooling Heterogeneous Samples.” Journal of the Royal Statistical Society. Series D (The Statistician) 52 (3): 367–79.
which is referenced by the PMC article above, points out Simpson's paradox for correlation.
However that looks to me just like estimating between-group correlation instead of intraclass correlation, or something like that.
I didn't find anything quickly on between-group in contrast to intraclass correlation.
)
D_i needs to be estimated mabye: 1/w_i * pooled weighted variance (w_i is vector over variables)
we can add a nobs_i in there, but we don't have optimally weighted R-hat, I guess.
@drevicko I don't see a way right now. However, if you find a description for another statistics package or a reference that would do what you need, then I can look into or help with implementing it.
I looked for a bit at the measurement error literature in #3187 but the only things for correlation coefficient that I looked at, use a bivariate normality assumption and need nonlinear optimization to solve for the variances and correlation, and seems to run easily into optimization problems and corner solutions.
Most of the literature I saw was focused on regression problems, which is related but doesn't directly estimate the correlation. The implied estimate from the corrected covariance matrix would not fit into the simple weighting structure of DescrStatsW and will need separate modules and functions.
It's likely that there are things that would work but that I missed in my relatively brief look at measurement error problem. Maybe just a simple correction to the covariance would be already enough, to remove most of the attenuation bias from the correlation. (How good that is would also depend on the sample size, and might not be very good in small samples.)
Ho Josef, Thanks for all the thought and effort!
When I posed this, I had thought there was an R package that did what I was after, but I now think that's not true, indeed all the weighted covariance work I can find does not do this.
It looks like an analytic approach is not trivial and my guess is that if you didn't find it in your research, it's probably not in the literature (if you can think of a good approach, perhps worth putting it there! ;).
That said, the best approach I can imagine right now would be the sampling approach in that blog post. For that, you need either errors provided as a distribution or to make some assumption about what distribution a "confidence" measure represent.s
All that is non-trivial, so I think for now perhaps we leave it be.
Thanks again for looking into it!
to point out: the original case of having different weights for different variables is not ruled out. However, AFAICS, it does not for the measurement error case (with uncorrelated measurement errors).
example: cross-observation correlation when observations have different weights, simplest case would be first order autocovariance between observation i with weight w_i and observation i-1 with weight w_{i-1}.
(If seen it in some formulas for outlier robust estimation and for the correlation robust sandwich cov_params in probability weighting for complex surveys.)
Activity
josef-pkt commentedon Sep 2, 2016
@drevicko What's your usecase?
I had thought about it briefly when I wrote this, but my impression was that it is not commonly enough used to be worth the complication.
It might not be difficult to add the feature (to almost (?) all methods), more work will be to add unit tests for all the methods.
drevicko commentedon Sep 2, 2016
I have annotation data, where I get a confidence level (0-1) for each variable/item combination based on the consistency of multiple annotators.
I can imagine other use cases where the reliability of each individual measurement can vary, though if you can estimate an error distribution for each measurement, you may be better off with an sampling approach like in this blog:
http://www.exegetic.biz/blog/2013/08/finding-correlations-in-data-with-uncertainty-bootstrap/
A quick peek at the code also made me think this wouldn't be hard (though not immediately obvious if degrees of freedom would be tricky). Unit tests would be a bit of work, yes. If this goes ahead, I could have a go at providing some numbers.
josef-pkt commentedon Sep 2, 2016
I skimmed parts of the blog post.
This requires more thinking or background information before we can add it to correlation calculation.
Currently, the main interpretation for the weights in
weightstatsis as frequency or case weights. The interpretation of the weights doesn't matter for many things, but it makes a difference in the degrees of freedom calculations (and maybe some other parts).Having variable specific weight vectors for vectorized univariate measures is theoretically no problem.
However, for multivariate measures where one row is interpreted as an observation, e.g. for correlation or paired t-test, frequency weights don't really make sense. Switching to variance_weights (precision or uncertainty) interpretation, requires that we have proper combination of weights and the correct degrees of freedom.
after a bit of search for "combining correlation":
this http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3765419/
"Comprehensive analysis of correlation coefficients estimated from pooling heterogeneous microarray data"
might be a likely starting point for correlation estimates under unequal variance, or unequal subsample sizes. (based on quick skimming of formulas)
(There also seems to be something in the psychology literature in the early 90s but I didn't see anything useful in very quick browsing)
The basic idea in this case, AFAICS, is that we want to downweight observation where the combined weight reflects a large uncertainty and increase the weights for observations where the combined weight reflects small uncertainty.
I don't know how weights should be combined for one observation (similar question paired t-test with unequal observation specific variances). I'm also a bit doubtful whether the source of uncertainty, measurement error, different sample sizes or heteroscedasticity doesn't affect the calculation or/and interpretation of the overall correlation coefficient.
josef-pkt commentedon Sep 3, 2016
maybe these references all consider other cases, that's what it looks like to me based on skimming several things.
I have to give up here for now, I don't find a meaningful interpretation for the weights.
I wrote the part below the line yesterday before realizing that just using heteroscedasticity doesn't give me any uncertainty or precision on the individual observations. (weights in this case might depend on 4th moment as in gamma distribution/GLM for second moments)
maybe Fisher transform or tanh with associated variance would be a possible normal approximation shortcut http://mathoverflow.net/questions/57908/combining-correlation-coefficients/57921#57921
measurement errors is a different issue, and I don't have an overview.
(repeated measure(ment) models might be helpful, e.g. measurement error as a random effect with one observation per cluster which would give just a mixture distribution with known mixing distribution. The problem is that I looked mostly at mean estimates and I'm not able to quickly figure out second moment estimators from scratch)
e.g. https://www3.nd.edu/~rwilliam/stats2/l21.pdf for the attenuation bias in the correlation estimate with measurement errors. (I got this on my own but I'm not sure my correction of the bias would be correct.)
Based on a simple calculation with normal distribution (*), I think that all variables can be divided by the known variance (observation and variable specific weight) and the correlation can be calculated in the standard way. (assumes demeaned by common mean and identical correlation and the only difference is in variance)
(as a note, mainly for myself:
Hassler, Uwe, and Thorsten Thadewald. 2003. “Nonsensical and Biased Correlation Due to Pooling Heterogeneous Samples.” Journal of the Royal Statistical Society. Series D (The Statistician) 52 (3): 367–79.
which is referenced by the PMC article above, points out Simpson's paradox for correlation.
However that looks to me just like estimating between-group correlation instead of intraclass correlation, or something like that.
I didn't find anything quickly on between-group in contrast to intraclass correlation.
)
(*)
x_i ~ N(0, V) V = D_i R D_i
(D_i)^{-1} x_i ~ N(0, R)
R-hat = sum_i (D_i)^{-1} x_i x_i' (D_i)^{-1}
D_i needs to be estimated mabye: 1/w_i * pooled weighted variance (w_i is vector over variables)
we can add a nobs_i in there, but we don't have optimally weighted R-hat, I guess.
josef-pkt commentedon Sep 9, 2016
@drevicko I don't see a way right now. However, if you find a description for another statistics package or a reference that would do what you need, then I can look into or help with implementing it.
I looked for a bit at the measurement error literature in #3187 but the only things for correlation coefficient that I looked at, use a bivariate normality assumption and need nonlinear optimization to solve for the variances and correlation, and seems to run easily into optimization problems and corner solutions.
Most of the literature I saw was focused on regression problems, which is related but doesn't directly estimate the correlation. The implied estimate from the corrected covariance matrix would not fit into the simple weighting structure of DescrStatsW and will need separate modules and functions.
It's likely that there are things that would work but that I missed in my relatively brief look at measurement error problem. Maybe just a simple correction to the covariance would be already enough, to remove most of the attenuation bias from the correlation. (How good that is would also depend on the sample size, and might not be very good in small samples.)
drevicko commentedon Sep 9, 2016
Ho Josef, Thanks for all the thought and effort!
When I posed this, I had thought there was an R package that did what I was after, but I now think that's not true, indeed all the weighted covariance work I can find does not do this.
It looks like an analytic approach is not trivial and my guess is that if you didn't find it in your research, it's probably not in the literature (if you can think of a good approach, perhps worth putting it there! ;).
That said, the best approach I can imagine right now would be the sampling approach in that blog post. For that, you need either errors provided as a distribution or to make some assumption about what distribution a "confidence" measure represent.s
All that is non-trivial, so I think for now perhaps we leave it be.
Thanks again for looking into it!
josef-pkt commentedon Dec 26, 2016
to point out: the original case of having different weights for different variables is not ruled out. However, AFAICS, it does not for the measurement error case (with uncorrelated measurement errors).
example: cross-observation correlation when observations have different weights, simplest case would be first order autocovariance between observation
iwith weightw_iand observationi-1with weightw_{i-1}.(If seen it in some formulas for outlier robust estimation and for the correlation robust sandwich cov_params in probability weighting for complex surveys.)