Announcement

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

  • Figure with hypothesized correlations on left and actual correlations on right

    I created a new psychological scale to measure a construct and I hypothesized the correlations it would have with related constructs. I'd now like to generate something like the figure below which from Costello et al. (2020), Clarifying the structure and nature of left-wing authoritarianism.

    The hypothesized correlations are on the left and the actual ones are on the right. I want just one box on the right, not two as shown here. I know that coefplot can create graphs from regressions like this, but I don't think it works with correlations. And I don't think you can create a layout with a hypothesized set of correlations on the left. (I believe R was used to generate this one.) Is this doable in Stata?



    Click image for larger version

Name:	@hypoth.jpg
Views:	1
Size:	87.1 KB
ID:	1776416

  • #2
    Originally posted by Chris Martin View Post
    I created a new psychological scale to measure a construct and I hypothesized the correlations it would have with related constructs.
    Provide us a sample of such correlations.

    Comment


    • #3
      Here is some data for the correlations

      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input float(sjtsima ang del emp frk honeshex npow ih jsb jso clos sdo tru)
      25  1.4  3.777778 3.9 4.875 4.3125  3.666667  4.681818   2   3       2.4     3  2.909091
      18 2.75         3 3.9 3.125 3.4375         3 3.5454545 4.5 4.5       4.6  2.25 2.3636363
      25    2  3.777778 4.1 2.875 3.1875  3.142857  3.636364   3 3.5       4.8   1.5  2.818182
      25  2.1  4.111111   4 3.375  3.875 2.2857144  3.909091 3.5 2.5 3.8666666 2.125  2.636364
      24  1.1         4   4  3.25 4.3125  3.857143 4.2272725 4.5   5         2     1         4
      24  1.8         4 4.1 3.875 4.0625 2.5714285 4.1363635   2   3 3.8666666 2.875  3.727273
      21  2.2  4.111111 3.3   3.5 4.1875 1.8571428 3.5454545   4   4  5.133333     1         4
      25  1.1 4.3333335 4.9 2.375    4.5 2.4285715 4.4545455 4.5 3.5 2.3333333 1.375 4.4545455
      25  2.2         4 3.9 2.125 3.6875  3.142857 3.4545455   4   4  4.933333 4.125  3.818182
      19  2.1 4.4444447 4.6  3.25 3.9375         3 4.0454545   3   3  4.733333 2.125  3.272727
      20    2         4   4  3.75    3.5         3 3.5454545   2   3         5   3.5  2.909091
      19  2.4 3.5555556 3.5  2.25 3.8125 1.7142857  3.636364   3   3  4.866667  3.25         3
      18  2.6  3.888889 3.7 2.625 3.1875 3.2857144  3.318182   3   3       4.6     4 2.5454545
      21  2.2 3.5555556 3.9     4 3.9375 3.2857144 4.1363635   1   1  3.533333 3.375 4.4545455
      20  2.2  4.111111 3.5 4.125  2.625 2.7142856  3.181818   5 4.5  5.533333  1.75  3.090909
      end
      The key variable is sjtsima.

      To get the actual correlations, see the first column:
      Code:
      pwcorr sjtsima ang del emp frk hon npow ih jsb jso clos sdo tru
      Here are the hypothesized correlations in the same order as listed above from ang through tru:

      Anger Proneness (Neuro. facet) -0.10
      Deliberation (Consc. facet) 0
      Empathy (Agree. facet) 0.35
      Frankness (Extra. facet) 0.10
      Honesty-humility 0.20
      nPow: Implicit need for power -0.25
      Intellectual Humility 0.20
      Justice sensitivity (Beneficiary) 0.35
      Justice Sensitivity (Observer) 0.30
      Closure: i.e. Need for closure -0.15
      Social Dominance Orientation -0.30
      Trust (Agree.facet) 0.25

      Thanks!



      Comment


      • #4
        Thanks. I use coefplot from SSC. You can further customize the graph using standard twoway options.

        Code:
        clear
        input float(sjtsima ang del emp frk honeshex npow ih jsb jso clos sdo tru)
        25  1.4  3.777778 3.9 4.875 4.3125  3.666667  4.681818   2   3       2.4     3  2.909091
        18 2.75         3 3.9 3.125 3.4375         3 3.5454545 4.5 4.5       4.6  2.25 2.3636363
        25    2  3.777778 4.1 2.875 3.1875  3.142857  3.636364   3 3.5       4.8   1.5  2.818182
        25  2.1  4.111111   4 3.375  3.875 2.2857144  3.909091 3.5 2.5 3.8666666 2.125  2.636364
        24  1.1         4   4  3.25 4.3125  3.857143 4.2272725 4.5   5         2     1         4
        24  1.8         4 4.1 3.875 4.0625 2.5714285 4.1363635   2   3 3.8666666 2.875  3.727273
        21  2.2  4.111111 3.3   3.5 4.1875 1.8571428 3.5454545   4   4  5.133333     1         4
        25  1.1 4.3333335 4.9 2.375    4.5 2.4285715 4.4545455 4.5 3.5 2.3333333 1.375 4.4545455
        25  2.2         4 3.9 2.125 3.6875  3.142857 3.4545455   4   4  4.933333 4.125  3.818182
        19  2.1 4.4444447 4.6  3.25 3.9375         3 4.0454545   3   3  4.733333 2.125  3.272727
        20    2         4   4  3.75    3.5         3 3.5454545   2   3         5   3.5  2.909091
        19  2.4 3.5555556 3.5  2.25 3.8125 1.7142857  3.636364   3   3  4.866667  3.25         3
        18  2.6  3.888889 3.7 2.625 3.1875 3.2857144  3.318182   3   3       4.6     4 2.5454545
        21  2.2 3.5555556 3.9     4 3.9375 3.2857144 4.1363635   1   1  3.533333 3.375 4.4545455
        20  2.2  4.111111 3.5 4.125  2.625 2.7142856  3.181818   5 4.5  5.533333  1.75  3.090909
        end
        
        cap frame drop corr
        frame create corr
        frame corr{
            clear
            input str400 label str10 var float corr2
            "Anger Proneness (Neuro. facet)" "ang" -0.10
            "Deliberation (Consc. facet)" "del" 0
            "Empathy (Agree. facet)" "emp" 0.35
            "Frankness (Extra. facet)" "frk" 0.10
            "Honesty-humility" "honeshex" 0.20
            "nPow: Implicit need for power" "npow" -0.25
            "Intellectual Humility" "ih" 0.20
            "Justice sensitivity (Benefic.)" "jsb" 0.35
            "Justice Sensitivity (Observer)" "jso" 0.30
            "Closure: i.e. Need for closure" "clos" -0.15
            "Social Dominance Orientation" "sdo" -0.30
            "Trust (Agree. facet)" "tru" 0.25
            end
            gen corr=.
            replace label= ustrregexra(subinstr(trim(itrim(label)), ".", "", .), "[\s]", "`=uchar(160)'")
        }
        
        foreach var of varlist ang-tru{
            corr sjtsima `var'
            frame corr: replace corr= r(rho) if var=="`var'"
        }
        
        
        frame corr: mkmat corr, mat(Actual) rownames(var) roweq(label)
        frame corr: mkmat corr2, mat(Predicted) rownames(var) roweq(label)
        
        coefplot matrix(Actual[,1])|| matrix(Predicted[,1])||, keep(*:) ylab("")

        Click image for larger version

