Announcement

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

  • #31
    Thanks Weiwen,

    Ok, so it's not quite back to the drawingboard, but a little rethinking is required. In summary, advised next steps are as follows:
    1. I'll stick with BIC rather than SS-BIC as my sample size is large enough.
    2. I accept that my proposed class structure is complex and will therefore disregard the LMR-LR test as a suitable assessment of goodness of fit.
    3. I will examine logit intercepts for models that only converge with the -nonrtolerance- option and constrain them at + or - 15 if they are near +/- 15 and will attempt to re-fit the models if this is the case. Otherwise, I will conclude that these models couldn't converge, and are therefore not good explanations of the data.
    4. I will look into the -lcinvariant- and -covstructure- options to explore different class structures for the continuous indicators.
    I want to account for clustering at the ward-level too.. and I hope adding this complication doesn't throw another spanner in the works! I believe it's just a case of adding the following code at the end of my -gsem-
    Code:
    vce(cluster [wardvariable])
    I am also running a parallel analysis on another dataset which has a complex survey design. I am tempted to make the executive decision now that I will ignore sample weighting in model estimation as svysetting won't allow for goodness of fit statistics to be calculated with estat gof. Or perhaps goodness of fit statistics should be assessed on the non-weighted models first, and then the weighted models should be use to estimate predicted class probabilities and in later regressions.

    Thank you so much for your help, Weiwen. I hope I don't go too far down the rabbit hole!


    Comment


    • #32

      Hi all I am trying to calculate model entropy and have used the syntax kindly provided by Mengmeng Li after running the following LCA 3-class model including four binary indicators and two ordinal indicators.However, E is not displayed. Please any advice welcome. BW Paul gsem(c d e lowersoc<-, logit) (polq imdq<-, ologit), lclass(3)startvalues(randomid,draws(30)seed(123321 )iter(1000) estat lcgof quietly predict classpost*, classposteriorpr forvalues k = 1/2 { gen p_lnp_k`k' = classpost`k'*ln(classpost`k') } egen sum_p_lnp = rowtotal(p_lnp_k?) total sum_p_lnp drop classpost? p_lnp_k? sum_p_lnp matrix a = e(b) scalar E = 1 + a[1,1]/(e(N)*ln(2)) di E

      Comment


      • #33
        Hi,

        Using the information from previous post #23, I tried to create an ado program file to have Stata calculate the entropy measure whenever I type entropy after running a LCA. However, somehow the output is different when I run the program, compared to when I just run the code in a syntax file. Anyone have any idea what is wrong with my code?

        Also, am I correct that the "2" in the line
        Code:
        scalar Entropy = 1+`sum'/(r(N)*ln(2))
        needs to be replaced by the number of classes?

        Code:
        program define entropy
        
        quietly predict classpost*, classposteriorpr
        unab myvars : classpost*
        local count : word count `myvars'
        forvalues k = 1/`count' {      
         quietly gen sum_p_lnp_`k' = classpost`k'*ln(classpost`k')
         }
        egen sum_p_lnp = rowtotal(sum_p_lnp_*)
        summ sum_p_lnp, meanonly
        local sum = r(sum)
        quietly count if !missing(sum_p_lnp)
        scalar Entropy = 1+`sum'/(r(N)*ln(`count'))
        drop classpost* sum_p_lnp*
        display Entropy
        
        end

        Comment


        • #34
          To update my previous post: I found out that the code does indeed work correctly. I wasn't aware that I had to close and re-open Stata, or type -discard- for changes in .ado files to "apply". After doing this, the .ado file/program worked as expected.

          In any case, I have updated the code a little bit more, so that the entropy is only calculated over cases that are actually included in the LCA (in case one uses a selection of the complete sample using the -if- command). Also, to answer my own question, I was correct in changing the "2" in the line to the number of classes (see previous posts #18 and #24)

          Code:
          program define entropy
           
          quietly predict classpost* if e(sample) == 1, classposteriorpr
          unab myvars : classpost*
          local count : word count `myvars'
          forvalues k = 1/`count' {       
           quietly gen sum_p_lnp_`k' = classpost`k'*ln(classpost`k') if e(sample) == 1
           }
          quietly egen sum_p_lnp = rowtotal(sum_p_lnp_*) if e(sample) == 1
          summ sum_p_lnp, meanonly
          local sum = r(sum)
          quietly count if !missing(sum_p_lnp) & e(sample) == 1
          scalar Entropy = 1+`sum'/(r(N)*ln(`count'))
          drop classpost* sum_p_lnp*
          display Entropy 
          
          end

          Comment


          • #35
            Thank you for closing the thread by showing the solution you found and sharing your code.

            Comment

            Working...
            X