How can I estimate a latent class model with individual-specific parameters in R?

180 Views Asked by At

I am trying to estimate a latent class model in R based on a discrete choice experiment. Attributes in my choice set were 'COST', 'NUCL', 'REN', 'FOSS' and 'OUTAGE'. I also asked background questions which give me the variables 'MALE', 'NL', 'Y25', 'Y50', 'INC4000' and many more (about 40 variables). The code I am using is:

df01 <- mlogit.data(data, 
                      id = "ID", 
                      choice = "Choice",
                      varying = 3:17, 
                      shape = "wide", 
                      sep = "",
                      alt.levels = c("FOSS","REN","NUCL","COST","OUTAGE"))

lc <- gmnl(Choice ~ COST + REN + NUCL + OUTAGE | MALE + NL + Y25 + Y50 + EDSEC + EDMAS + INC4000 + INC8000 + CDV + WINZ + NSGR + NVA + SPA| 0 | 0 | 1 , 
           data = df01,
           model = 'lc', 
           Q = 3, 
           panel = TRUE,
           method = "bhhh")

summary(lc)

So far, it works. However, I need to add many more individual characteristics (since I have about 40). When I add one more variable after "SPA", the model does not work anymore. Then, I get the error:

"Error in solve.default(-H) : system is computationally singular: reciprocal condition number = 2.58564e-109"

Maybe the model only accepts 17 variables since I specified "varying = 3:17"? However, the "df01"-file includes many more columns. And if I try to change "3:17" to e.g. "3:18", I get the error:

"Error in reshapeLong(data, idvar = idvar, timevar = timevar, varying = varying, : 'varying' arguments must be the same length"

What am I doing wrong? I hope someone has some good advice. Thanks for helping!

0

There are 0 best solutions below