Name:	Graph.png
Views:	1
Size:	59.6 KB
ID:	1776429

        Comment


        • #5
          I would tend to prefer correlations being superimposed. It's a little awkward to have predicted correlations in the same dataset as the data, but it's perfectly possible. Following Andrew Musau's lead consider something like this:

          Code:
          clear
          input float(sjtsima ang del emp frk honeshex npow ih jsb jso clos sdo tru)
          25  1.4  3.777778 3.9 4.875 4.3125  3.666667  4.681818   2   3       2.4     3  2.909091
          18 2.75         3 3.9 3.125 3.4375         3 3.5454545 4.5 4.5       4.6  2.25 2.3636363
          25    2  3.777778 4.1 2.875 3.1875  3.142857  3.636364   3 3.5       4.8   1.5  2.818182
          25  2.1  4.111111   4 3.375  3.875 2.2857144  3.909091 3.5 2.5 3.8666666 2.125  2.636364
          24  1.1         4   4  3.25 4.3125  3.857143 4.2272725 4.5   5         2     1         4
          24  1.8         4 4.1 3.875 4.0625 2.5714285 4.1363635   2   3 3.8666666 2.875  3.727273
          21  2.2  4.111111 3.3   3.5 4.1875 1.8571428 3.5454545   4   4  5.133333     1         4
          25  1.1 4.3333335 4.9 2.375    4.5 2.4285715 4.4545455 4.5 3.5 2.3333333 1.375 4.4545455
          25  2.2         4 3.9 2.125 3.6875  3.142857 3.4545455   4   4  4.933333 4.125  3.818182
          19  2.1 4.4444447 4.6  3.25 3.9375         3 4.0454545   3   3  4.733333 2.125  3.272727
          20    2         4   4  3.75    3.5         3 3.5454545   2   3         5   3.5  2.909091
          19  2.4 3.5555556 3.5  2.25 3.8125 1.7142857  3.636364   3   3  4.866667  3.25         3
          18  2.6  3.888889 3.7 2.625 3.1875 3.2857144  3.318182   3   3       4.6     4 2.5454545
          21  2.2 3.5555556 3.9     4 3.9375 3.2857144 4.1363635   1   1  3.533333 3.375 4.4545455
          20  2.2  4.111111 3.5 4.125  2.625 2.7142856  3.181818   5 4.5  5.533333  1.75  3.090909
          end
          
          input str400 label str10 var float corr2
              "Anger Proneness (Neuro. facet)" "ang" -0.10
              "Deliberation (Consc. facet)" "del" 0
              "Empathy (Agree. facet)" "emp" 0.35
              "Frankness (Extra. facet)" "frk" 0.10
              "Honesty-humility" "honeshex" 0.20
              "nPow: Implicit need for power" "npow" -0.25
              "Intellectual Humility" "ih" 0.20
              "Justice sensitivity (Benefic.)" "jsb" 0.35
              "Justice Sensitivity (Observer)" "jso" 0.30
              "Closure: i.e. Need for closure" "clos" -0.15
              "Social Dominance Orientation" "sdo" -0.30
              "Trust (Agree. facet)" "tru" 0.25
          end
              
          gen corr=.
          
          foreach var of varlist ang-tru{
              corr sjtsima `var'
              replace corr= r(rho) if var=="`var'"
          }
          
          graph dot (asis) corr corr2 , over(label, sort(corr)) marker(1, ms(Oh) msize(*2)) marker(2, ms(+) msize(*2)) legend(order(1 "observed" 2 "predicted") row(1) pos(6)) yscale(alt) t1title(Observed and predicted correlations) linetype(line) lines(lc(gs12) lw(vthin))
          Click image for larger version

