Announcement

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

  • How can I obtain the belonging class of each individuals when using latent class choice model?

    Dear all,

    I have run the codes in the paper "lclogit: A Stata command for fitting latent-class conditional logit models via the expectation-maximization algorithm", and would like to determine belonging class of each individuals.

    Here is the code that I have used
    Code:
    use http://fmwww.bc.edu/repec/bocode/t/traindata.dta
    set seed 1234567890
    by pid, sort: egen _x1=sum(round(rnormal(0.5),1))
    list in 1/12, sepby(gid)
    
    forvalues c = 2/10 {
    quietly lclogit y price contract local wknown tod seasonal, group(gid) id(pid) nclasses(`c') membership(_x1) seed(1234567890)
    matrix b = e(b)
    matrix ic = nullmat(ic) \ `e(nclasses)', `e(ll)', `=colsof(b)', `e(caic)', `e(bic)'
    }
    
    matrix colnames ic = "Classes" "LLF" "Nparam" "CAIC" "BIC"
    matlist ic, name(columns)
    
    lclogit y price contract local wknown tod seasonal, group(gid) id(pid) nclasses(5) membership(_x1) seed(1234567890)
    
    lclogitpr pr, pr
    generate byte class = .
    
    forvalues c = 1/`e(nclasses)' {
    quietly replace class = `c' if cpmax==cp`c'
    }
    
    forvalues c = 1/`e(nclasses)' {
    quietly summarize pr if class == `c' & y==1
    local n=r(N)
    local a=r(mean)
    quietly summarize pr`c' if class == `c' & y==1
    local b=r(mean)
    matrix pr = nullmat(pr) \ `n', `c', `a', `b'
    }
    
    matrix colnames pr = "Obs" "Class" "Uncond_Pr" "Cond_PR"
    matlist pr, name(columns)
    I have tried many ways with lclogitpr pr, pr, but can not get belonging class of each individuals.

    Coud you please give me some instruction for this?

    Thanks and best regards,

    Quoc Cuong Nguyen

  • #2
    I don't completely understand but I suggest you look at example 50g in the SEM manual; my best guess is that you want:
    Code:
    predict classpost*, classposteriorpr
    where the above is copied from that example so be sure you read the doc

    Comment


    • #3
      I have tried many ways with lclogitpr pr, pr, but can not get belonging class of each individuals.
      You cannot get the class to which each individual belongs because there is no such thing.

      The nature of these models is inherently probabilistic. Each individual has a certain probability of belonging to each of the latent classes--and you may have already calculated that with the -lclogitpr, pr- command*. But no individual deterministically belongs to any one class.

      Sometimes, as a convenience, one assigns each individual a single deterministic class equal to the one for which it has the highest probability (with some rule for how to break ties). And sometimes one then uses this deterministic class assignment as a variable in later models, as if it were real. But it isn't real, and it really contradicts the meaning of the latent class model to do that. Indeed, if the desire for this single class assignment is to use it as a variable in subsequent analyses, the better approach is, instead, to keep the class as a latent variable in the subsequent analyses. As a practical matter, depending on the software you are using, that may not be possible or practical, which is, I suppose, why single deterministic class assignment is fairly widely used. But it really should be avoided when possible.

      *You are using some user-written commands for this and I don't know whether -lclogitpr, pr- calculates the overall probability of each class or whether it calculates individuals' probabilities of membership in each class. (Please read the Forum FAQ: when posting we are asked to identify commands that are not official Stata and say where they come from.) The command that Rich Goldstein suggests in #2 (which crossed with this post) is intended for use after -gsem-. It is unclear what program you used for the actual latent class analysis, but if it, too, was user-written, -predict, classposteriorpr- might not work with it.
      Last edited by Clyde Schechter; 29 Jun 2024, 14:01.

      Comment


      • #4
        Hi Rich (#2), I do not use the example 50g, but use the codes in the paper for latent class analysis for choice model. Then,
        Code:
         
         predict classpost*, classposteriorpr
        does not work.

        Hi Clyde (#3), yes I would like to get, for each individual, a certain probability of belonging to each of the latent classes. I guess these are calcualte in -lclogitpr, pr- command, but do not know how to collect it (i.e. show the values and copy to excel file, for example).
        I agree that it is hard to define what is the highest probability and assign an individual into a class. Thanks very much for your suggestion of keep the class as a latent variable in the subsequent analyses. I will use these as responses for the regression onto consumer attributes.

        Currently, I use Stata/MP 17.0, and use the -lclogit- for latent class analysis.

        Thanks for your comments and appreciate if you can give me further explaination.

        Best,

        Cuong

        Comment


        • #5
          Sorry I can't help with this request. I do not use -lclogit- and its associated programs, so I can't tell you how that would work. When I do work with latent class models I use Stata's official -gsem- for the purpose. In that framework, getting an individual's probabilities of membership in each class is done with the command that Rich Goldstein showed you in #2.

          Comment


          • #6
            Thanks Clyde. I will try to figure out how to do this in -lclogit-.

            Cuong

            Comment

            Working...
            X