Repository navigation
Correlation#3842
Conversation
Merge new master
- Added KMO and Bartlett Sphericity functions - Added respective tests functions - Added tests.csv file with test Dataset
|
@josef-pkt Just to inform I've done this new PR with correlation.py and respective tests regarding KMO and Bartlett Sphericity tests. Cheers |
|
@josef-pkt Please advise where to put the tests.csv file. The automated checks are failing due to errors like file not found. Cheers |
|
@Sarmentor I'm not sure what the problem with the csv file is, there are several possibilities. The easiest is to follow our standard pattern, put the file in tests/results and use the full file path e.g. another test in stats |
-Changes in how test functions call test dataset
…on v2 and v3 packages results, regarding decimal floating point values
|
@josef-pkt @bashtage Hi! I believe the tests are all ok. I'll be out for the weekend. I'll be back next monday, if you need more feedback from me please leave a message and I'll work on that next week. |
|
@josef-pkt Hi! Can you please confirm if this merge will be associated with release 0.9? |
|
@Sarmentor Yes, it will be in 0.9 for sure. |
|
@josef-pkt Hi! Should I close the other two PRs that are now obsolete? |
|
@Sarmentor Do you have a reference that the bartlett_sphericity can be used with spearman correlation? i.e that it has the same distribution of the test statistic. One confusing thing about it is that it is a test that the covariance matrix is diagonal, so the covariance does not need to be spherical. Stata has the same test statistic and pvalues for the diagonal covariance test. |
|
@josef-pkt Depending on the variable type, different methods to obtain the correlation matrix should be used. In the case of quantitative variables, Pearson correlations have satisfactory results. However, in the case of nominal and ordinal variables, some authors (for example, Marôco, 2011) advocate the use of Spearman correlation. Please note that in the function provided I give the option to choose between Spearman or Pearson correlations. Default option is currently Spearman, however the user can change this. |
|
Is Marôco, 2011 reference the SPSS book in Portuguese? I don't like adding things where I don't see a theoretical justification or at least has been confirmed by some Monte Carlo studies. The correlation test is for Pearson correlation with a normal distributed sample and might be robust to some distributional deviation from normality. My guess would be that using spearman does not have the correct scaling. To avoid the issue and to have more flexibility, for example with using outlier robust estimators, I'm thinking of just using the correlation matrix as argument, e.g. I went over the Stata manual and the chapter in Rencher Christensen that they refer to and I'm thinking of adding e.g. the call would then be with a dataframe
I would like some extra functions that take the data and call the underlying corr_test or cov_test, but I don't know yet what the design for that should be. I think that's not urgent given that computing various cov/corr is easy with pandas. |
|
Paritally related: for multivariate outlier detection and robust covariance or correlation estimation, I wrote a function that converts some of the other correlation types to be consistent at normality https://github.com/statsmodels/statsmodels/pull/3230/files#diff-0999b4a53db162f8a6150dbeecb638d7R35 The corr_test would have lower requirements because under the null the correlations are zero, so only the neighborhood of zero is relevant. |
|
just a piece of information: |
|
@josef-pkt Yes, that reference is in Portuguese. Another example might be "COMPARISON OF VALUES OF PEARSON’S AND SPEARMAN’S CORRELATION COEFFICIENTS ON THE SAME SETS OF DATA" by Jan Hauke, Tomasz Kossowski |
|
Hauke, Kossowski is just a comparison of single correlation coefficients. They don't specify which significance test they use, but by default there should be two different versions for the two types of correlations. In any case, if we use correlation matrix as argument to the function, then it is up to the user to decide what to use. (Right now my guess is that the test overrejects when spearman is used, but I have no guess how strong the distortion might be.) |
|
looks like my guess about overrejection is wrong, at least in the normal case spearman is similar to pearson correlation in maintaining size |
|
Another MC run, it looks pretty good even with nobs, k_vars = 50, 10 one more with large samples: |
|
@josef-pkt What do you think? Robust? |
|
Yes, based on the limited MC examples using spearman looks good. Maybe the difference in scaling is not large around zero correlation. I found another article that compares single correlation confidence intervals that compares pearson, spearman and a few others where spearman with the Bartlett version (1.06) does very well. (I only looked at abstract and some graphs) However, for 0.9 I would prefer to stick to the basic versions that use either corr or cov as argument, and postpone both more API decision and more quality checks to 0.10. What I'm still not sure about is what the functions should return. My trend is to think of returning some results instance by default. I don't like named tuples because they need to create the instance and class and don't allow adding additional returns in future (not future proof). |
|
postponed to 0.10 after all |
|
@josef-pkt Best |
|
I added sphericity and similar tests for covariance patterns in a simple way in #6693 KMO is still missing, and I haven't looked at the details again. I guess it will go in statsmodels.multivariate to support the statistical methods there, e.g. FA, and not in statsmodels.stats as standalone. I'm still working my way around stats in several rounds. |
No description provided.