Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 95% CIs from POLYCORR (ssc) do not match 95% CIs from CORRCI (ssc)

    The POLYCORR package caught my eye this afternoon as I browsed recent contributions to SSC.
    Code:
    ssc whatsnew
    ssc describe polycorr
    It looks potentially useful, but I thought it might be wise to compare its CIs for Pearson correlations to the CIs from Nick Cox's CORRCI package (ssc). And to this point, I have not been able to coax POLYCORR into giving the same results as CORRCI. This strikes me as problematic, so I thought I should alert others. Here is what I have tried so far.

    Code:
    . // ssc install corrci 
    . // ssc install polycorr 
    . clear
    
    . sysuse auto 
    (1978 automobile data)
    
    . summarize trunk weight length
    
        Variable |        Obs        Mean    Std. dev.       Min        Max
    -------------+---------------------------------------------------------
           trunk |         74    13.75676    4.277404          5         23
          weight |         74    3019.459    777.1936       1760       4840
          length |         74    187.9324    22.26634        142        233
    
    . 
    . corrci trunk weight length, format(%9.4f)
    
    (obs=74)
    
                   correlations and 95% limits
    trunk  weight     0.6722   0.5242   0.7808
    trunk  length     0.7266   0.5973   0.8191
    weight length     0.9460   0.9154   0.9657
    
    . corrci trunk weight length, format(%9.4f) fisher
    
    (obs=74)
    
                   correlations and 95% limits
    trunk  weight     0.6722   0.5209   0.7790
    trunk  length     0.7266   0.5940   0.8175
    weight length     0.9460   0.9143   0.9653
    
    . 
    . polycorr trunk weight length
    
    Polychoric, polyserial and Pearson correlations   Number of obs   =         74
    Deletion: listwise                                Variables       =          3
    VCE: robust                                       Pairs           =          3
    ------------------------------------------------------------------------------
    Variable 1   Variable 2   Type      rho    Std. err.    z    [95% CI]
    ------------------------------------------------------------------------------
    trunk        weight       Pearson    0.6722  0.0614   10.95   0.5518   0.7926
    trunk        length       Pearson    0.7266  0.0593   12.26   0.6104   0.8428
    weight       length       Pearson    0.9460  0.0147   64.49   0.9173   0.9748
    ------------------------------------------------------------------------------
    Bivariate normality: no testable polychoric pairs (2x2 tables have df = 0)
    Smallest eigenvalue of R =  0.050578  (positive definite)
    
    . polycorr trunk weight length, cifz 
    
    Polychoric, polyserial and Pearson correlations   Number of obs   =         74
    Deletion: listwise                                Variables       =          3
    VCE: robust                                       Pairs           =          3
    ------------------------------------------------------------------------------
    Variable 1   Variable 2   Type      rho    Std. err.    z    [95% CI, Fisher z]
    ------------------------------------------------------------------------------
    trunk        weight       Pearson    0.6722  0.0614   10.95   0.5336   0.7756
    trunk        length       Pearson    0.7266  0.0593   12.26   0.5885   0.8235
    weight       length       Pearson    0.9460  0.0147   64.49   0.9085   0.9684
    ------------------------------------------------------------------------------
    Bivariate normality: no testable polychoric pairs (2x2 tables have df = 0)
    Smallest eigenvalue of R =  0.050578  (positive definite)
    I tried to tag the author of POLYCORR (Yusuf Toyin Yusuf), but he is not among the Yusufs listed, which suggests he is not a Statalist member.


    APPENDIX
    Here is my code without the output, in case anyone wants it.
    Code:
    // ssc install corrci 
    // ssc install polycorr 
    clear
    sysuse auto 
    summarize trunk weight length
    
    corrci trunk weight length, format(%9.4f)
    corrci trunk weight length, format(%9.4f) fisher
    
    polycorr trunk weight length
    polycorr trunk weight length, cifz

    --
    Bruce Weaver
    Email: [email protected]
    Version: Stata/MP 19.5 (Windows)
    Crypticity belongs in crosswords, not code! 🤨

  • #2
    And this is why unit testing one's code is a great idea, folks.

    I haven't read the code of -polycorr-, but my immediate hunch is the use of floats (or locals) over doubles (or scalars), or some implicit intermediate rounding. Since it seems like the point estimates and reported standard errors match, up to the stated precision.

    Comment


    • #3
      I took a quick look a the source of -polycorr- and I note the following important differences, as compared to -corrci- and as it pertains to your question, Bruce. The package implements a robust variance estimator, and can use the Fisher's Z/atanh() transformation, but the optimization is done using a grid search optimizer. Also all the computation is done in Mata (great for precision and speed). So there's no immediate reason I can see that these two packages should produce the same confidence intervals. Indeed, I misremembed -corrci- producing SEs, as I initially assumed in 2, but it does not.

      Comment


      • #4

        Following Leonardo’s explanation in #3, I reproduced Bruce’s example directly from the Pearson formulas. polycorr, cifz retains the robust variance, whereas corrci uses the classical Fisher-z standard error; corrci’s fisher option adds a bias correction.

        I have put the self-contained Stata/Mata calculations in Sandbox #10 (https://www.statalist.org/forums/for...6#post1787886), and a coverage experiment in #11 (https://www.statalist.org/forums/for...88#post1787888). With n=74, true rho=.7 and 20,000 paired replications per condition, classical/robust Fisher-z coverage without the bias correction was 95.0%/93.5% under normality and 84.8%/91.6% under a common-scale bivariate t(5) model. These are model-specific illustrations, not a universal ranking of the methods.

        Comment


        • #5
          Thanks, Bruce, for testing -polycorr- so carefully, and thanks to Leonardo and Choonjoo for working out the explanation.

          The differences are by design, not a bug. -polycorr- and -corrci- give the same point estimates but different standard errors and intervals:
          1. -polycorr- reports a robust (influence-function, or sandwich) standard error for every correlation: Pearson, polychoric and polyserial alike. It does not assume bivariate normality. It also extends to vce(cluster) and svy, and it is what makes e(V) the joint covariance matrix that -test- and -nlcom- use. -corrci- uses the classical Fisher standard error, 1/sqrt(n-3) on the z scale, which assumes bivariate normality.
          2. By default -polycorr- reports a Wald interval, r ± zSE. The -cifz- option puts the same robust SE on the Fisher z scale: tanh(atanh(r) ± zSE/(1-r^2)). -corrci-‘s -fisher- option also applies Fisher’s bias correction, which -polycorr- does not.
          Bruce’s numbers can be reproduced exactly. For trunk and weight (r = .6722, n = 74, robust SE = .0614):
          classical Fisher z: tanh(atanh(.6722) ± 1.96/sqrt(71)) = [.5242, .7808] (corrci) robust Fisher z: tanh(atanh(.6722) ± 1.96*.0614/(1-.6722^2)) = [.5336, .7756] (polycorr, cifz) robust Wald: .6722 ± 1.96*.0614 = [.5518, .7926] (polycorr)
          Choonjoo’s coverage experiment shows the trade-off well. Under bivariate normality the classical interval is very slightly better. Under heavier tails the robust interval holds its coverage much better (91.6% against 84.8%).

          For Pearson correlations of continuous variables, I recommend the -cifz- option, which keeps the interval inside [-1, 1]. Users who want results identical to -corrci- should use -corrci-. I will make the help file clearer about the standard error -polycorr- reports and how it differs from the classical one.

          Yusuf Toyin Yusuf

          Comment


          • #6
            As a detail of a different kind, please note that the files for corrci are to be found on the Stata Journal website, not on SSC.

            The original paper in 2008 was positive about bootstrapping too, IIRC.

            Comment


            • #7
              Thanks for the clarification about -polycorr- (SSC), Yusuf Yusuf. And my apologies for mistakenly stating that -corrci- is available via scc. As Nick Cox said in #6, it is available via the Stata Journal website. I should have checked that before posting.
              Code:
              search corrci, sj
              --
              Bruce Weaver
              Email: [email protected]
              Version: Stata/MP 19.5 (Windows)
              Crypticity belongs in crosswords, not code! 🤨

              Comment

              Working...
              X