Announcement

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

  • 95% confidence intervals from pwcorr

    Hello

    I am running the following command in Stata:

    Code:
    pwcorr drug*, star(0.001) sig
    Since I have 4 drugs this gives me a 4x4 table with correlations and p-values. Can someone help me with a basic question here: what test is Stata using to calculate this p-value?

    And how to obtain 95% confidence intervals for each correlation?

    Many thanks!

  • #2
    what test is Stata using to calculate this p-value?
    Should be just a simple t-test where the null hypothesis is the correlation coefficient is equal to 0 against the alternative that it is significantly different from 0. The test statistic is

    $$\text{t}= \frac{\hat{\rho} \sqrt{n-2}}{\sqrt{1-\hat{\rho}^2}}$$

    where \(\hat{\rho}\) is the estimated correlation coefficient and \(n\) is the sample size.

    Code:
    clear
    set obs 10
    gen x1=_n
    gen x2=x1
    replace x2=1 in 9
    pwcorr x1 x2, sig
    
    *STATISTIC
    di 0.6543*(sqrt(8))/(sqrt(1-(0.6543^2)))
    *P-VALUE
    di 2*ttail(8, abs(2.4471753))
    Res.:

    Code:
    . clear
    
    .
    . set obs 10
    number of observations (_N) was 0, now 10
    
    .
    . gen x1=_n
    
    .
    . gen x2=x1
    
    .
    . replace x2=1 in 9
    (1 real change made)
    
    .
    . pwcorr x1 x2, sig
    
                 |       x1       x2
    -------------+------------------
              x1 |   1.0000
                 |
                 |
              x2 |   0.6543   1.0000
                 |   0.0401
                 |
    
    . .
    .
    . di 0.6543*(sqrt(8))/(sqrt(1-(0.6543^2)))
    2.4471753
    
    .
    . di 2*ttail(8, abs(2.4471753))
    .04011306
    Last edited by Andrew Musau; 09 Oct 2019, 16:26.

    Comment


    • #3
      Thank you very much Andrew for the explanation. Perfectly clear now.

      Do you know how to calculate 95% CI for those correlations?


      Many thanks!

      Comment


      • #4
        There are ancient routines ci2 and cii2 that claim to do it. findit ci2

        Example:

        Code:
        . webuse nhanes2f, clear
        
        . pwcorr weight height
        
                     |   weight   height
        -------------+------------------
              weight |   1.0000 
              height |   0.4777   1.0000 
        
        . ci2 weight height, corr
        
        Confidence interval for Pearson's product-moment correlation 
        of weight and height, based on Fisher's transformation.
        Correlation = 0.478 on 10337 observations (95% CI: 0.463 to 0.492)
        It seem odd to me that built-in ci doesn't do it. You can read about the commands starting on p. 27 of

        https://www.stata.com/products/stb/journals/stb59.pdf
        -------------------------------------------
        Richard Williams, Notre Dame Dept of Sociology
        StataNow Version: 19.5 MP (2 processor)

        EMAIL: [email protected]
        WWW: https://www3.nd.edu/~rwilliam

        Comment


        • #5
          If you want to stick with official Stata commands, you could look into bootstrapping the confidence bounds. Something like
          Code:
          set seed `=strreverse("1519756")'
          
          sysuse auto
          bootstrap rho = r(rho), reps(400): corr displacement gear_ratio
          estat bootstrap, all
          You have to do the pairs individually, though.

          Comment


          • #6
            Many thanks Richard and Joseph for your comments. It was very helpful!

            Comment


            • #7
              Some tips on how to find information on such things in Stata:

              1) "What formula is Stata using?" StataCorp is quite good about documenting such things. Try -help pwcorr-, and then click on the highlighted "View complete PDF manual entry." Near the top of the resulting PDF page you will see a link for "Methods and Formulas," which you can click on to jump to the formulas in the text.

              2) When you have a "How do I do ... question, " trying searching in the command window using some of your key words. This won't always work, but in this case it leads to several possible add-on program of use: -search confidence interval correlation-

              Comment


              • #8
                Makes sense - many thanks Mike for taking the time to share these tips.

                Comment


                • #9
                  Originally posted by Richard Williams View Post
                  There are ancient routines ci2 and cii2 that claim to do it. findit ci2

                  Example:

                  Code:
                  . webuse nhanes2f, clear
                  
                  . pwcorr weight height
                  
                  | weight height
                  -------------+------------------
                  weight | 1.0000
                  height | 0.4777 1.0000
                  
                  . ci2 weight height, corr
                  
                  Confidence interval for Pearson's product-moment correlation
                  of weight and height, based on Fisher's transformation.
                  Correlation = 0.478 on 10337 observations (95% CI: 0.463 to 0.492)
                  It seem odd to me that built-in ci doesn't do it. You can read about the commands starting on p. 27 of

                  https://www.stata.com/products/stb/journals/stb59.pdf
                  Just in case anyone is interested, there seems to be a typo on p.28 (near bottom) of the document cited above:
                  the macro of the correlation value stored after running ci2 should be r(rho), not r(r).

                  Comment

                  Working...
                  X