Name:	correlation.png
Views:	1
Size:	64.3 KB
ID:	1776441

          Comment


          • #6
            Thank you. I like the use of a single graph. Is there a way to add the 95% confidence intervals?

            Comment


            • #7
              For the Pearson correlation coefficients, you could, for example, use bootstrapping to obtain the confidence intervals. For your own results, you'll need to provide these yourself.

              Code:
              clear
              input float(sjtsima ang del emp frk honeshex npow ih jsb jso clos sdo tru)
              25  1.4  3.777778 3.9 4.875 4.3125  3.666667  4.681818   2   3       2.4     3  2.909091
              18 2.75         3 3.9 3.125 3.4375         3 3.5454545 4.5 4.5       4.6  2.25 2.3636363
              25    2  3.777778 4.1 2.875 3.1875  3.142857  3.636364   3 3.5       4.8   1.5  2.818182
              25  2.1  4.111111   4 3.375  3.875 2.2857144  3.909091 3.5 2.5 3.8666666 2.125  2.636364
              24  1.1         4   4  3.25 4.3125  3.857143 4.2272725 4.5   5         2     1         4
              24  1.8         4 4.1 3.875 4.0625 2.5714285 4.1363635   2   3 3.8666666 2.875  3.727273
              21  2.2  4.111111 3.3   3.5 4.1875 1.8571428 3.5454545   4   4  5.133333     1         4
              25  1.1 4.3333335 4.9 2.375    4.5 2.4285715 4.4545455 4.5 3.5 2.3333333 1.375 4.4545455
              25  2.2         4 3.9 2.125 3.6875  3.142857 3.4545455   4   4  4.933333 4.125  3.818182
              19  2.1 4.4444447 4.6  3.25 3.9375         3 4.0454545   3   3  4.733333 2.125  3.272727
              20    2         4   4  3.75    3.5         3 3.5454545   2   3         5   3.5  2.909091
              19  2.4 3.5555556 3.5  2.25 3.8125 1.7142857  3.636364   3   3  4.866667  3.25         3
              18  2.6  3.888889 3.7 2.625 3.1875 3.2857144  3.318182   3   3       4.6     4 2.5454545
              21  2.2 3.5555556 3.9     4 3.9375 3.2857144 4.1363635   1   1  3.533333 3.375 4.4545455
              20  2.2  4.111111 3.5 4.125  2.625 2.7142856  3.181818   5 4.5  5.533333  1.75  3.090909
              end
              
              cap frame drop corr
              frame create corr
              frame corr{
                  clear
                  input str400 label str10 var float corr2
                  "Anger Proneness (Neuro. facet)" "ang" -0.10
                  "Deliberation (Consc. facet)" "del" 0
                  "Empathy (Agree. facet)" "emp" 0.35
                  "Frankness (Extra. facet)" "frk" 0.10
                  "Honesty-humility" "honeshex" 0.20
                  "nPow: Implicit need for power" "npow" -0.25
                  "Intellectual Humility" "ih" 0.20
                  "Justice sensitivity (Benefic.)" "jsb" 0.35
                  "Justice Sensitivity (Observer)" "jso" 0.30
                  "Closure: i.e. Need for closure" "clos" -0.15
                  "Social Dominance Orientation" "sdo" -0.30
                  "Trust (Agree. facet)" "tru" 0.25
                  end
                  gen corr=.
                  gen ll=.
                  gen ul=.
                  replace label= ustrregexra(trim(itrim(label)), "[\s]", "`=uchar(160)'")
                  replace label= ustrregexra(label, "[\.]", "`=ustrunescape("\u2024")'")
                  replace label= ustrregexra(label, "[\:]", "`=ustrunescape("\uff1a")'")
              }
              set seed 04242025
              foreach var of varlist ang-tru{
                 bootstrap rho = r(rho), reps(400): corr sjtsima `var'
                  frame corr: replace corr= r(table)["b", 1] if var=="`var'"
                  frame corr: replace ll= r(table)["ll", 1] if var=="`var'"
                  frame corr: replace ul= r(table)["ul", 1] if var=="`var'"
              }
              
              frame corr: sort corr
              frame corr: mkmat corr ll ul, mat(Actual) rownames(var) roweq(label)
              frame corr: mkmat corr2, mat(Hypothesized) rownames(var) roweq(label)
              
              coefplot matrix(Hypothesized[,1])|| matrix(Actual[,1]), ci((Actual[,2] Actual[,3]))||, keep(*:) ///
              nokey norecycle ylab("") b1title(Correlations) xline(0, lp(dash) lc(red))
              Click image for larger version

