Announcement

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

  • Latent profile analysis - getting graph with predicted means and CIs

    Dear Statalisters.

    I have 5 continuous variables and a binary variable

    This is the abridged dataset:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(binvar var1 var2 var3 var4 var5)
    0   50 67.85714 54.16667  83.33334  43.75
    1 62.5 39.28571     62.5  58.33333   37.5
    0   50 64.28571 54.16667        50  43.75
    1 62.5 71.42857       75  91.66666 53.125
    1 62.5 53.57143 66.66667  58.33333 34.375
    0 37.5 82.14285 54.16667  41.66667     25
    0 87.5 89.28572 95.83334        75     75
    0 87.5 78.57143 70.83333  83.33334  56.25
    1  100 89.28572     87.5  83.33334  81.25
    1 62.5 45.83333 58.33333        50   37.5
    0   50 67.85714     62.5  66.66667     50
    1   75 67.85714 70.83333        75  68.75
    1 87.5       75     87.5        75 46.875
    0 87.5 89.28572       75  83.33334  68.75
    0  100 96.42857 91.66666  83.33334  81.25
    0   50 64.28571       75  66.66667  43.75
    0   75 57.14286 66.66667  83.33334 59.375
    1 62.5 53.57143 54.16667  58.33333  43.75
    0 87.5       75     87.5        75     75
    0 62.5 64.28571     62.5  66.66667 59.375
    1 87.5 71.42857 79.99999  83.33334 53.125
    1 37.5 57.14286       75        75   37.5
    1 62.5 53.57143 58.33333  83.33334   37.5
    0 62.5 64.28571       75  58.33333   37.5
    0 87.5       75 79.16666  83.33334  56.25
    1   50       75 70.83333  58.33333  56.25
    1   75       50     62.5        75 40.625
    0 62.5 71.42857       70  58.33333 65.625
    1  100 78.57143 91.66666  91.66666 59.375
    0   75 92.85715 83.33334  58.33333 53.125
    0   75 67.85714 83.33334  83.33334     75
    1   75 60.71429 58.33333  83.33334 53.125
    0  100 71.42857       75  66.66667   62.5
    0 62.5       75 66.66667        75 46.875
    0  100 96.42857     87.5       100     50
    1 62.5 53.57143 79.16666        75  56.25
    1 62.5 53.57143 66.66667        75     50
    1   50       50       75        50      .
    1 87.5 53.57143     62.5  83.33334 65.625
    0 62.5       75 54.16667        75 59.375
    0   75 78.57143       75  83.33334 65.625
    1 37.5 64.28571 54.16667        75  18.75
    0   50 60.71429 66.66667  41.66667   37.5
    1 62.5 60.71429 70.83333  83.33334 40.625
    0 62.5 96.42857 79.16666       100 78.125
    0 62.5 67.85714       75  66.66667 46.875
    1 87.5 60.71429 54.16667        50     50
    0 62.5 85.71428 54.16667  58.33333 53.125
    1 87.5 78.57143 83.33334       100     50
    0 87.5 85.71428 70.83333  66.66667     50
    0  100 67.85714 79.16666        75 71.875
    1 62.5 46.42857 41.66667  41.66667 28.125
    1 87.5 67.85714 70.83333  91.66666  56.25
    1   75 57.14286     62.5        75  43.75
    0 87.5       75       75  58.33333  43.75
    0 62.5 60.71429     62.5  66.66667 40.625
    1   75 71.42857 58.33333        75     50
    1   50 60.71429 54.16667  41.66667  43.75
    1   75 60.71429       75        75  43.75
    1  100 64.28571 70.83333       100 71.875
    1 62.5 82.14285 54.16667        50 53.125
    0   75 78.57143       75  91.66666  43.75
    1 87.5 71.42857       50       100 71.875
    0 87.5       75       70  91.66666   62.5
    0 62.5 71.42857 70.83333  58.33333 46.875
    0    . 67.85714 58.33333  66.66667   62.5
    1   50 64.28571 66.66667        50 40.625
    1   75 71.42857     87.5        75     50
    0  100       75 70.83333  66.66667 78.125
    0   50 64.28571     62.5        75 53.125
    0  100      100 91.66666       100 78.125
    0   75 82.14285 83.33334  83.33334 65.625
    1   75 57.14286       75  41.66667     50
    1 62.5       75       75  91.66666  43.75
    0   75 64.28571 70.83333        75 53.125
    0   75 64.28571 70.83333        50     50
    0   75 78.57143     87.5 33.333332  68.75
    0 62.5 60.71429 58.33333  83.33334   37.5
    0 62.5 60.71429     87.5  83.33334  56.25
    0 62.5 67.85714 70.83333  83.33334   37.5
    1 62.5 53.57143 54.16667       100 71.875
    0 62.5 71.42857     87.5  91.66666 59.375
    0    . 91.66666     87.5  83.33334 71.875
    1   75       75       75        75     50
    0   75       50 58.33333  91.66666 59.375
    1 87.5 64.28571 70.83333        75   62.5
    0 87.5 89.28572       75       100  56.25
    0 62.5 64.28571 70.83333        75  56.25
    1   50 67.85714 66.66667  41.66667 40.625
    0   75 60.71429 45.83333        75 65.625
    0   75 82.14285 70.83333  58.33333 59.375
    1   75       75       75  91.66666 40.625
    1  100 82.14285       90      87.5  68.75
    0 87.5      100 91.66666       100     75
    1   75     62.5 58.33333      37.5 40.625
    0   75 64.28571       75       100 59.375
    1   50 57.14286 54.16667  83.33334 59.375
    1    . 60.71429     62.5        75  68.75
    0  100 71.42857       75        75   62.5
    0   75 71.42857 66.66667  66.66667     50
    end

    I decided to perform a latent profile analysis. Below, command and output :

    Code:
     gsem (var1 var2 var3 var4 var5 <- _cons), family(gaussian) link(identity) lclass(C 2)
    
    (output omitted, because the summary result is presented below)
    
     estat lcmean
    
    Latent class marginal means                     Number of obs     =         96
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
    1            |
            var1 |    63.1006   1.727262    36.53   0.000     59.71523    66.48597
            var2 |   63.35653   1.420895    44.59   0.000     60.57162    66.14143
            var3 |   64.09592   1.381402    46.40   0.000     61.38842    66.80342
            var4 |   67.63647    2.22846    30.35   0.000     63.26877    72.00417
            var5 |   47.28173   1.523574    31.03   0.000     44.29558    50.26788
    -------------+----------------------------------------------------------------
    2            |
            var1 |   85.80579   2.117787    40.52   0.000       81.655    89.95657
            var2 |    78.5297   1.816236    43.24   0.000     74.96994    82.08946
            var3 |   79.42668   1.602816    49.55   0.000     76.28521    82.56814
            var4 |   82.44715   2.532471    32.56   0.000      77.4836    87.41071
            var5 |   62.92604   1.905211    33.03   0.000     59.19189    66.66018

    Now, the obstacle I'm facing.

    In spite of the presentation of the margins as well as the CIs, I have not found a way to get the marginsplot of var1 to var5, according to the two classes. Ideally, I would like to have a graph for the means + CI of each var, with the 2 classes side by side.

    Indeed, I see these values are available in the r(table) matrix:

    Code:
    return list
    matrix list r(table)
    In spite of being a - gsem - , I believe we can use - margins - as well as - marginsplot -, for a couple of reasons:

    There is an example here, provided by StataCorp, albeit the case is slightly different from mine.

    Additionally, if I type:

    Code:
    margins, dydx(*)
    marginsplot
    I get the predictive values for mu overvall.

    However, I wish to have the predictive margins according to each class (1 and 2) as presented after typing - estat lcmean - command.

    To end, I wonder whether it is possible to get it, maybe:

    a) Under -margins + marginsplot
    b) Using Mata, after transforming the r(table) in a dataset
    c) Some sort of - predict - under "twoway" command, using the mean + rcap.

    So far, I tried options a and c, to no avail.

    Thank you in advance for the suggestions.
    Best regards,

    Marcos

  • #2
    I'm still trying to curb the issue.

    Among the solutions, quite "paleolithic", so to speak, I copied and pasted the latent marginal means (plus CIs) in a new dataset, and managed to get a graph by using - graph twoway - with - rcap - commands.

    Sitll, I wonder whether there is a more elegant solution, for the strategy seems to be "anywhere nearby" (since Stata gives the marginal means and CIs).

    So near, yet so far, I mean, in terms of getting the marginsplot for the latent marginal means, according to each class?
    Best regards,

    Marcos

    Comment


    • #3
      Helly Marcos Almeida,

      I'm facing the same issue. Did you find a (more elegant) solution yet?

      Best regards,
      Anton

      Comment


      • #4
        Hello Anton,

        Actually, I did manage to get the wishful graph, albeit under a dowdy way, you know, as described in #2.
        Best regards,

        Marcos

        Comment


        • #5
          This is an update of my own query (also a reply to Anton Schwarz), more than two months later.

          Indeed, I couldn't keep this (yet unsurpassed) obstacle out of mind, hence I had to face it anyway.

          Basically, we need to fiddle with the - post - option beforehand, then save the columns of the matrix e(b) as variables names in the dataset.

          Code:
          estat lcmean, post
          ereturn list
          matrix D = e(b)
          svmat D, names(var)
          matrix list D
          After performing ordinary data management operations (rename, generate, reshape, label, etc.), we will find the desired display for a graph bar (mean) command.

          That being said, and feeling somewhat relieved, this is just a strategy (a little bit more elegant than typing results directly in a blank spreadsheet, I expect) to provide a similar graph such as the one presented in the link I shared in #1, then with the LCA frame, now with the LPA frame.

          But I still prefer the more informative presentation under graph two way (scatter for the mean + rcap for the CIs).

          Hopefully that helps!
          Last edited by Marcos Almeida; 11 Oct 2017, 06:09.
          Best regards,

          Marcos

          Comment


          • #6
            I think the graph you are looking for can be obtained with the following code

            Code:
            estat lcmean, post
            margins, dydx(*) noesample predict(outcome(1)) predict(outcome(2))
            marginsplot, bydimension(_outcome, allsimplelabels)
            Or as a bar graph

            Code:
            marginsplot, bydimension(_outcome, allsimplelabels) recast(bar)
            Best,

            Ahmed

            Comment


            • #7
              Thank you for the suggestion. The graphs weren't exactly what I wished. That said, just typing - marginsplot - after the command you shared -
              margins, dydx(*) noesample predict(outcome(1)) predict(outcome(2)) - gave practically what I desired, apart from the fact that it presents a connected display, instead of just means + CIs ,as we would get with rcap command. Anyway, that was really an elegant rendition. Thanks again.
              Best regards,

              Marcos

              Comment

              Working...
              X