Name:	Graph.png
Views:	1
Size:	71.2 KB
ID:	1776473

              Comment


              • #8
                Thanks. This runs on my end, but the variables labels are vertically oriented instead of horizontally oriented. However this could be due to Stata 17. I am most of my work on a computer with Stata 19

                Comment


                • #9
                  I can replicate that in V16. You can add:

                  Code:
                  coefplot matrix(Hypothesized[,1])|| matrix(Actual[,1]), ci((Actual[,2] Actual[,3]))||, keep(*:) ///
                  nokey norecycle ylab("") eqlab(, angle(horiz)) b1title(Correlations) xline(0, lp(dash) lc(red))
                  Click image for larger version

Name:	Graph.png
Views:	1
Size:	71.7 KB
ID:	1776481

                  Comment


                  • #10
                    Thanks. I'm trying to sort the items on the y axis in alphabetical order by variable, which is: ang del emp frk honeshex npow ih jsb jso clos sdo tru.

                    However, the documentation for coefplot suggests that the sort option doesn't support this. Do you know of another way?

                    Comment


                    • #11
                      The sort command in #7 is:

                      frame corr: sort corr
                      Reading the graph is easier when the correlations are sorted, but the best way to get what you want is to order the variables before building the matrix.


                      Code:
                      order sjtsima ang del emp frk honeshex npow ih jsb jso clos sdo tru
                      
                      foreach var of varlist ang-tru{
                          bootstrap rho = r(rho), reps(400): corr sjtsima `var'
                          frame corr: replace corr= r(table)["b", 1] if var=="`var'"
                          frame corr: replace ll= r(table)["ll", 1] if var=="`var'"
                          frame corr: replace ul= r(table)["ul", 1] if var=="`var'"
                      } 
                      frame corr: mkmat corr ll ul, mat(Actual) rownames(var) roweq(label)
                      frame corr: mkmat corr2, mat(Hypothesized) rownames(var) roweq(label)
                      
                      coefplot matrix(Hypothesized[,1])|| matrix(Actual[,1]), ci((Actual[,2] Actual[,3]))||, keep(*:) ///
                      nokey norecycle ylab("") eqlab(,angle(horiz)) b1title(Correlations) xline(0, lp(dash) lc(red))

                      Comment

                      Working...
                      X