Important: Read this before posting to this forum

  1. This forum is for questions related to the use of Apollo. We will answer some general choice modelling questions too, where appropriate, and time permitting. We cannot answer questions about how to estimate choice models with other software packages.
  2. There is a very detailed manual for Apollo available at http://www.ApolloChoiceModelling.com/manual.html. This contains detailed descriptions of the various Apollo functions, and numerous examples are available at http://www.ApolloChoiceModelling.com/examples.html. In addition, help files are available for all functions, using e.g. ?apollo_mnl
  3. Before asking a question on the forum, users are kindly requested to follow these steps:
    1. Check that the same issue has not already been addressed in the forum - there is a search tool.
    2. Ensure that the correct syntax has been used. For any function, detailed instructions are available directly in Apollo, e.g. by using ?apollo_mnl for apollo_mnl
    3. Check the frequently asked questions section on the Apollo website, which discusses some common issues/failures. Please see http://www.apollochoicemodelling.com/faq.html
    4. Make sure that R is using the latest official release of Apollo.
  4. If the above steps do not resolve the issue, then users should follow these steps when posting a question:
    1. provide full details on the issue, including the entire code and output, including any error messages
    2. posts will not immediately appear on the forum, but will be checked by a moderator first. This may take a day or two at busy times. There is no need to submit the post multiple times.

Error in Mixed Latent Class model

Ask questions about the results reported after estimation. If the output includes errors, please include your model code if possible.
Post Reply
TomC
Posts: 4
Joined: 21 Mar 2022, 09:18

Error in Mixed Latent Class model

Post by TomC »

Hi,

Thanks for all the help you provide through this forum.

I am having some problems running this model. When producing a two class model it appears to work fine, however when producing a three class or above the model produces NA for all SE, and the estimates look very suspicious.

Subsequently, I have also ran 3 and 4 class models with just regular Latent Class modelling with no issues (however at 5 classes it fails with NAs, I assume because it is over specified? I have also tried running the three class model with random parameters in just Delta A, Delta B and one choice option Areaplay (A,b &C), with the same issue.

In addition, I've tried playing around with the number of draws and types of draws.

Script
# ################################################################# #
#### LOAD LIBRARY AND DEFINE CORE SETTINGS ####
# ################################################################# #

### Clear memory
rm(list = ls())

### Load Apollo library
library(apollo)

### Initialise code
apollo_initialise()

### Set core controls
apollo_control = list(
modelName = "MM-MNL Test run v1 500",
modelDescr = "MM-MNL model on Belsay Hall, covariates in class allocation model",
indivID = "RID",
mixing = TRUE,
nCores = 6,
outputDirectory = "output"
)

# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS ####
# ################################################################# #

### Loading data from package

database = read.csv("~/Visitor_demo.csv", header=TRUE)
choiceAnalysis_settings <- list(
alternatives = c(a1=1, a2=2, a3=3),
avail = list(a1=database$a1_x1, a2=database$a2_x1, a3=database$a3_x1),
choiceVar = database$pref1)


# ################################################################# #
#### DEFINE MODEL PARAMETERS ####
# ################################################################# #

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(
mu_log_b_areaplay_a = 0,
mu_log_b_areaplay_b = 0,
mu_log_b_areaplay_c = 0,

mu_log_b_castle_a = 0 ,
mu_log_b_castle_b = 0 ,
mu_log_b_castle_c = 0 ,

mu_log_b_cno_a = 0,
mu_log_b_cno_b = 0,
mu_log_b_cno_c = 0,

mu_log_b_educadults_a = 0,
mu_log_b_educadults_b = 0,
mu_log_b_educadults_c = 0,

mu_log_b_eno_a = 0,
mu_log_b_eno_b = 0,
mu_log_b_eno_c = 0,

mu_log_b_eventschild_a = 0,
mu_log_b_eventschild_b = 0,
mu_log_b_eventschild_c = 0,

mu_log_b_hall_a = 0,
mu_log_b_hall_b = 0,
mu_log_b_hall_c = 0,

mu_log_b_price_a = 0,
mu_log_b_price_b = 0,
mu_log_b_price_c = 0,

mu_log_b_sno_a = 0,
mu_log_b_sno_b = 0,
mu_log_b_sno_c = 0,

mu_log_b_social_a = 0,
mu_log_b_social_b = 0,
mu_log_b_social_c = 0,

sigma_log_b_areaplay_a = 0,
sigma_log_b_areaplay_b = 0,
sigma_log_b_areaplay_c = 0,

sigma_log_b_castle_a = 0 ,
sigma_log_b_castle_b = 0 ,
sigma_log_b_castle_c = 0 ,

sigma_log_b_cno_a = 0,
sigma_log_b_cno_b = 0,
sigma_log_b_cno_c = 0,

sigma_log_b_educadults_a = 0,
sigma_log_b_educadults_b = 0,
sigma_log_b_educadults_c = 0,

sigma_log_b_eno_a = 0,
sigma_log_b_eno_b = 0,
sigma_log_b_eno_c = 0,

sigma_log_b_eventschild_a = 0,
sigma_log_b_eventschild_b = 0,
sigma_log_b_eventschild_c = 0,

sigma_log_b_hall_a = 0,
sigma_log_b_hall_b = 0,
sigma_log_b_hall_c = 0,

sigma_log_b_price_a = 0,
sigma_log_b_price_b = 0,
sigma_log_b_price_c = 0,

sigma_log_b_sno_a = 0,
sigma_log_b_sno_b = 0,
sigma_log_b_sno_c = 0,

sigma_log_b_social_a = 0,
sigma_log_b_social_b = 0,
sigma_log_b_social_c = 0,


gamma_englishheritage_a =0,
gamma_englishheritage_b =0,
gamma_englishheritage_c =0,


gamma_highincome_a =0,
gamma_highincome_b=0,
gamma_highincome_c =0,


gamma_children_a =0,
gamma_children_b =0,
gamma_children_c=0,


gamma_highereducation_a =0,
gamma_highereducation_b =0,
gamma_highereducation_c =0,

gamma_heritage_very_future_a = 0,
gamma_heritage_very_future_b = 0,
gamma_heritage_very_future_c =0,

gamma_heritage_visit_a = 0,
gamma_heritage_visit_b = 0,
gamma_heritage_visit_c =0,




delta_a = 0,
delta_b = 0,
b_delta_c = 0,

sigma_delta_a = 0,
sigma_delta_b = 0
)

### Vector with names (in quotes) of parameters to be kept fixed at their starting value in apollo_beta, use apollo_beta_fixed = c() if none
apollo_fixed = c("b_delta_c",
"mu_log_b_cno_a", "mu_log_b_sno_a", "mu_log_b_eno_a",
"mu_log_b_cno_b", "mu_log_b_sno_b", "mu_log_b_eno_b",
"mu_log_b_cno_c", "mu_log_b_sno_c", "mu_log_b_eno_c",
"gamma_children_c", "gamma_englishheritage_c", "gamma_highincome_c", "gamma_highereducation_c",
"gamma_heritage_very_future_c", "gamma_heritage_visit_c")


### Set parameters for generating draws
apollo_draws = list(
interDrawsType = "mlhs", ##changed to pmc draws
interNDraws = 500,
interUnifDraws = c(),
interNormDraws = c(
"draws_educadults_a", "draws_social_a", "draws_price_a", "draws_cno_a","draws_hall_a","draws_castle_a","draws_eno_a", "draws_areaplay_a", "draws_eventschild_a", "draws_sno_a",
"draws_educadults_b", "draws_social_b", "draws_price_b", "draws_cno_b","draws_hall_b","draws_castle_b","draws_eno_b", "draws_areaplay_b", "draws_eventschild_b", "draws_sno_b",
"draws_educadults_c", "draws_social_c", "draws_price_c", "draws_cno_c","draws_hall_c","draws_castle_c","draws_eno_c", "draws_areaplay_c", "draws_eventschild_c", "draws_sno_c",
"draws_pi_a", "draws_pi_b", "draws_pi_c"),
intraDrawsType = "pmc",
intraNDraws = 0,
intraUnifDraws = c(),
intraNormDraws = c()
)


###Random coeffecients##

apollo_randCoeff = function(apollo_beta, apollo_inputs){
randcoeff = list()

randcoeff[["b_cno_a"]] = ( mu_log_b_cno_a + 0*sigma_log_b_cno_a * 0*draws_cno_a)
randcoeff[["b_hall_a"]] = ( mu_log_b_hall_a + 0*sigma_log_b_hall_a * 0*draws_hall_a)
randcoeff[["b_castle_a"]] = ( mu_log_b_castle_a + 0*sigma_log_b_castle_a * 0*draws_castle_a)
randcoeff[["b_eno_a"]] = ( mu_log_b_eno_a + 0*sigma_log_b_eno_a * 0*draws_eno_a)
randcoeff[["b_areaplay_a"]] = ( mu_log_b_areaplay_a + 0*sigma_log_b_areaplay_a * 0*draws_areaplay_a)
randcoeff[["b_eventschild_a"]] = ( mu_log_b_eventschild_a + 0*sigma_log_b_eventschild_a * 0*draws_eventschild_a)
randcoeff[["b_sno_a"]] = ( mu_log_b_sno_a + 0*sigma_log_b_sno_a * 0*draws_sno_a)
randcoeff[["b_educadults_a"]] = ( mu_log_b_educadults_a + 0*sigma_log_b_educadults_a * 0*draws_educadults_a)
randcoeff[["b_social_a"]] = ( mu_log_b_social_a + 0*sigma_log_b_social_a * 0*draws_social_a)
randcoeff[["b_price_a"]] = ( mu_log_b_price_a + 0*sigma_log_b_price_a * 0*draws_price_a)
randcoeff[["b_delta_a"]] = ( delta_a + 0*sigma_delta_a * 0*draws_pi_a)



randcoeff[["b_cno_b"]] = ( mu_log_b_cno_b + 0*sigma_log_b_cno_b * 0*draws_cno_b)
randcoeff[["b_hall_b"]] = ( mu_log_b_hall_b + 0*sigma_log_b_hall_b * 0*draws_hall_b)
randcoeff[["b_castle_b"]] = ( mu_log_b_castle_b + 0*sigma_log_b_castle_b * 0*draws_castle_b)
randcoeff[["b_eno_b"]] = ( mu_log_b_eno_b + 0*sigma_log_b_eno_b * 0*draws_eno_b)
randcoeff[["b_areaplay_b"]] = ( mu_log_b_areaplay_b + 0*sigma_log_b_areaplay_b * 0*draws_areaplay_b)
randcoeff[["b_eventschild_b"]] = ( mu_log_b_eventschild_b + 0*sigma_log_b_eventschild_b * 0*draws_eventschild_b)
randcoeff[["b_sno_b"]] = ( mu_log_b_sno_b + 0*sigma_log_b_sno_b * 0*draws_sno_b)
randcoeff[["b_educadults_b"]] = ( mu_log_b_educadults_b + 0*sigma_log_b_educadults_b * 0*draws_educadults_b)
randcoeff[["b_social_b"]] = ( mu_log_b_social_b + 0*sigma_log_b_social_b * 0*draws_social_b)
randcoeff[["b_price_b"]] = ( mu_log_b_price_b + 0*sigma_log_b_price_b * 0*draws_price_b)
randcoeff[["b_delta_b"]] = ( delta_b + 0*sigma_delta_b * 0*draws_pi_b)


randcoeff[["b_cno_c"]] = ( mu_log_b_cno_c + 0*sigma_log_b_cno_c * 0*draws_cno_c)
randcoeff[["b_hall_c"]] = ( mu_log_b_hall_c + 0*sigma_log_b_hall_c * 0*draws_hall_c)
randcoeff[["b_castle_c"]] = ( mu_log_b_castle_c + 0*sigma_log_b_castle_c * 0*draws_castle_c)
randcoeff[["b_eno_c"]] = ( mu_log_b_eno_c + 0*sigma_log_b_eno_c * 0*draws_eno_c)
randcoeff[["b_areaplay_c"]] = ( mu_log_b_areaplay_c + 0*sigma_log_b_areaplay_c * 0*draws_areaplay_c)
randcoeff[["b_eventschild_c"]] = ( mu_log_b_eventschild_c + 0*sigma_log_b_eventschild_c * 0*draws_eventschild_c)
randcoeff[["b_sno_c"]] = ( mu_log_b_sno_c + 0*sigma_log_b_sno_c* 0*draws_sno_c)
randcoeff[["b_educadults_c"]] = ( mu_log_b_educadults_c + 0*sigma_log_b_educadults_c * 0*draws_educadults_c)
randcoeff[["b_social_c"]] = ( mu_log_b_social_c + 0*sigma_log_b_social_c * 0*draws_social_c)
randcoeff[["b_price_c"]] = ( mu_log_b_price_c + 0*sigma_log_b_price_c * 0*draws_price_c)


return(randcoeff)
}

# ################################################################# #
#### DEFINE LATENT CLASS COMPONENTS ####
# ################################################################# #


apollo_lcPars=function(apollo_beta, apollo_inputs){
lcpars = list()

lcpars[["b_cno"]] = list(b_cno_a, b_cno_b, b_cno_c)
lcpars[["b_hall"]] = list( b_hall_a, b_hall_b, b_hall_c)
lcpars[["b_castle"]] = list( b_castle_a, b_castle_b, b_castle_c)
lcpars[["b_eno"]] = list( b_eno_a, b_eno_b, b_eno_c)
lcpars[["b_areaplay"]] = list( b_areaplay_a, b_areaplay_b, b_areaplay_c)
lcpars[["b_eventschild"]] = list( b_eventschild_a, b_eventschild_b, b_eventschild_c)
lcpars[["b_sno"]] = list( b_sno_a, b_sno_b, b_sno_c)
lcpars[["b_educadults"]] = list( b_educadults_a, b_educadults_b, b_educadults_c)
lcpars[["b_social"]] = list( b_social_a, b_social_b, b_social_c)
lcpars[["b_price"]] = list( b_price_a, b_price_b, b_price_c)



### Utilities of class allocation model

V=list()
V[["class_a"]] = (b_delta_a
+ gamma_englishheritage_a * (( q5 == 1) *1
+ (q5 == 2) * 0)
+ gamma_highincome_a * ( ( ( income ==1)
+ (income ==2)
+( income == 3)
+ (income == 4) *1
+ (income == 5) * 1 ) )
+gamma_children_a *(( children == 1) *1
+ (children == 2) * 0)
+ gamma_highereducation_a *
(((education == 4) * 0)
+ ((education == 3) )
+((education == 2) *1)
+((education == 1) *1))

+ gamma_heritage_very_future_a * ((q4 == 1) *1
+(q4 == 2) * 0
+(q4 == 3) )

+ gamma_heritage_visit_a * ((q2 == 1) * 0
+(q2 == 2) * 0
+(q2 == 3) *1)

)

V[["class_b"]] = (b_delta_b
+ gamma_englishheritage_b * (( q5 == 1) *1
+ (q5 == 2) * 0)
+ gamma_highincome_b * ( ( ( income ==1)
+ (income ==2)
+( income == 3)
+ (income == 4) *1
+ (income == 5) * 1 ) )
+gamma_children_b *(( children == 1) *1
+ (children == 2) * 0)
+ gamma_highereducation_b *
(((education == 4) * 0)
+ ((education == 3) )
+((education == 2) *1)
+((education == 1) *1))

+ gamma_heritage_very_future_b * ((q4 == 1) *1
+(q4 == 2) * 0
+(q4 == 3) )
+ gamma_heritage_visit_b * ((q2 == 1) * 0
+(q2 == 2) * 0
+(q2 == 3) *1)



)


V[["class_c"]] = (b_delta_c
+ gamma_englishheritage_c * (( q5 == 1) *1
+ (q5 == 2) * 0)

+ gamma_highincome_c * ( ( ( income ==1)
+ (income ==2)
+( income == 3)
+ (income == 4) *1
+ (income == 5) * 1 ) )

+ gamma_children_c *(( children == 1) *1
+ (children == 2) * 0)

+ gamma_highereducation_c *
(((education == 4) * 0)
+ ((education == 3) )
+((education == 2) *1)
+((education == 1) *1))

+ gamma_heritage_very_future_c * ((q4 == 1) *1
+(q4 == 2) * 0
+(q4 == 3) )
+ gamma_heritage_visit_c * ((q2 == 1) * 0
+(q2 == 2) * 0
+(q2 == 3) *1)


)


classAlloc_settings = list(
classes = c(class_a=1, class_b=2, class_c=3),
utilities = V
)





lcpars[["pi_values"]] = apollo_classAlloc(classAlloc_settings)


return(lcpars)


}

# ################################################################# #
#### GROUP AND VALIDATE INPUTS ####
# ################################################################# #

apollo_inputs = apollo_validateInputs()

# ################################################################# #
#### DEFINE MODEL AND LIKELIHOOD FUNCTION ####
# ################################################################# #

apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){

### Attach inputs and detach after function exit
apollo_attach(apollo_beta, apollo_inputs)
on.exit(apollo_detach(apollo_beta, apollo_inputs))

### Create list of probabilities P
P = list()



### Loop over classes
for(s in 1:3){

### Compute class-specific utilities
V = list()
V[['A']] = (
b_cno[[s]] * ( a1_x1 == 1)
+ b_hall[[s]] * ( a1_x1 == 2)
+ b_castle[[s]] * ( a1_x1 == 3)
+ b_eno[[s]] * ( a1_x2 == 1)
+ b_areaplay[[s]] * ( a1_x2 == 2)
+ b_eventschild[[s]] * ( a1_x2 == 3)
+ b_sno[[s]] * ( a1_x3 == 1)
+ b_educadults[[s]] * ( a1_x3 == 2)
+ b_social[[s]] * ( a1_x3 == 3)
+ b_price[[s]] * ( ( a1_x4 == 1) * 2
+( a1_x4 == 2) * 4
+( a1_x4 == 3) * 6
+( a1_x4 == 4) * 8
+( a1_x4 ==5) * 10
+( a1_x4 ==6) * 12 ))

V[['B']] = (
b_cno[[s]] * ( a2_x1 == 1)
+ b_hall[[s]] * ( a2_x1 == 2)
+ b_castle[[s]] * ( a2_x1 == 3)
+ b_eno[[s]] * ( a2_x2 == 1)
+ b_areaplay[[s]] * ( a2_x2 == 2)
+ b_eventschild[[s]] * ( a2_x2 == 3)
+ b_sno[[s]] * ( a2_x3 == 1)
+ b_educadults[[s]] * ( a2_x3 == 2)
+ b_social[[s]] * ( a2_x3 == 3)
+ b_price[[s]] * ( ( a2_x4 == 1) *2
+ ( a2_x4==2) *4
+ (a2_x4==3) *6
+ (a2_x4==4) *8
+ (a2_x4==5) *10
+ (a2_x4==6) *12 ))

V[['C']] = (
b_cno[[s]] * ( a3_x1 == 1)
+ b_eno[[s]] * ( a3_x2 == 1)
+ b_sno[[s]] * ( a3_x3 == 1)
+ b_price[[s]] * ( a3_x4 == 1) )

### Define settings for MNL model component that are generic across classes
mnl_settings = list(
alternatives = c(A=1,B=2, C=3),
choiceVar = pref1

)


mnl_settings$utilities = V
mnl_settings$componentName = paste0("Class_",s)

### Compute within-class choice probabilities using MNL model
P[[paste0("Class_",s)]] = apollo_mnl(mnl_settings, functionality)

### Take product across observation for same individual
P[[paste0("Class_",s)]] = apollo_panelProd(P[[paste0("Class_",s)]], apollo_inputs ,functionality)

### Average across inter-individual draws within classes
P[[paste0("Class_",s)]] = apollo_avgInterDraws(P[[paste0("Class_",s)]], apollo_inputs, functionality)
}

### Compute latent class model probabilities
lc_settings = list(inClassProb = P, classProb=pi_values)
P[["model"]] = apollo_lc(lc_settings, apollo_inputs, functionality)

### Average across inter-individual draws in class allocation probabilities
P[["model"]] = apollo_avgInterDraws(P[["model"]], apollo_inputs, functionality)

### Prepare and return outputs of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}

Output
Model run by TColwill using Apollo 0.2.7 on R 4.1.2 for Windows.
www.ApolloChoiceModelling.com

Model name : Visit MM-MNL Class 3 V1 pmc
Model description : Visit Simple LC model on Belsay Hall, no covariates in class allocation model
Model run at : 2022-03-17 10:09:29
Estimation method : bfgs
Model diagnosis : successful convergence
Number of individuals : 190
Number of rows in database : 1140
Number of modelled outcomes : 1140

Number of cores used : 6
Number of inter-individual draws : 100 (pmc)

LL(start) : -1252.42
LL(0, whole model) : -1252.42
LL(C, whole model) : -1211.06
LL(final, whole model) : -875.52
Rho-square (0) : 0.3009
Adj.Rho-square (0) : 0.2474
Rho-square (C) : 0.2771
Adj.Rho-square (C) : 0.2217
AIC : 1885.03
BIC : 2222.63

LL(0,Class_1) : -1252.42
LL(final,Class_1) : -1133.6
LL(0,Class_2) : -1252.42
LL(final,Class_2) : -Inf Likelihood equal to zero for at least
one individual in this component.
LL(0,Class_3) : -1252.42
LL(final,Class_3) : -Inf Likelihood equal to zero for at least
one individual in this component.

Estimated parameters : 67
Time taken (hh:mm:ss) : 00:22:14.37
pre-estimation : 00:01:51.09
estimation : 00:10:58.7
post-estimation : 00:09:24.58
Iterations : 366

Unconstrained optimisation.

Estimates:
Estimate s.e. t.rat.(0) Rob.s.e. Rob.t.rat.(0)
mu_log_b_areaplay_a -0.16928 NA NA NA NA
mu_log_b_areaplay_b 3004.36005 NA NA NA NA
mu_log_b_areaplay_c -326.31949 NA NA NA NA
mu_log_b_castle_a 0.30221 NA NA NA NA
mu_log_b_castle_b 2457.89438 NA NA NA NA
mu_log_b_castle_c 6614.35597 NA NA NA NA
mu_log_b_cno_a 0.00000 NA NA NA NA
mu_log_b_cno_b 0.00000 NA NA NA NA
mu_log_b_cno_c 0.00000 NA NA NA NA
mu_log_b_educadults_a 0.01917 NA NA NA NA
mu_log_b_educadults_b 830.86443 NA NA NA NA
mu_log_b_educadults_c -141.59485 NA NA NA NA
mu_log_b_eno_a 0.00000 NA NA NA NA
mu_log_b_eno_b 0.00000 NA NA NA NA
mu_log_b_eno_c 0.00000 NA NA NA NA
mu_log_b_eventschild_a -0.29509 NA NA NA NA
mu_log_b_eventschild_b 1707.29144 NA NA NA NA
mu_log_b_eventschild_c -940.36912 NA NA NA NA
mu_log_b_hall_a 0.31901 NA NA NA NA
mu_log_b_hall_b 2181.92695 NA NA NA NA
mu_log_b_hall_c 4478.03264 NA NA NA NA
mu_log_b_price_a -0.05604 NA NA NA NA
mu_log_b_price_b -148.93076 NA NA NA NA
mu_log_b_price_c -590.92589 NA NA NA NA
mu_log_b_sno_a 0.00000 NA NA NA NA
mu_log_b_sno_b 0.00000 NA NA NA NA
mu_log_b_sno_c 0.00000 NA NA NA NA
mu_log_b_social_a -0.02015 NA NA NA NA
mu_log_b_social_b 1180.19742 NA NA NA NA
mu_log_b_social_c -1499.99203 NA NA NA NA
sigma_log_b_areaplay_a -0.08176 NA NA NA NA
sigma_log_b_areaplay_b -505.52589 NA NA NA NA
sigma_log_b_areaplay_c 2325.31844 NA NA NA NA
sigma_log_b_castle_a 0.95924 NA NA NA NA
sigma_log_b_castle_b -1161.89618 NA NA NA NA
sigma_log_b_castle_c -531.21592 NA NA NA NA
sigma_log_b_cno_a -0.30539 NA NA NA NA
sigma_log_b_cno_b 901.70966 NA NA NA NA
sigma_log_b_cno_c -1813.21190 NA NA NA NA
sigma_log_b_educadults_a -0.06946 NA NA NA NA
sigma_log_b_educadults_b 1107.43212 NA NA NA NA
sigma_log_b_educadults_c -424.59087 NA NA NA NA
sigma_log_b_eno_a 0.82920 NA NA NA NA
sigma_log_b_eno_b 1354.58093 NA NA NA NA
sigma_log_b_eno_c 1691.90057 NA NA NA NA
sigma_log_b_eventschild_a -0.18289 NA NA NA NA
sigma_log_b_eventschild_b 260.40792 NA NA NA NA
sigma_log_b_eventschild_c -900.31635 NA NA NA NA
sigma_log_b_hall_a 0.77380 NA NA NA NA
sigma_log_b_hall_b 463.41418 NA NA NA NA
sigma_log_b_hall_c -2239.05269 NA NA NA NA
sigma_log_b_price_a 0.05705 NA NA NA NA
sigma_log_b_price_b -201.84341 NA NA NA NA
sigma_log_b_price_c 585.59683 NA NA NA NA
sigma_log_b_sno_a -0.28233 NA NA NA NA
sigma_log_b_sno_b 1399.26160 NA NA NA NA
sigma_log_b_sno_c 2208.94517 NA NA NA NA
sigma_log_b_social_a 0.62873 NA NA NA NA
sigma_log_b_social_b -439.00748 NA NA NA NA
sigma_log_b_social_c 451.31010 NA NA NA NA
gamma_englishheritage_a 1024.01459 NA NA NA NA
gamma_englishheritage_b 958.55245 NA NA NA NA
gamma_englishheritage_c 0.00000 NA NA NA NA
gamma_highincome_a -3965.36036 NA NA NA NA
gamma_highincome_b -2818.90149 NA NA NA NA
gamma_highincome_c 0.00000 NA NA NA NA
gamma_children_a 8527.20836 NA NA NA NA
gamma_children_b 3266.26965 NA NA NA NA
gamma_children_c 0.00000 NA NA NA NA
gamma_highereducation_a 7480.63409 NA NA NA NA
gamma_highereducation_b 2864.21271 NA NA NA NA
gamma_highereducation_c 0.00000 NA NA NA NA
gamma_heritage_very_future_a -858.05016 NA NA NA NA
gamma_heritage_very_future_b 1873.29907 NA NA NA NA
gamma_heritage_very_future_c 0.00000 NA NA NA NA
gamma_heritage_visit_a -3072.30863 NA NA NA NA
gamma_heritage_visit_b -879.06421 NA NA NA NA
gamma_heritage_visit_c 0.00000 NA NA NA NA
delta_a -6755.58876 NA NA NA NA
delta_b -2040.71110 NA NA NA NA
b_delta_c 0.00000 NA NA NA NA
sigma_delta_a 1753.52771 NA NA NA NA
sigma_delta_b 179.13502 NA NA NA NA


Summary of class allocation for LC model component :
Mean prob.
Class_1 0.1753
Class_2 0.5269
Class_3 0.2978


Overview of choices for MNL model component Class_1:
A B C
Times available 1140.00 1140.00 1140.00
Times chosen 431.00 467.00 242.00
Percentage chosen overall 37.81 40.96 21.23
Percentage chosen when available 37.81 40.96 21.23


Overview of choices for MNL model component Class_2:
A B C
Times available 1140.00 1140.00 1140.00
Times chosen 431.00 467.00 242.00
Percentage chosen overall 37.81 40.96 21.23
Percentage chosen when available 37.81 40.96 21.23


Overview of choices for MNL model component Class_3:
A B C
Times available 1140.00 1140.00 1140.00
Times chosen 431.00 467.00 242.00
Percentage chosen overall 37.81 40.96 21.23
Percentage chosen when available 37.81 40.96 21.23



mu_log_b_areaplay_a NA
mu_log_b_areaplay_b NA
mu_log_b_areaplay_c NA
mu_log_b_castle_a NA
mu_log_b_castle_b NA
mu_log_b_castle_c NA
mu_log_b_educadults_a NA
mu_log_b_educadults_b NA
mu_log_b_educadults_c NA
mu_log_b_eventschild_a NA
mu_log_b_eventschild_b NA
mu_log_b_eventschild_c NA
mu_log_b_hall_a NA
mu_log_b_hall_b NA
mu_log_b_hall_c NA
mu_log_b_price_a NA
mu_log_b_price_b NA
mu_log_b_price_c NA
mu_log_b_social_a NA
mu_log_b_social_b NA
mu_log_b_social_c NA
sigma_log_b_areaplay_a NA
sigma_log_b_areaplay_b NA
sigma_log_b_areaplay_c NA
sigma_log_b_castle_a NA
sigma_log_b_castle_b NA
sigma_log_b_castle_c NA
sigma_log_b_cno_a NA
sigma_log_b_cno_b NA
sigma_log_b_cno_c NA
sigma_log_b_educadults_a NA
sigma_log_b_educadults_b NA
sigma_log_b_educadults_c NA
sigma_log_b_eno_a NA
sigma_log_b_eno_b NA
sigma_log_b_eno_c NA
sigma_log_b_eventschild_a NA
sigma_log_b_eventschild_b NA
sigma_log_b_eventschild_c NA
sigma_log_b_hall_a NA
sigma_log_b_hall_b NA
sigma_log_b_hall_c NA
sigma_log_b_price_a NA
sigma_log_b_price_b NA
sigma_log_b_price_c NA
sigma_log_b_sno_a NA
sigma_log_b_sno_b NA
sigma_log_b_sno_c NA
sigma_log_b_social_a NA
sigma_log_b_social_b NA
sigma_log_b_social_c NA
gamma_englishheritage_a NA
gamma_englishheritage_b NA
gamma_highincome_a NA
gamma_highincome_b NA
gamma_children_a NA
gamma_children_b NA
gamma_highereducation_a NA
gamma_highereducation_b NA
gamma_heritage_very_future_a NA
gamma_heritage_very_future_b NA
gamma_heritage_visit_a NA
gamma_heritage_visit_b NA
delta_a NA
delta_b NA
sigma_delta_a NA
sigma_delta_b NA

20 worst outliers in terms of lowest average per choice prediction:
ID Avg prob per choice
941 0.1712810
1035 0.2564993
1087 0.2635812
1030 0.2680049
1145 0.2687322
1110 0.2701354
1080 0.2717807
1131 0.2823847
1153 0.2831397
1036 0.2860580
1078 0.2869393
1109 0.2949251
1054 0.2949613
1122 0.2968025
1062 0.2979753
1140 0.2981836
1127 0.2983129
1160 0.3025875
1051 0.3030202
1066 0.3031365

Changes in parameter estimates from starting values:
Initial Estimate Difference
mu_log_b_areaplay_a 0.000 -0.16928 -0.16928
mu_log_b_areaplay_b 0.000 3004.36005 3004.36005
mu_log_b_areaplay_c 0.000 -326.31949 -326.31949
mu_log_b_castle_a 0.000 0.30221 0.30221
mu_log_b_castle_b 0.000 2457.89438 2457.89438
mu_log_b_castle_c 0.000 6614.35597 6614.35597
mu_log_b_cno_a 0.000 0.00000 0.00000
mu_log_b_cno_b 0.000 0.00000 0.00000
mu_log_b_cno_c 0.000 0.00000 0.00000
mu_log_b_educadults_a 0.000 0.01917 0.01917
mu_log_b_educadults_b 0.000 830.86443 830.86443
mu_log_b_educadults_c 0.000 -141.59485 -141.59485
mu_log_b_eno_a 0.000 0.00000 0.00000
mu_log_b_eno_b 0.000 0.00000 0.00000
mu_log_b_eno_c 0.000 0.00000 0.00000
mu_log_b_eventschild_a 0.000 -0.29509 -0.29509
mu_log_b_eventschild_b 0.000 1707.29144 1707.29144
mu_log_b_eventschild_c 0.000 -940.36912 -940.36912
mu_log_b_hall_a 0.000 0.31901 0.31901
mu_log_b_hall_b 0.000 2181.92695 2181.92695
mu_log_b_hall_c 0.000 4478.03264 4478.03264
mu_log_b_price_a 0.000 -0.05604 -0.05604
mu_log_b_price_b 0.000 -148.93076 -148.93076
mu_log_b_price_c 0.000 -590.92589 -590.92589
mu_log_b_sno_a 0.000 0.00000 0.00000
mu_log_b_sno_b 0.000 0.00000 0.00000
mu_log_b_sno_c 0.000 0.00000 0.00000
mu_log_b_social_a 0.000 -0.02015 -0.02015
mu_log_b_social_b 0.000 1180.19742 1180.19742
mu_log_b_social_c 0.000 -1499.99203 -1499.99203
sigma_log_b_areaplay_a 0.000 -0.08176 -0.08176
sigma_log_b_areaplay_b 0.000 -505.52589 -505.52589
sigma_log_b_areaplay_c 0.000 2325.31844 2325.31844
sigma_log_b_castle_a 0.000 0.95924 0.95924
sigma_log_b_castle_b 0.000 -1161.89618 -1161.89618
sigma_log_b_castle_c 0.000 -531.21592 -531.21592
sigma_log_b_cno_a 0.000 -0.30539 -0.30539
sigma_log_b_cno_b 0.000 901.70966 901.70966
sigma_log_b_cno_c 0.000 -1813.21190 -1813.21190
sigma_log_b_educadults_a 0.000 -0.06946 -0.06946
sigma_log_b_educadults_b 0.000 1107.43212 1107.43212
sigma_log_b_educadults_c 0.000 -424.59087 -424.59087
sigma_log_b_eno_a 0.000 0.82920 0.82920
sigma_log_b_eno_b 0.000 1354.58093 1354.58093
sigma_log_b_eno_c 0.000 1691.90057 1691.90057
sigma_log_b_eventschild_a 0.000 -0.18289 -0.18289
sigma_log_b_eventschild_b 0.000 260.40792 260.40792
sigma_log_b_eventschild_c 0.000 -900.31635 -900.31635
sigma_log_b_hall_a 0.000 0.77380 0.77380
sigma_log_b_hall_b 0.000 463.41418 463.41418
sigma_log_b_hall_c 0.000 -2239.05269 -2239.05269
sigma_log_b_price_a 0.000 0.05705 0.05705
sigma_log_b_price_b 0.000 -201.84341 -201.84341
sigma_log_b_price_c 0.000 585.59683 585.59683
sigma_log_b_sno_a 0.000 -0.28233 -0.28233
sigma_log_b_sno_b 0.000 1399.26160 1399.26160
sigma_log_b_sno_c 0.000 2208.94517 2208.94517
sigma_log_b_social_a 0.000 0.62873 0.62873
sigma_log_b_social_b 0.000 -439.00748 -439.00748
sigma_log_b_social_c 0.000 451.31010 451.31010
gamma_englishheritage_a 0.000 1024.01459 1024.01459
gamma_englishheritage_b 0.000 958.55245 958.55245
gamma_englishheritage_c 0.000 0.00000 0.00000
gamma_highincome_a 0.000 -3965.36036 -3965.36036
gamma_highincome_b 0.000 -2818.90149 -2818.90149
gamma_highincome_c 0.000 0.00000 0.00000
gamma_children_a 0.000 8527.20836 8527.20836
gamma_children_b 0.000 3266.26965 3266.26965
gamma_children_c 0.000 0.00000 0.00000
gamma_highereducation_a 0.000 7480.63409 7480.63409
gamma_highereducation_b 0.000 2864.21271 2864.21271
gamma_highereducation_c 0.000 0.00000 0.00000
gamma_heritage_very_future_a 0.000 -858.05016 -858.05016
gamma_heritage_very_future_b 0.000 1873.29907 1873.29907
gamma_heritage_very_future_c 0.000 0.00000 0.00000
gamma_heritage_visit_a 0.000 -3072.30863 -3072.30863
gamma_heritage_visit_b 0.000 -879.06421 -879.06421
gamma_heritage_visit_c 0.000 0.00000 0.00000
delta_a 0.000 -6755.58876 -6755.58876
delta_b 0.000 -2040.71110 -2040.71110
b_delta_c 0.000 0.00000 0.00000
sigma_delta_a 0.000 1753.52771 1753.52771
sigma_delta_b 0.000 179.13502 179.13502

Settings and functions used in model definition:

apollo_control
--------------
Value
modelName "Visit MM-MNL Class 3 V1 pmc"
modelDescr "Visit Simple LC model on Belsay Hall, no covariates in class allocation model"
indivID "RID"
mixing "TRUE"
nCores "6"
outputDirectory "output/"
debug "FALSE"
workInLogs "FALSE"
seed "13"
HB "FALSE"
noValidation "FALSE"
noDiagnostics "FALSE"
calculateLLC "TRUE"
panelData "TRUE"
analyticGrad "TRUE"
analyticGrad_manualSet "FALSE"

Hessian routines attempted
--------------
numerical jacobian of LL analytical gradient

Scaling in estimation
--------------
Value
mu_log_b_areaplay_a 1.681677e-01
mu_log_b_areaplay_b 2.803410e+03
mu_log_b_areaplay_c 3.263594e+02
mu_log_b_castle_a 3.084298e-01
mu_log_b_castle_b 2.387801e+03
mu_log_b_castle_c 6.591531e+03
mu_log_b_educadults_a 1.913314e-02
mu_log_b_educadults_b 8.204261e+02
mu_log_b_educadults_c 1.415768e+02
mu_log_b_eventschild_a 2.891355e-01
mu_log_b_eventschild_b 1.644573e+03
mu_log_b_eventschild_c 9.411673e+02
mu_log_b_hall_a 3.206292e-01
mu_log_b_hall_b 2.163831e+03
mu_log_b_hall_c 4.464013e+03
mu_log_b_price_a 5.657223e-02
mu_log_b_price_b 1.464994e+02
mu_log_b_price_c 5.908180e+02
mu_log_b_social_a 2.014402e-02
mu_log_b_social_b 1.178308e+03
mu_log_b_social_c 1.498977e+03
sigma_log_b_areaplay_a 8.174196e-02
sigma_log_b_areaplay_b 5.004401e+02
sigma_log_b_areaplay_c 2.325589e+03
sigma_log_b_castle_a 9.660690e-01
sigma_log_b_castle_b 1.133048e+03
sigma_log_b_castle_c 5.310414e+02
sigma_log_b_cno_a 3.107990e-01
sigma_log_b_cno_b 8.916439e+02
sigma_log_b_cno_c 1.814123e+03
sigma_log_b_educadults_a 6.936703e-02
sigma_log_b_educadults_b 1.099849e+03
sigma_log_b_educadults_c 4.243019e+02
sigma_log_b_eno_a 8.304969e-01
sigma_log_b_eno_b 1.307996e+03
sigma_log_b_eno_c 1.696654e+03
sigma_log_b_eventschild_a 1.840628e-01
sigma_log_b_eventschild_b 2.631237e+02
sigma_log_b_eventschild_c 9.025027e+02
sigma_log_b_hall_a 7.785056e-01
sigma_log_b_hall_b 4.581843e+02
sigma_log_b_hall_c 2.237547e+03
sigma_log_b_price_a 5.668826e-02
sigma_log_b_price_b 1.983826e+02
sigma_log_b_price_c 5.903603e+02
sigma_log_b_sno_a 2.817422e-01
sigma_log_b_sno_b 1.368183e+03
sigma_log_b_sno_c 2.196609e+03
sigma_log_b_social_a 6.283991e-01
sigma_log_b_social_b 4.296221e+02
sigma_log_b_social_c 4.513092e+02
gamma_englishheritage_a 1.022535e+03
gamma_englishheritage_b 9.556722e+02
gamma_highincome_a 3.941580e+03
gamma_highincome_b 2.827438e+03
gamma_children_a 8.422864e+03
gamma_children_b 3.276342e+03
gamma_highereducation_a 7.403916e+03
gamma_highereducation_b 2.883096e+03
gamma_heritage_very_future_a 8.414569e+02
gamma_heritage_very_future_b 1.836735e+03
gamma_heritage_visit_a 3.030201e+03
gamma_heritage_visit_b 8.863527e+02
delta_a 6.620170e+03
delta_b 2.003061e+03
sigma_delta_a 1.718152e+03
sigma_delta_b 1.744937e+02

Scaling used in computing Hessian
--------------
Value
mu_log_b_areaplay_a 1.692759e-01
mu_log_b_areaplay_b 3.004360e+03
mu_log_b_areaplay_c 3.263195e+02
mu_log_b_castle_a 3.022086e-01
mu_log_b_castle_b 2.457894e+03
mu_log_b_castle_c 6.614356e+03
mu_log_b_educadults_a 1.916761e-02
mu_log_b_educadults_b 8.308644e+02
mu_log_b_educadults_c 1.415948e+02
mu_log_b_eventschild_a 2.950926e-01
mu_log_b_eventschild_b 1.707291e+03
mu_log_b_eventschild_c 9.403691e+02
mu_log_b_hall_a 3.190099e-01
mu_log_b_hall_b 2.181927e+03
mu_log_b_hall_c 4.478033e+03
mu_log_b_price_a 5.603745e-02
mu_log_b_price_b 1.489308e+02
mu_log_b_price_c 5.909259e+02
mu_log_b_social_a 2.015416e-02
mu_log_b_social_b 1.180197e+03
mu_log_b_social_c 1.499992e+03
sigma_log_b_areaplay_a 8.176051e-02
sigma_log_b_areaplay_b 5.055259e+02
sigma_log_b_areaplay_c 2.325318e+03
sigma_log_b_castle_a 9.592374e-01
sigma_log_b_castle_b 1.161896e+03
sigma_log_b_castle_c 5.312159e+02
sigma_log_b_cno_a 3.053948e-01
sigma_log_b_cno_b 9.017097e+02
sigma_log_b_cno_c 1.813212e+03
sigma_log_b_educadults_a 6.945674e-02
sigma_log_b_educadults_b 1.107432e+03
sigma_log_b_educadults_c 4.245909e+02
sigma_log_b_eno_a 8.291966e-01
sigma_log_b_eno_b 1.354581e+03
sigma_log_b_eno_c 1.691901e+03
sigma_log_b_eventschild_a 1.828888e-01
sigma_log_b_eventschild_b 2.604079e+02
sigma_log_b_eventschild_c 9.003164e+02
sigma_log_b_hall_a 7.738004e-01
sigma_log_b_hall_b 4.634142e+02
sigma_log_b_hall_c 2.239053e+03
sigma_log_b_price_a 5.705048e-02
sigma_log_b_price_b 2.018434e+02
sigma_log_b_price_c 5.855968e+02
sigma_log_b_sno_a 2.823324e-01
sigma_log_b_sno_b 1.399262e+03
sigma_log_b_sno_c 2.208945e+03
sigma_log_b_social_a 6.287303e-01
sigma_log_b_social_b 4.390075e+02
sigma_log_b_social_c 4.513101e+02
gamma_englishheritage_a 1.024015e+03
gamma_englishheritage_b 9.585525e+02
gamma_highincome_a 3.965360e+03
gamma_highincome_b 2.818901e+03
gamma_children_a 8.527208e+03
gamma_children_b 3.266270e+03
gamma_highereducation_a 7.480634e+03
gamma_highereducation_b 2.864213e+03
gamma_heritage_very_future_a 8.580502e+02
gamma_heritage_very_future_b 1.873299e+03
gamma_heritage_visit_a 3.072309e+03
gamma_heritage_visit_b 8.790642e+02
delta_a 6.755589e+03
delta_b 2.040711e+03
sigma_delta_a 1.753528e+03
sigma_delta_b 1.791350e+02

Rand Coeff. deleted for character limit
}
<bytecode: 0x000002097359d120>




)


classAlloc_settings = list(
classes = c(class_a=1, class_b=2, class_c=3),
utilities = V
)





lcpars[["pi_values"]] = apollo_classAlloc(classAlloc_settings)


return(lcpars)


}
<bytecode: 0x000002091808ed90>



### Define settings for MNL model component that are generic across classes
mnl_settings = list(
alternatives = c(A=1,B=2, C=3),
choiceVar = pref1

)


mnl_settings$utilities = V
mnl_settings$componentName = paste0("Class_",s)

### Compute within-class choice probabilities using MNL model
P[[paste0("Class_",s)]] = apollo_mnl(mnl_settings, functionality)

### Take product across observation for same individual
P[[paste0("Class_",s)]] = apollo_panelProd(P[[paste0("Class_",s)]], apollo_inputs ,functionality)

### Average across inter-individual draws within classes
P[[paste0("Class_",s)]] = apollo_avgInterDraws(P[[paste0("Class_",s)]], apollo_inputs, functionality)
}

### Compute latent class model probabilities
lc_settings = list(inClassProb = P, classProb=pi_values)
P[["model"]] = apollo_lc(lc_settings, apollo_inputs, functionality)

### Average across inter-individual draws in class allocation probabilities
P[["model"]] = apollo_avgInterDraws(P[["model"]], apollo_inputs, functionality)

### Prepare and return outputs of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}
<bytecode: 0x000002097bceaf38>

Any help will be greatly appreciated.

Thanks
Tom
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: Error in Mixed Latent Class model

Post by stephanehess »

Hi

why are you multiplying by 0 in the below? That would mean the parameter is not used, and then the model would not be identified. But you get estimates, so the output doesn't seem to come from the code you copied below

Code: Select all

0*sigma_log_b_cno_a * 0*draws_cno_a
Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
TomC
Posts: 4
Joined: 21 Mar 2022, 09:18

Re: Error in Mixed Latent Class model

Post by TomC »

stephanehess wrote: 21 Mar 2022, 18:33 Hi

why are you multiplying by 0 in the below? That would mean the parameter is not used, and then the model would not be identified. But you get estimates, so the output doesn't seem to come from the code you copied below

Code: Select all

0*sigma_log_b_cno_a * 0*draws_cno_a
Stephane
Apologies, I've copied the wrong code in here. This was an attempt to check if it was the random parameters were causing this. I am also aware that even to do so, this was the wrong way - this was an old code that somehow I ended up copying, however I've tried a specification with no luck

Code: Select all

 mu_log_b_hall_a +  0*draws_hall_a 
with exception to one or two parameters

Code: Select all

 mu_log_b_cno_a + sigma_log_b_cno_a * draws_cno_a 
For example.

However, this still came up with errors NA.

The code that was meant to be copied in was this one in the original post was this one:

Code: Select all

# ################################################################# #
#### LOAD LIBRARY AND DEFINE CORE SETTINGS                       ####
# ################################################################# #

### Clear memory
rm(list = ls())

### Load Apollo library
library(apollo)

### Initialise code
apollo_initialise()

### Set core controls
apollo_control = list(
  modelName       = "MM-MNL Test run v1 500",
  modelDescr      = "MM-MNL model on Belsay Hall,  covariates in class allocation model",
  indivID         = "RID",
  mixing = TRUE,
  nCores = 4,
  outputDirectory = "output"
)

# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS                     ####
# ################################################################# #

### Loading data from package

database = read.csv("~/Visitor_demo.csv", header=TRUE)
choiceAnalysis_settings <- list(
  alternatives = c(a1=1, a2=2, a3=3),
  avail        = list(a1=database$a1_x1, a2=database$a2_x1, a3=database$a3_x1),
  choiceVar    = database$pref1)


# ################################################################# #
#### DEFINE MODEL PARAMETERS                                     ####
# ################################################################# #

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(
  mu_log_b_areaplay_a           = 0,
  mu_log_b_areaplay_b           = 0,
  mu_log_b_areaplay_c           = 0,
  
  mu_log_b_castle_a = 0 ,
  mu_log_b_castle_b = 0 ,
  mu_log_b_castle_c = 0 ,
  
  mu_log_b_cno_a          = 0,
  mu_log_b_cno_b          = 0,
  mu_log_b_cno_c          = 0,
  
  mu_log_b_educadults_a      = 0,
  mu_log_b_educadults_b      = 0,
  mu_log_b_educadults_c      = 0,
  
  mu_log_b_eno_a             = 0,
  mu_log_b_eno_b             = 0,
  mu_log_b_eno_c             = 0,
  
  mu_log_b_eventschild_a    = 0,
  mu_log_b_eventschild_b    = 0,
  mu_log_b_eventschild_c    = 0,
  
  mu_log_b_hall_a        = 0,
  mu_log_b_hall_b        = 0,
  mu_log_b_hall_c        = 0,
  
  mu_log_b_price_a                    = 0,
  mu_log_b_price_b                    = 0,
  mu_log_b_price_c                   = 0,
  
  mu_log_b_sno_a              = 0,
  mu_log_b_sno_b              = 0,
  mu_log_b_sno_c              = 0,
  
  mu_log_b_social_a          = 0,
  mu_log_b_social_b          = 0,
  mu_log_b_social_c          = 0,
  
  sigma_log_b_areaplay_a           = 0,
  sigma_log_b_areaplay_b           = 0,
  sigma_log_b_areaplay_c           = 0,
  
  sigma_log_b_castle_a = 0 ,
  sigma_log_b_castle_b = 0 ,
  sigma_log_b_castle_c = 0 ,
  
  sigma_log_b_cno_a          = 0,
  sigma_log_b_cno_b          = 0,
  sigma_log_b_cno_c          = 0,
  
  sigma_log_b_educadults_a      = 0,
  sigma_log_b_educadults_b      = 0,
  sigma_log_b_educadults_c      = 0,
  
  sigma_log_b_eno_a             = 0,
  sigma_log_b_eno_b             = 0,
  sigma_log_b_eno_c            = 0,
  
  sigma_log_b_eventschild_a    = 0,
  sigma_log_b_eventschild_b    = 0,
  sigma_log_b_eventschild_c   = 0,
  
  sigma_log_b_hall_a        = 0,
  sigma_log_b_hall_b        = 0,
  sigma_log_b_hall_c        = 0,
  
  sigma_log_b_price_a                    = 0,
  sigma_log_b_price_b                    = 0,
  sigma_log_b_price_c                   = 0,
  
  sigma_log_b_sno_a              = 0,
  sigma_log_b_sno_b              = 0,
  sigma_log_b_sno_c              = 0,
  
  sigma_log_b_social_a          = 0,
  sigma_log_b_social_b          = 0,
  sigma_log_b_social_c          = 0,
  
  
  gamma_englishheritage_a =0,
  gamma_englishheritage_b =0,
  gamma_englishheritage_c =0,
  
  
  gamma_highincome_a =0,
  gamma_highincome_b=0, 
  gamma_highincome_c =0,
  
  
  gamma_children_a =0,
  gamma_children_b =0, 
  gamma_children_c=0,
  
  
  gamma_highereducation_a  =0,
  gamma_highereducation_b  =0,
  gamma_highereducation_c  =0,
  
  gamma_heritage_very_future_a = 0,
  gamma_heritage_very_future_b = 0,
  gamma_heritage_very_future_c =0,
  
  gamma_heritage_visit_a = 0,
  gamma_heritage_visit_b = 0,
  gamma_heritage_visit_c =0,
  
  

  
  delta_a   = 0,
  delta_b   = 0,
  b_delta_c   = 0,
  
  sigma_delta_a   = 0,
  sigma_delta_b  = 0
  )

### Vector with names (in quotes) of parameters to be kept fixed at their starting value in apollo_beta, use apollo_beta_fixed = c() if none
apollo_fixed = c("b_delta_c", 
                 "mu_log_b_cno_a", "mu_log_b_sno_a", "mu_log_b_eno_a", 
                 "mu_log_b_cno_b", "mu_log_b_sno_b", "mu_log_b_eno_b", 
                 "mu_log_b_cno_c", "mu_log_b_sno_c", "mu_log_b_eno_c", 
                 "gamma_children_c", "gamma_englishheritage_c", "gamma_highincome_c", "gamma_highereducation_c",
                 "gamma_heritage_very_future_c", "gamma_heritage_visit_c") 


### Set parameters for generating draws
apollo_draws = list(
  interDrawsType = "mlhs",  ##changed to pmc draws
  interNDraws    = 100,
  interUnifDraws = c(),
  interNormDraws = c(
    "draws_educadults_a", "draws_social_a", "draws_price_a", "draws_cno_a","draws_hall_a","draws_castle_a","draws_eno_a", "draws_areaplay_a", "draws_eventschild_a", "draws_sno_a",
    "draws_educadults_b", "draws_social_b", "draws_price_b", "draws_cno_b","draws_hall_b","draws_castle_b","draws_eno_b", "draws_areaplay_b", "draws_eventschild_b", "draws_sno_b",
    "draws_educadults_c", "draws_social_c", "draws_price_c", "draws_cno_c","draws_hall_c","draws_castle_c","draws_eno_c", "draws_areaplay_c", "draws_eventschild_c", "draws_sno_c",
      "draws_pi_a", "draws_pi_b", "draws_pi_c"),
  intraDrawsType = "pmc",
  intraNDraws    = 0,
  intraUnifDraws = c(),
  intraNormDraws = c()
)


###Random coeffecients##

apollo_randCoeff = function(apollo_beta, apollo_inputs){
  randcoeff = list()
  
  randcoeff[["b_cno_a"]] = ( mu_log_b_cno_a + sigma_log_b_cno_a * draws_cno_a)
  randcoeff[["b_hall_a"]] = ( mu_log_b_hall_a + sigma_log_b_hall_a * draws_hall_a)
  randcoeff[["b_castle_a"]] = ( mu_log_b_castle_a + sigma_log_b_castle_a * draws_castle_a)
  randcoeff[["b_eno_a"]] = ( mu_log_b_eno_a + sigma_log_b_eno_a * draws_eno_a)
  randcoeff[["b_areaplay_a"]] = ( mu_log_b_areaplay_a + sigma_log_b_areaplay_a * draws_areaplay_a)
  randcoeff[["b_eventschild_a"]] = ( mu_log_b_eventschild_a + sigma_log_b_eventschild_a * draws_eventschild_a)
  randcoeff[["b_sno_a"]] = ( mu_log_b_sno_a + sigma_log_b_sno_a * draws_sno_a)
  randcoeff[["b_educadults_a"]] = ( mu_log_b_educadults_a + sigma_log_b_educadults_a * draws_educadults_a)
  randcoeff[["b_social_a"]] = ( mu_log_b_social_a + sigma_log_b_social_a * draws_social_a)
  randcoeff[["b_price_a"]] = ( mu_log_b_price_a + sigma_log_b_price_a * draws_price_a)
  randcoeff[["b_delta_a"]] = ( delta_a + sigma_delta_a * draws_pi_a)
  
  
  
  randcoeff[["b_cno_b"]] = ( mu_log_b_cno_b + sigma_log_b_cno_b * draws_cno_b)
  randcoeff[["b_hall_b"]] = ( mu_log_b_hall_b + sigma_log_b_hall_b * draws_hall_b)
  randcoeff[["b_castle_b"]] = ( mu_log_b_castle_b + sigma_log_b_castle_b * draws_castle_b)
  randcoeff[["b_eno_b"]] = ( mu_log_b_eno_b + sigma_log_b_eno_b * draws_eno_b)
  randcoeff[["b_areaplay_b"]] = ( mu_log_b_areaplay_b + sigma_log_b_areaplay_b * draws_areaplay_b)
  randcoeff[["b_eventschild_b"]] = ( mu_log_b_eventschild_b + sigma_log_b_eventschild_b * draws_eventschild_b)
  randcoeff[["b_sno_b"]] = ( mu_log_b_sno_b + sigma_log_b_sno_b * draws_sno_b)
  randcoeff[["b_educadults_b"]] = ( mu_log_b_educadults_b + sigma_log_b_educadults_b * draws_educadults_b)
  randcoeff[["b_social_b"]] = ( mu_log_b_social_b + sigma_log_b_social_b * draws_social_b)
  randcoeff[["b_price_b"]] = ( mu_log_b_price_b + sigma_log_b_price_b * draws_price_b)
  randcoeff[["b_delta_b"]] = ( delta_b + sigma_delta_b * draws_pi_b)
  
  
  randcoeff[["b_cno_c"]] = ( mu_log_b_cno_c + sigma_log_b_cno_c * draws_cno_c)
  randcoeff[["b_hall_c"]] = ( mu_log_b_hall_c + sigma_log_b_hall_c * draws_hall_c)
  randcoeff[["b_castle_c"]] = ( mu_log_b_castle_c + sigma_log_b_castle_c * draws_castle_c)
  randcoeff[["b_eno_c"]] = ( mu_log_b_eno_c + sigma_log_b_eno_c * draws_eno_c)
  randcoeff[["b_areaplay_c"]] = ( mu_log_b_areaplay_c + sigma_log_b_areaplay_c * draws_areaplay_c)
  randcoeff[["b_eventschild_c"]] = ( mu_log_b_eventschild_c + sigma_log_b_eventschild_c * draws_eventschild_c)
  randcoeff[["b_sno_c"]] = ( mu_log_b_sno_c + sigma_log_b_sno_c* draws_sno_c)
  randcoeff[["b_educadults_c"]] = ( mu_log_b_educadults_c + sigma_log_b_educadults_c * draws_educadults_c)
  randcoeff[["b_social_c"]] = ( mu_log_b_social_c + sigma_log_b_social_c * draws_social_c)
  randcoeff[["b_price_c"]] = ( mu_log_b_price_c + sigma_log_b_price_c * draws_price_c)


  return(randcoeff)
}

# ################################################################# #
#### DEFINE LATENT CLASS COMPONENTS                              ####
# ################################################################# #


apollo_lcPars=function(apollo_beta, apollo_inputs){
  lcpars = list()
  
  lcpars[["b_cno"]] = list(b_cno_a, b_cno_b, b_cno_c)
  lcpars[["b_hall"]] = list( b_hall_a, b_hall_b, b_hall_c)
  lcpars[["b_castle"]] = list( b_castle_a, b_castle_b, b_castle_c) 
  lcpars[["b_eno"]] = list( b_eno_a, b_eno_b, b_eno_c)
  lcpars[["b_areaplay"]] = list( b_areaplay_a, b_areaplay_b, b_areaplay_c)
  lcpars[["b_eventschild"]] = list( b_eventschild_a, b_eventschild_b, b_eventschild_c) 
  lcpars[["b_sno"]] = list( b_sno_a, b_sno_b, b_sno_c)
  lcpars[["b_educadults"]] = list( b_educadults_a, b_educadults_b, b_educadults_c)
  lcpars[["b_social"]] = list( b_social_a, b_social_b, b_social_c)
  lcpars[["b_price"]] = list( b_price_a, b_price_b, b_price_c)
  
  
  
  ### Utilities of class allocation model
  
  V=list()
  V[["class_a"]] = (b_delta_a
                    + gamma_englishheritage_a * (( q5 == 1) *1
                                                 + (q5 == 2) * 0)
                    + gamma_highincome_a * (  ( ( income ==1) 
                                                + (income ==2) 
                                                +( income == 3) 
                                                + (income == 4) *1
                                                + (income == 5) * 1 )  )
                    +gamma_children_a *(( children == 1) *1
                                        + (children == 2) * 0)
                    +  gamma_highereducation_a  *
                      (((education == 4) * 0)
                       + ((education == 3)  )
                       +((education == 2) *1)
                       +((education == 1) *1))
                    
                    + gamma_heritage_very_future_a * ((q4 == 1) *1
                                                      +(q4 == 2) * 0
                                                      +(q4 == 3) )
                    
                    + gamma_heritage_visit_a * ((q2 == 1) * 0
                                                +(q2 == 2) * 0
                                                +(q2 == 3) *1)
                    
  )
  
  V[["class_b"]] = (b_delta_b
                    + gamma_englishheritage_b * (( q5 == 1) *1
                                                 + (q5 == 2) * 0)
                    + gamma_highincome_b * (  ( ( income ==1) 
                                                + (income ==2) 
                                                +( income == 3) 
                                                + (income == 4) *1
                                                + (income == 5) * 1 )  )
                    +gamma_children_b *(( children == 1) *1
                                        + (children == 2) * 0)
                    +  gamma_highereducation_b  *
                      (((education == 4) * 0)
                       + ((education == 3)  )
                       +((education == 2) *1)
                       +((education == 1) *1))
                    
                    + gamma_heritage_very_future_b * ((q4 == 1) *1
                                                      +(q4 == 2) * 0
                                                      +(q4 == 3) )
                    + gamma_heritage_visit_b * ((q2 == 1) * 0
                                                +(q2 == 2) * 0
                                                +(q2 == 3) *1)
                    
                    
                    
  )
  
  
  V[["class_c"]] = (b_delta_c
                    + gamma_englishheritage_c * (( q5 == 1) *1
                                                 + (q5 == 2) * 0) 
                    
                    + gamma_highincome_c * (   ( ( income ==1) 
                                                 + (income ==2) 
                                                 +( income == 3) 
                                                 + (income == 4) *1
                                                 + (income == 5) * 1 )  ) 
                    
                    +   gamma_children_c *(( children == 1) *1
                                           + (children == 2) * 0) 
                    
                    + gamma_highereducation_c  *
                      (((education == 4) * 0)
                       + ((education == 3)  )
                       +((education == 2) *1)
                       +((education == 1) *1))
                    
                    + gamma_heritage_very_future_c * ((q4 == 1) *1
                                                      +(q4 == 2) * 0
                                                      +(q4 == 3) )
                    + gamma_heritage_visit_c * ((q2 == 1) * 0
                                                +(q2 == 2) * 0
                                                +(q2 == 3) *1)
                    
                    
  )
  
  
                     classAlloc_settings = list(
                       classes      = c(class_a=1, class_b=2, class_c=3), 
                       utilities    = V  
  )
  
  
  
  
  
  lcpars[["pi_values"]] = apollo_classAlloc(classAlloc_settings)
                     
  
  return(lcpars)
  
  
}

# ################################################################# #
#### GROUP AND VALIDATE INPUTS                                   ####
# ################################################################# #

apollo_inputs = apollo_validateInputs()

# ################################################################# #
#### DEFINE MODEL AND LIKELIHOOD FUNCTION                        ####
# ################################################################# #

apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){
  
  ### Attach inputs and detach after function exit
  apollo_attach(apollo_beta, apollo_inputs)
  on.exit(apollo_detach(apollo_beta, apollo_inputs))
  
  ### Create list of probabilities P
  P = list()
  
  
  
  ### Loop over classes
  for(s in 1:3){
    
    ### Compute class-specific utilities
    V = list()
    V[['A']]  = (
      b_cno[[s]]     * ( a1_x1 == 1)    
      + b_hall[[s]]  * ( a1_x1 == 2)
      + b_castle[[s]]       * ( a1_x1 == 3)        
      + b_eno[[s]]       * ( a1_x2 == 1)       
      + b_areaplay[[s]]   * ( a1_x2 == 2)   
      + b_eventschild[[s]]      * ( a1_x2 == 3)      
      + b_sno[[s]]      * ( a1_x3 == 1)
      + b_educadults[[s]]        * ( a1_x3 == 2)
      + b_social[[s]]       * ( a1_x3 == 3)
      + b_price[[s]]                * ( ( a1_x4 == 1) * 2
                                        +( a1_x4 == 2) * 4
                                        +( a1_x4 == 3) * 6
                                        +( a1_x4 == 4) * 8
                                        +( a1_x4 ==5)  * 10
                                        +( a1_x4 ==6)  * 12 ))
    
    V[['B']]  = ( 
      b_cno[[s]]     *   ( a2_x1 == 1)    
      + b_hall[[s]]  *  ( a2_x1 == 2)
      + b_castle[[s]]  * ( a2_x1 == 3)        
      + b_eno[[s]]   * ( a2_x2 == 1)       
      + b_areaplay[[s]]   * ( a2_x2 == 2)   
      + b_eventschild[[s]]       * ( a2_x2 == 3)      
      + b_sno[[s]]         * ( a2_x3 == 1)
      + b_educadults[[s]]        * ( a2_x3 == 2)
      + b_social[[s]]        * ( a2_x3 == 3)
      + b_price[[s]]          * ( ( a2_x4 == 1) *2
                                  + ( a2_x4==2) *4
                                  + (a2_x4==3)  *6
                                  + (a2_x4==4)  *8
                                  + (a2_x4==5)  *10
                                  + (a2_x4==6)  *12 ))
    
    V[['C']]  = ( 
      b_cno[[s]]     *   ( a3_x1 == 1)    
      + b_eno[[s]]   * ( a3_x2 == 1)      
      + b_sno[[s]]         * ( a3_x3 == 1)
      + b_price[[s]]          *  ( a3_x4 == 1) )
    
    ### Define settings for MNL model component that are generic across classes
    mnl_settings = list(
      alternatives  = c(A=1,B=2, C=3),
      choiceVar     = pref1
      
    )
    
    
    mnl_settings$utilities = V
    mnl_settings$componentName = paste0("Class_",s)
    
    ### Compute within-class choice probabilities using MNL model
    P[[paste0("Class_",s)]] = apollo_mnl(mnl_settings, functionality)
    
    ### Take product across observation for same individual
    P[[paste0("Class_",s)]] = apollo_panelProd(P[[paste0("Class_",s)]], apollo_inputs ,functionality)
    
    ### Average across inter-individual draws within classes
    P[[paste0("Class_",s)]] = apollo_avgInterDraws(P[[paste0("Class_",s)]], apollo_inputs, functionality)
  }
  
  ### Compute latent class model probabilities
  lc_settings  = list(inClassProb = P, classProb=pi_values)
  P[["model"]] = apollo_lc(lc_settings, apollo_inputs, functionality)
  
  ### Average across inter-individual draws in class allocation probabilities
  P[["model"]] = apollo_avgInterDraws(P[["model"]], apollo_inputs, functionality)
  
  ### Prepare and return outputs of function
  P = apollo_prepareProb(P, apollo_inputs, functionality)
  return(P)
}


# ################################################################# #
#### MODEL ESTIMATION AND OUTPUT                                 ####
# ################################################################# #

### Estimate model
model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs, estimate_settings=list(maxIterations=2000))

### Show output in screen
apollo_modelOutput(model)

### Save output to file(s)
apollo_saveOutput(model)
Again, apologies for the confusion.

Thanks again
Tom
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: Error in Mixed Latent Class model

Post by stephanehess »

Tom

if you look at your estimates, it's clear that the model has converged to a solution with very extreme values, likely causing your problems. Can you show us the model results for 1, 2 and 3 class models next to each other (use apollo_combineResults)

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
TomC
Posts: 4
Joined: 21 Mar 2022, 09:18

Re: Error in Mixed Latent Class model

Post by TomC »

Hi Stephane,

Again thanks for the help.

I've re ran the two class model and found the same issues exists, it appears more luck then anything that I thought this one worked ( I ran with 50 MLHS draws, if I increase the amount of draws we run into extreme numbers and NA).

This is the two class model.

Code: Select all

# ################################################################# #
#### LOAD LIBRARY AND DEFINE CORE SETTINGS                       ####
# ################################################################# #

### Clear memory
rm(list = ls())

### Load Apollo library
library(apollo)

### Initialise code
apollo_initialise()

### Set core controls
apollo_control = list(
  modelName       = "Visit MM-MNL Test6 mlhs",
  modelDescr      = "Visit Simple LC model on Belsay Hall, no covariates in class allocation model",
  indivID         = "RID",
  mixing = TRUE,
  nCores          = 6,
  outputDirectory = "output"
)

# ################################################################# #
#### LOAD DATA AND APPLY ANY TRANSFORMATIONS                     ####
# ################################################################# #

### Loading data from package

database = read.csv("~/Visitor_demo.csv", header=TRUE)
choiceAnalysis_settings <- list(
  alternatives = c(a1=1, a2=2, a3=3),
  avail        = list(a1=database$a1_x1, a2=database$a2_x1, a3=database$a3_x1),
  choiceVar    = database$pref1)


# ################################################################# #
#### DEFINE MODEL PARAMETERS                                     ####
# ################################################################# #

### Vector of parameters, including any that are kept fixed in estimation
apollo_beta = c(
  mu_log_b_areaplay_a           = 0,
  mu_log_b_areaplay_b           = 0,
  mu_log_b_castle_a = 0 ,
  mu_log_b_castle_b = 0 ,
  mu_log_b_cno_a          = 0,
  mu_log_b_cno_b          = 0,
  mu_log_b_educadults_a      = 0,
  mu_log_b_educadults_b      = 0,
  mu_log_b_eno_a             = 0,
  mu_log_b_eno_b             = 0,
  mu_log_b_eventschild_a    = 0,
  mu_log_b_eventschild_b    = 0,
  mu_log_b_hall_a        = 0,
  mu_log_b_hall_b        = 0,
  mu_log_b_price_a                    = 0,
  mu_log_b_price_b                    = 0,
  mu_log_b_sno_a              = 0,
  mu_log_b_sno_b              = 0,
  mu_log_b_social_a          = 0,
  mu_log_b_social_b          = 0,
  
  sigma_log_b_areaplay_a           = 0,
  sigma_log_b_areaplay_b           = 0,
  sigma_log_b_castle_a = 0 ,
  sigma_log_b_castle_b = 0 ,
  sigma_log_b_cno_a          = 0,
  sigma_log_b_cno_b          = 0,
  sigma_log_b_educadults_a      = 0,
  sigma_log_b_educadults_b      = 0,
  sigma_log_b_eno_a             = 0,
  sigma_log_b_eno_b             = 0,
  sigma_log_b_eventschild_a    = 0,
  sigma_log_b_eventschild_b    = 0,
  sigma_log_b_hall_a        = 0,
  sigma_log_b_hall_b        = 0,
  sigma_log_b_price_a                    = 0,
  sigma_log_b_price_b                    = 0,
  sigma_log_b_sno_a              = 0,
  sigma_log_b_sno_b              = 0,
  sigma_log_b_social_a          = 0,
  sigma_log_b_social_b          = 0,
  
  gamma_englishheritage_a =0,
  gamma_englishheritage_b =0,
  
  gamma_highincome_a =0,
  gamma_highincome_b=0, 
  
  gamma_children_a =0,
  gamma_children_b =0, 
  
  gamma_highereducation_a  =0,
  gamma_highereducation_b  =0,
  

  
  gamma_heritage_very_future_a = 0,
  gamma_heritage_very_future_b = 0,

  gamma_heritage_visit_a = 0,
  gamma_heritage_visit_b = 0,

  
  
  delta_a   = 0,
  b_delta_b   = 0,
  sigma_delta_a   = 0
)

### Vector with names (in quotes) of parameters to be kept fixed at their starting value in apollo_beta, use apollo_beta_fixed = c() if none
apollo_fixed = c("b_delta_b", "mu_log_b_cno_a", "mu_log_b_cno_b", "mu_log_b_eno_a", "mu_log_b_eno_b", "mu_log_b_sno_a", "mu_log_b_sno_b", 
                 "gamma_children_b", "gamma_englishheritage_b", "gamma_highincome_b", "gamma_highereducation_b",
                 "gamma_heritage_very_future_b", "gamma_heritage_visit_b")


### Set parameters for generating draws
apollo_draws = list(
  interDrawsType = "mlhs",
  interNDraws    = 100,
  interUnifDraws = c(),
  interNormDraws = c(
                     "draws_educadults_a", "draws_social_a", "draws_price_a", "draws_cno_a","draws_hall_a","draws_castle_a","draws_eno_a", "draws_areaplay_a", "draws_eventschild_a", "draws_sno_a",
                     "draws_educadults_b", "draws_social_b", "draws_price_b", "draws_cno_b","draws_hall_b","draws_castle_b","draws_eno_b", "draws_areaplay_b", "draws_eventschild_b", "draws_sno_b",
                     "draws_delta_a", "draws_delta_b"),
  intraDrawsType = "pmc",
  intraNDraws    = 0,
  intraUnifDraws = c(),
  intraNormDraws = c()
)


###Random coeffecients##

apollo_randCoeff = function(apollo_beta, apollo_inputs){
  randcoeff = list()
  
  randcoeff[["b_cno_a"]] = ( mu_log_b_cno_a + sigma_log_b_cno_a * draws_cno_a)
  randcoeff[["b_hall_a"]] = ( mu_log_b_hall_a + sigma_log_b_hall_a * draws_hall_a)
  randcoeff[["b_castle_a"]] = ( mu_log_b_castle_a + sigma_log_b_castle_a * draws_castle_a)
  randcoeff[["b_eno_a"]] = ( mu_log_b_eno_a + sigma_log_b_eno_a * draws_eno_a)
  randcoeff[["b_areaplay_a"]] = ( mu_log_b_areaplay_a + sigma_log_b_areaplay_a * draws_areaplay_a)
  randcoeff[["b_eventschild_a"]] = ( mu_log_b_eventschild_a + sigma_log_b_eventschild_a * draws_eventschild_a)
  randcoeff[["b_sno_a"]] = ( mu_log_b_sno_a + sigma_log_b_sno_a* draws_sno_a)
  randcoeff[["b_educadults_a"]] = ( mu_log_b_educadults_a + sigma_log_b_educadults_a * draws_educadults_a)
  randcoeff[["b_social_a"]] = ( mu_log_b_social_a + sigma_log_b_social_a * draws_social_a)
  randcoeff[["b_price_a"]] = ( mu_log_b_price_a + sigma_log_b_price_a * draws_price_a)
  randcoeff[["b_delta_a"]] = ( delta_a + sigma_delta_a * draws_delta_a)
  
  
  
  randcoeff[["b_cno_b"]] = ( mu_log_b_cno_b + sigma_log_b_cno_b * draws_cno_b)
  randcoeff[["b_hall_b"]] = ( mu_log_b_hall_b + sigma_log_b_hall_b * draws_hall_b)
  randcoeff[["b_castle_b"]] = ( mu_log_b_castle_b + sigma_log_b_castle_b * draws_castle_b)
  randcoeff[["b_eno_b"]] = ( mu_log_b_eno_b + sigma_log_b_eno_b * draws_eno_b)
  randcoeff[["b_areaplay_b"]] = ( mu_log_b_areaplay_b + sigma_log_b_areaplay_b * draws_areaplay_b)
  randcoeff[["b_eventschild_b"]] = ( mu_log_b_eventschild_b + sigma_log_b_eventschild_b * draws_eventschild_b)
  randcoeff[["b_sno_b"]] = ( mu_log_b_sno_b + sigma_log_b_sno_b * draws_sno_b)
  randcoeff[["b_educadults_b"]] = ( mu_log_b_educadults_b + sigma_log_b_educadults_b * draws_educadults_b)
  randcoeff[["b_social_b"]] = ( mu_log_b_social_b + sigma_log_b_social_b * draws_social_b)
  randcoeff[["b_price_b"]] = ( mu_log_b_price_b + sigma_log_b_price_b * draws_price_b)

  
  return(randcoeff)
}

# ################################################################# #
#### DEFINE LATENT CLASS COMPONENTS                              ####
# ################################################################# #


apollo_lcPars=function(apollo_beta, apollo_inputs){
  lcpars = list()
  
  lcpars[["b_cno"]] = list(b_cno_a, b_cno_b)
  lcpars[["b_hall"]] = list( b_hall_a, b_hall_b)
  lcpars[["b_castle"]] = list( b_castle_a, b_castle_b) 
  lcpars[["b_eno"]] = list( b_eno_a, b_eno_b)
  lcpars[["b_areaplay"]] = list( b_areaplay_a, b_areaplay_b)
  lcpars[["b_eventschild"]] = list( b_eventschild_a, b_eventschild_b) 
  lcpars[["b_sno"]] = list( b_sno_a, b_sno_b)
  lcpars[["b_educadults"]] = list( b_educadults_a, b_educadults_b)
  lcpars[["b_social"]] = list( b_social_a, b_social_b)
  lcpars[["b_price"]] = list( b_price_a, b_price_b)
  
  
  
  ### Utilities of class allocation model
  
  
  V=list()
  V[["class_a"]] = (b_delta_a
                    + gamma_englishheritage_a * (( q5 == 1) *1
                                                 + (q5 == 2) * 0)
                    + gamma_highincome_a * (  ( ( income ==1) *0
                                                + (income ==2) *0
                                                +( income == 3) *0
                                                + (income == 4) *1
                                                + (income == 5) * 1 )  )
                    +gamma_children_a *(( children == 1) *1
                                        + (children == 2) * 0)
                    +  gamma_highereducation_a  *
                      (((education == 4) * 0)
                       + ((education == 3) *0 )
                       +((education == 2) *1)
                       +((education == 1) *1))
                    
                    + gamma_heritage_very_future_a * ((q4 == 1) *1
                                                      +(q4 == 2) * 0
                                                      +(q4 == 3) *0)
                    
                    + gamma_heritage_visit_a * ((q2 == 1) * 0
                                                +(q2 == 2) * 0
                                                +(q2 == 3) *1)
                    
  )
  
  V[["class_b"]] = (b_delta_b
                    + gamma_englishheritage_b * (( q5 == 1) *1
                                                 + (q5 == 2) * 0)
                    + gamma_highincome_b * (  ( ( income ==1) *0
                                                + (income ==2) *0
                                                +( income == 3) *0
                                                + (income == 4) *1
                                                + (income == 5) * 1 )  )
                    +gamma_children_b *(( children == 1) *1
                                        + (children == 2) * 0)
                    +  gamma_highereducation_b  *
                      (((education == 4) * 0)
                       + ((education == 3) *0 )
                       +((education == 2) *1)
                       +((education == 1) *1))
                    
                    + gamma_heritage_very_future_b * ((q4 == 1) *1
                                                      +(q4 == 2) * 0
                                                      +(q4 == 3) *0)
                    + gamma_heritage_visit_b * ((q2 == 1) * 0
                                                +(q2 == 2) * 0
                                                +(q2 == 3) *1)
                    
                    
  )
  
  
  classAlloc_settings = list(
    classes      = c(class_a=1, class_b=2), 
    utilities    = V  
  )
  
  
  
  
  
  lcpars[["pi_values"]] = apollo_classAlloc(classAlloc_settings)
  
  
  
  
  return(lcpars)
  
  
}

# ################################################################# #
#### GROUP AND VALIDATE INPUTS                                   ####
# ################################################################# #

apollo_inputs = apollo_validateInputs()

# ################################################################# #
#### DEFINE MODEL AND LIKELIHOOD FUNCTION                        ####
# ################################################################# #

apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){
  
  ### Attach inputs and detach after function exit
  apollo_attach(apollo_beta, apollo_inputs)
  on.exit(apollo_detach(apollo_beta, apollo_inputs))
  
  ### Create list of probabilities P
  P = list()
  
  ### Define settings for MNL model component that are generic across classes
  mnl_settings = list(
    alternatives  = c(A=1,B=2, C=3),
    choiceVar     = pref1
  )
    
  
  ### Loop over classes
  for(s in 1:2){
    
    ### Compute class-specific utilities
    V = list()
    V[['A']]  = (
      b_cno[[s]]     * ( a1_x1 == 1)    
      + b_hall[[s]]  * ( a1_x1 == 2)
      + b_castle[[s]]       * ( a1_x1 == 3)        
      + b_eno[[s]]       * ( a1_x2 == 1)       
      + b_areaplay[[s]]   * ( a1_x2 == 2)   
      + b_eventschild[[s]]      * ( a1_x2 == 3)      
      + b_sno[[s]]      * ( a1_x3 == 1)
      + b_educadults[[s]]        * ( a1_x3 == 2)
      + b_social[[s]]       * ( a1_x3 == 3)
      + b_price[[s]]                * ( ( a1_x4 == 1) * 2
                                        +( a1_x4 == 2) * 4
                                        +( a1_x4 == 3) * 6
                                        +( a1_x4 == 4) * 8
                                        +( a1_x4 ==5)  * 10
                                        +( a1_x4 ==6)  * 12 ))
    
    V[['B']]  = ( 
      b_cno[[s]]     *   ( a2_x1 == 1)    
      + b_hall[[s]]  *  ( a2_x1 == 2)
      + b_castle[[s]]  * ( a2_x1 == 3)        
      + b_eno[[s]]   * ( a2_x2 == 1)       
      + b_areaplay[[s]]   * ( a2_x2 == 2)   
      + b_eventschild[[s]]       * ( a2_x2 == 3)      
      + b_sno[[s]]         * ( a2_x3 == 1)
      + b_educadults[[s]]        * ( a2_x3 == 2)
      + b_social[[s]]        * ( a2_x3 == 3)
      + b_price[[s]]          * ( ( a2_x4 == 1) *2
                                  + ( a2_x4==2) *4
                                  + (a2_x4==3)  *6
                                  + (a2_x4==4)  *8
                                  + (a2_x4==5)  *10
                                  + (a2_x4==6)  *12 ))
    
    V[['C']]  = ( 
      b_cno[[s]]     *   ( a3_x1 == 1)    
      + b_eno[[s]]   * ( a3_x2 == 1)      
      + b_sno[[s]]         * ( a3_x3 == 1)
      + b_price[[s]]          *  ( a3_x4 == 1) *0)
    


    
    
    mnl_settings$utilities = V
    mnl_settings$componentName = paste0("Class_",s)
    
    ### Compute within-class choice probabilities using MNL model
    P[[paste0("Class_",s)]] = apollo_mnl(mnl_settings, functionality)
    
    ### Take product across observation for same individual
    P[[paste0("Class_",s)]] = apollo_panelProd(P[[paste0("Class_",s)]], apollo_inputs ,functionality)
    
    ### Average across inter-individual draws within classes
    P[[paste0("Class_",s)]] = apollo_avgInterDraws(P[[paste0("Class_",s)]], apollo_inputs, functionality)
  }
  
  ### Compute latent class model probabilities
  lc_settings  = list(inClassProb = P, classProb=pi_values)
  P[["model"]] = apollo_lc(lc_settings, apollo_inputs, functionality)
  
  ### Average across inter-individual draws in class allocation probabilities
  P[["model"]] = apollo_avgInterDraws(P[["model"]], apollo_inputs, functionality)
  
  ### Prepare and return outputs of function
  P = apollo_prepareProb(P, apollo_inputs, functionality)
  return(P)
}


# ################################################################# #
#### MODEL ESTIMATION AND OUTPUT                                 ####
# ################################################################# #

### Estimate model
model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs, estimate_settings=list(maxIterations=2000))

### Show output in screen
apollo_modelOutput(model)

### Save output to file(s)
apollo_saveOutput(model)




These are the results with 50 MLHS

Code: Select all

Model run by TColwill using Apollo 0.2.7 on R 4.1.2 for Windows.
www.ApolloChoiceModelling.com

Model name                       : Visit MM-MNL Test1 MLHS
Model description                : Visit Simple LC model on Belsay Hall, no covariates in class allocation model
Model run at                     : 2022-03-15 15:22:26
Estimation method                : bfgs
Model diagnosis                  : successful convergence 
Number of individuals            : 190
Number of rows in database       : 1140
Number of modelled outcomes      : 1140

Number of cores used             :  6 
Number of inter-individual draws : 50 (mlhs)

LL(start)                        : -1252.42
LL(0, whole model)               : -1252.42
LL(C, whole model)               : -1211.06
LL(final, whole model)           : -925.94
Rho-square (0)                   :  0.2607 
Adj.Rho-square (0)               :  0.2271 
Rho-square (C)                   :  0.2354 
Adj.Rho-square (C)               :  0.2008 
AIC                              :  1935.87 
BIC                              :  2147.5 

LL(0,Class_1)                    : -1252.42
LL(final,Class_1)                : -1145.37
LL(0,Class_2)                    : -1252.42
LL(final,Class_2)                : -1200.81

Estimated parameters             :  42
Time taken (hh:mm:ss)            :  00:14:11.34 
     pre-estimation              :  00:00:25.11 
     estimation                  :  00:08:18.67 
     post-estimation             :  00:05:27.55 
Iterations                       :  121  
Min abs eigenvalue of Hessian    :  0.00023 

Unconstrained optimisation.

Estimates:
                                Estimate        s.e.   t.rat.(0)    Rob.s.e. Rob.t.rat.(0)
mu_log_b_areaplay_a             -0.07023     0.28605    -0.24552     0.29959      -0.23442
mu_log_b_areaplay_b              3.70570     0.83190     4.45449     0.92359       4.01230
mu_log_b_castle_a                0.08943     0.25563     0.34985     0.28117       0.31807
mu_log_b_castle_b                6.67855     1.08660     6.14626     1.13037       5.90830
mu_log_b_cno_a                   0.00000          NA          NA          NA            NA
mu_log_b_cno_b                   0.00000          NA          NA          NA            NA
mu_log_b_educadults_a            0.07576     0.18753     0.40400     0.17368       0.43622
mu_log_b_educadults_b            1.13845     0.43147     2.63854     0.44907       2.53511
mu_log_b_eno_a                   0.00000          NA          NA          NA            NA
mu_log_b_eno_b                   0.00000          NA          NA          NA            NA
mu_log_b_eventschild_a          -0.33044     0.23966    -1.37879     0.23917      -1.38160
mu_log_b_eventschild_b           2.97330     0.65491     4.53998     0.79752       3.72819
mu_log_b_hall_a                  0.17836     0.22873     0.77976     0.25542       0.69829
mu_log_b_hall_b                  5.59050     0.94967     5.88676     0.94533       5.91378
mu_log_b_price_a                -0.05608     0.02535    -2.21182     0.03043      -1.84277
mu_log_b_price_b                -0.21367     0.05633    -3.79296     0.06117      -3.49283
mu_log_b_sno_a                   0.00000          NA          NA          NA            NA
mu_log_b_sno_b                   0.00000          NA          NA          NA            NA
mu_log_b_social_a                0.01442     0.21231     0.06790     0.20891       0.06901
mu_log_b_social_b                1.20419     0.45183     2.66513     0.42097       2.86053
sigma_log_b_areaplay_a           0.04581     0.73473     0.06235     0.67325       0.06805
sigma_log_b_areaplay_b           2.26372     0.67456     3.35586     0.55980       4.04378
sigma_log_b_castle_a             0.91851     0.38867     2.36320     0.44007       2.08719
sigma_log_b_castle_b            -1.80340     0.57452    -3.13899     0.61558      -2.92961
sigma_log_b_cno_a                0.42954     0.39218     1.09527     0.44212       0.97154
sigma_log_b_cno_b                3.19565     0.65512     4.87794     0.63275       5.05040
sigma_log_b_educadults_a         0.18111     0.35091     0.51612     0.23224       0.77985
sigma_log_b_educadults_b        -1.06507     0.41744    -2.55144     0.38618      -2.75794
sigma_log_b_eno_a                1.01997     0.25128     4.05910     0.27036       3.77269
sigma_log_b_eno_b               -3.51324     0.62675    -5.60551     0.68721      -5.11230
sigma_log_b_eventschild_a       -0.41918     0.32549    -1.28785     0.24192      -1.73272
sigma_log_b_eventschild_b        1.33105     0.75989     1.75163     0.87873       1.51475
sigma_log_b_hall_a              -0.49222     0.47040    -1.04638     0.47525      -1.03570
sigma_log_b_hall_b               1.26491     0.58092     2.17741     0.63566       1.98990
sigma_log_b_price_a              0.05523     0.03025     1.82569     0.03048       1.81183
sigma_log_b_price_b              0.35501     0.06620     5.36291     0.07327       4.84502
sigma_log_b_sno_a                0.21267     0.31055     0.68483     0.28906       0.73574
sigma_log_b_sno_b                3.30163     0.63959     5.16211     0.67533       4.88887
sigma_log_b_social_a             0.75352     0.32162     2.34291     0.36751       2.05037
sigma_log_b_social_b             0.92948     0.37617     2.47093     0.32482       2.86150
gamma_englishheritage_a          0.83478     3.23759     0.25784     2.36877       0.35241
gamma_englishheritage_b          0.00000          NA          NA          NA            NA
gamma_highincome_a              -1.39030     4.63664    -0.29985     1.96120      -0.70890
gamma_highincome_b               0.00000          NA          NA          NA            NA
gamma_children_a                 8.49528    28.33980     0.29976    15.73155       0.54002
gamma_children_b                 0.00000          NA          NA          NA            NA
gamma_highereducation_a         11.24647    38.50350     0.29209    22.99763       0.48903
gamma_highereducation_b          0.00000          NA          NA          NA            NA
gamma_heritage_very_future_a    -4.47494    15.29601    -0.29256     8.73105      -0.51253
gamma_heritage_very_future_b     0.00000          NA          NA          NA            NA
gamma_heritage_visit_a          -5.69213    19.66741    -0.28942    12.45869      -0.45688
gamma_heritage_visit_b           0.00000          NA          NA          NA            NA
delta_a                        -10.52711    35.53782    -0.29622    20.56933      -0.51179
b_delta_b                        0.00000          NA          NA          NA            NA
sigma_delta_a                   -2.29284    12.30663    -0.18631     7.64549      -0.29989


Summary of class allocation for LC model component :
         Mean prob.
Class_1      0.3622
Class_2      0.6378


Overview of choices for MNL model component Class_1:
                                       A       B       C
Times available                  1140.00 1140.00 1140.00
Times chosen                      431.00  467.00  242.00
Percentage chosen overall          37.81   40.96   21.23
Percentage chosen when available   37.81   40.96   21.23


Overview of choices for MNL model component Class_2:
                                       A       B       C
Times available                  1140.00 1140.00 1140.00
Times chosen                      431.00  467.00  242.00
Percentage chosen overall          37.81   40.96   21.23
Percentage chosen when available   37.81   40.96   21.23

however when increasing it to 500 MLHS

Code: Select all


Model name                       : Visit MM-MNL Test3 mlhs
Model description                : Visit Simple LC model on Belsay Hall, no covariates in class allocation model
Model run at                     : 2022-03-25 11:24:29
Estimation method                : bfgs
Model diagnosis                  : successful convergence 
Number of individuals            : 190
Number of rows in database       : 1140
Number of modelled outcomes      : 1140

Number of cores used             :  6 
Number of inter-individual draws : 500 (mlhs)

LL(start)                        : -1252.42
LL(0, whole model)               : -1252.42
LL(C, whole model)               : -1211.06
LL(final, whole model)           : -970.74
Rho-square (0)                   :  0.2249 
Adj.Rho-square (0)               :  0.1914 
Rho-square (C)                   :  0.1984 
Adj.Rho-square (C)               :  0.1638 
AIC                              :  2025.49 
BIC                              :  2237.12 

LL(0,Class_1)                    : -1252.42
LL(final,Class_1)                : -Inf Likelihood equal to zero for at least
                                        one individual in this component.
LL(0,Class_2)                    : -1252.42
LL(final,Class_2)                : -996.67

Estimated parameters             :  42
Time taken (hh:mm:ss)            :  00:32:53.76 
     pre-estimation              :  00:02:30.87 
     estimation                  :  00:19:29 
     post-estimation             :  00:10:53.89 
Iterations                       :  290  

Unconstrained optimisation.

Estimates:
                                Estimate        s.e.   t.rat.(0)    Rob.s.e. Rob.t.rat.(0)
mu_log_b_areaplay_a            9.947e+04          NA          NA          NA            NA
mu_log_b_areaplay_b              0.84966          NA          NA          NA            NA
mu_log_b_castle_a              9.144e+04          NA          NA          NA            NA
mu_log_b_castle_b                2.24779          NA          NA          NA            NA
mu_log_b_cno_a                   0.00000          NA          NA          NA            NA
mu_log_b_cno_b                   0.00000          NA          NA          NA            NA
mu_log_b_educadults_a         -1.883e+05          NA          NA          NA            NA
mu_log_b_educadults_b            0.63589          NA          NA          NA            NA
mu_log_b_eno_a                   0.00000          NA          NA          NA            NA
mu_log_b_eno_b                   0.00000          NA          NA          NA            NA
mu_log_b_eventschild_a         5.607e+04          NA          NA          NA            NA
mu_log_b_eventschild_b           0.79038          NA          NA          NA            NA
mu_log_b_hall_a                2.873e+05          NA          NA          NA            NA
mu_log_b_hall_b                  1.62770          NA          NA          NA            NA
mu_log_b_price_a              -1.036e+04          NA          NA          NA            NA
mu_log_b_price_b                -0.10438          NA          NA          NA            NA
mu_log_b_sno_a                   0.00000          NA          NA          NA            NA
mu_log_b_sno_b                   0.00000          NA          NA          NA            NA
mu_log_b_social_a              1.661e+04          NA          NA          NA            NA
mu_log_b_social_b                0.33946          NA          NA          NA            NA
sigma_log_b_areaplay_a        -3.914e+04          NA          NA          NA            NA
sigma_log_b_areaplay_b           0.08193          NA          NA          NA            NA
sigma_log_b_castle_a          -5.844e+05          NA          NA          NA            NA
sigma_log_b_castle_b            -0.07012          NA          NA          NA            NA
sigma_log_b_cno_a              3.386e+04          NA          NA          NA            NA
sigma_log_b_cno_b               -2.14329          NA          NA          NA            NA
sigma_log_b_educadults_a       1.231e+04          NA          NA          NA            NA
sigma_log_b_educadults_b         0.08903          NA          NA          NA            NA
sigma_log_b_eno_a              1.218e+05          NA          NA          NA            NA
sigma_log_b_eno_b                1.77717          NA          NA          NA            NA
sigma_log_b_eventschild_a     -1.454e+05          NA          NA          NA            NA
sigma_log_b_eventschild_b       -0.11660          NA          NA          NA            NA
sigma_log_b_hall_a           -1517.00630          NA          NA          NA            NA
sigma_log_b_hall_b               0.50816          NA          NA          NA            NA
sigma_log_b_price_a           -4.448e+04          NA          NA          NA            NA
sigma_log_b_price_b             -0.13519          NA          NA          NA            NA
sigma_log_b_sno_a              6.413e+04          NA          NA          NA            NA
sigma_log_b_sno_b               -1.13241          NA          NA          NA            NA
sigma_log_b_social_a          -1.748e+04          NA          NA          NA            NA
sigma_log_b_social_b             0.51120          NA          NA          NA            NA
gamma_englishheritage_a      -5594.31476          NA          NA          NA            NA
gamma_englishheritage_b          0.00000          NA          NA          NA            NA
gamma_highincome_a            3553.00467          NA          NA          NA            NA
gamma_highincome_b               0.00000          NA          NA          NA            NA
gamma_children_a              -2.315e+04          NA          NA          NA            NA
gamma_children_b                 0.00000          NA          NA          NA            NA
gamma_highereducation_a        1.490e+04          NA          NA          NA            NA
gamma_highereducation_b          0.00000          NA          NA          NA            NA
gamma_heritage_very_future_a -6420.00489          NA          NA          NA            NA
gamma_heritage_very_future_b     0.00000          NA          NA          NA            NA
gamma_heritage_visit_a        -2.693e+04          NA          NA          NA            NA
gamma_heritage_visit_b           0.00000          NA          NA          NA            NA
delta_a                      -3987.89626          NA          NA          NA            NA
b_delta_b                        0.00000          NA          NA          NA            NA
sigma_delta_a                  1.962e+04          NA          NA          NA            NA


Summary of class allocation for LC model component :
         Mean prob.
Class_1    0.005024
Class_2    0.994976


Overview of choices for MNL model component Class_1:
                                       A       B       C
Times available                  1140.00 1140.00 1140.00
Times chosen                      431.00  467.00  242.00
Percentage chosen overall          37.81   40.96   21.23
Percentage chosen when available   37.81   40.96   21.23


Overview of choices for MNL model component Class_2:
                                       A       B       C
Times available                  1140.00 1140.00 1140.00
Times chosen                      431.00  467.00  242.00
Percentage chosen overall          37.81   40.96   21.23
Percentage chosen when available   37.81   40.96   21.23

Apologies for question, but would a 1 class model be in effect a MIXL model? I can't seem to find an example of this within the latent class literature, on how this would work, I've attempted by reducing the classes however I get the error

Model component "classAlloc" requires at least 2 classes

Again thanks for all your help.

Thanks
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: Error in Mixed Latent Class model

Post by stephanehess »

Hi

yes, a single class model would just be a MMNL model in this case

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
TomC
Posts: 4
Joined: 21 Mar 2022, 09:18

Re: Error in Mixed Latent Class model

Post by TomC »

Hi Stephane,

Thanks again for your reply.

Here is the Appolo combine of these three models ran with 200 MLHS, PMC draws also give very similar results.

I've renamed the MMNL model to share the same names as the latent classes (_a)

Code: Select all


Model name	 MM_MNL_1_class		 MM_MNL_2_class		 MM_MNL_3_class 	
Model description	 MM_MNL_1_class		 MM_MNL_2_class		 MM_MNL_3_class	
Number of individuals	190		190		190	
Number of modelled outcomes	1140		1140		1140	
Estimated parameters	17		43		67	
LL(final)	-993.67		-915.93		-908.59	
Adj.Rho-square (0)	0.193		0.2343		0.221	
Adj.Rho-square (C)	0.1655		0.2082		0.1944	
AIC	2021.33		1917.87		1951.17	
BIC	2106.99		2134.54		2288.77	
						
	estimate	Rob.t-ratio(0)	estimate	Rob.t-ratio(0)	estimate	Rob.t-ratio(0)
mu_log_b_cno_a	0	NA	0	NA	0	NA
mu_log_b_hall_a	1.6549	5.92	1799.0359	0.12	38629.9307	NA
mu_log_b_castle_a	2.1499	7.64	1856.7025	0.12	-25543.1744	NA
mu_log_b_eno_a	0	NA	0	NA	0	NA
mu_log_b_areaplay_a	0.801	3.24	866.5481	0.12	-56441.2719	NA
mu_log_b_eventschild_a	0.6596	3.43	891.8456	0.12	57367.7187	NA
mu_log_b_sno_a	0	NA	0	NA	0	NA
mu_log_b_educadults_a	0.3746	2.24	366.0913	0.12	-76871.8208	NA
mu_log_b_social_a	0.2407	1.35	570.4097	0.12	686.3196	NA
mu_log_b_price_a	-0.1171	-5.03	-98.0522	-0.12	6389.7195	NA
sigma_log_b_castle_a	-1.3003	-3.94	-510.5955	-0.12	-176454.5333	NA
sigma_log_b_cno_a	1.9556	7.98	774.1104	0.12	-77219.0504	NA
sigma_log_b_hall_a	0.3788	0.6	329.341	0.12	-16579.8417	NA
sigma_log_b_eno_a	-1.6526	-6.49	585.7594	0.12	59787.8803	NA
sigma_log_b_areaplay_a	-0.1076	-0.32	599.3467	0.12	-3756.348	NA
sigma_log_b_eventschild_a	0.1446	0.4	1132.8744	0.12	-109665.313	NA
sigma_log_b_sno_a	-1.1586	-5.37	-1015.2727	-0.12	273781.0262	NA
sigma_log_b_educadults_a	-0.0972	-0.18	239.0043	0.13	16677.6384	NA
sigma_log_b_social_a	-0.2182	-0.29	552.9202	0.13	7761.9695	NA
sigma_log_b_price_a	0.1393	4.89	-94.2006	-0.12	799.1055	NA
mu_log_b_areaplay_b	NA	NA	-0.0552	-0.2	64842.5783	NA
mu_log_b_castle_b	NA	NA	0.3295	1.11	138144.9835	NA
mu_log_b_cno_b	NA	NA	0	NA	0	NA
mu_log_b_educadults_b	NA	NA	0.0577	0.34	14916.2692	NA
mu_log_b_eno_b	NA	NA	0	NA	0	NA
mu_log_b_eventschild_b	NA	NA	-0.1815	-0.86	30946.8742	NA
mu_log_b_hall_b	NA	NA	0.1661	0.62	93469.0796	NA
mu_log_b_price_b	NA	NA	-0.0637	-2.17	-9237.7354	NA
mu_log_b_sno_b	NA	NA	0	NA	0	NA
mu_log_b_social_b	NA	NA	-0.0516	-0.25	-9276.8553	NA
sigma_log_b_areaplay_b	NA	NA	0.1668	0.91	47158.3365	NA
sigma_log_b_castle_b	NA	NA	-0.9859	-2.81	9079.6879	NA
sigma_log_b_cno_b	NA	NA	0.3666	0.67	69759.9735	NA
sigma_log_b_educadults_b	NA	NA	-0.1888	-1.19	41774.0058	NA
sigma_log_b_eno_b	NA	NA	-1.1282	-4.46	-53481.1514	NA
sigma_log_b_eventschild_b	NA	NA	-0.0385	-0.31	-67457.5667	NA
sigma_log_b_hall_b	NA	NA	-0.6159	-1.64	-45214.9244	NA
sigma_log_b_price_b	NA	NA	-0.0621	-1.76	9263.4303	NA
sigma_log_b_sno_b	NA	NA	-0.0422	-0.34	49403.7393	NA
sigma_log_b_social_b	NA	NA	0.7123	1.77	-4128.3364	NA
gamma_englishheritage_a	NA	NA	0.1935	0.31	88838.5131	NA
gamma_englishheritage_b	NA	NA	0	NA	-176.6045	NA
gamma_highincome_a	NA	NA	0.5286	1.04	-68734.2853	NA
gamma_highincome_b	NA	NA	0	NA	108783.4303	NA
gamma_children_a	NA	NA	-2.9536	-3.47	-148461.3654	NA
gamma_children_b	NA	NA	0	NA	-125324.5211	NA
gamma_highereducation_a	NA	NA	-4.2393	-3.38	66531.1671	NA
gamma_highereducation_b	NA	NA	0	NA	-111928.4335	NA
gamma_heritage_very_future_a	NA	NA	1.3137	2.03	102514.5893	NA
gamma_heritage_very_future_b	NA	NA	0	NA	13928.966	NA
gamma_heritage_visit_a	NA	NA	2.2449	3.33	-9137.4766	NA
gamma_heritage_visit_b	NA	NA	0	NA	10579.4219	NA
delta_a	NA	NA	3.3375	2.38	-68734.2853	NA
delta_b	NA	NA	0	NA	108783.4303	NA
sigma_delta_a	NA	NA	-0.0815	-0.94	-23660.4136	NA
sigma_delta_b	NA	NA	0.0874	1.12	-12748.3652	NA
mu_log_b_areaplay_c	NA	NA	NA	NA	-0.0479	NA
mu_log_b_castle_c	NA	NA	NA	NA	0.1633	NA
mu_log_b_cno_c	NA	NA	NA	NA	0	NA
mu_log_b_educadults_c	NA	NA	NA	NA	0.1791	NA
mu_log_b_eno_c	NA	NA	NA	NA	0	NA
mu_log_b_eventschild_c	NA	NA	NA	NA	-0.1215	NA
mu_log_b_hall_c	NA	NA	NA	NA	-0.0423	NA
mu_log_b_price_c	NA	NA	NA	NA	-0.0469	NA
mu_log_b_sno_c	NA	NA	NA	NA	0	NA
mu_log_b_social_c	NA	NA	NA	NA	0.1057	NA
sigma_log_b_areaplay_c	NA	NA	NA	NA	0.1731	NA
sigma_log_b_castle_c	NA	NA	NA	NA	-0.673	NA
sigma_log_b_cno_c	NA	NA	NA	NA	-0.0623	NA
sigma_log_b_educadults_c	NA	NA	NA	NA	0.0507	NA
sigma_log_b_eno_c	NA	NA	NA	NA	-1.0826	NA
sigma_log_b_eventschild_c	NA	NA	NA	NA	0.0481	NA
sigma_log_b_hall_c	NA	NA	NA	NA	-0.4586	NA
sigma_log_b_price_c	NA	NA	NA	NA	-0.0452	NA
sigma_log_b_sno_c	NA	NA	NA	NA	0.0525	NA
sigma_log_b_social_c	NA	NA	NA	NA	-0.2267	NA
gamma_englishheritage_c	NA	NA	NA	NA	0	NA
gamma_highincome_c	NA	NA	NA	NA	0	NA
gamma_children_c	NA	NA	NA	NA	0	NA
gamma_highereducation_c	NA	NA	NA	NA	0	NA
gamma_heritage_very_future_c	NA	NA	NA	NA	0	NA
gamma_heritage_visit_c	NA	NA	NA	NA	0	NA
b_delta_c	NA	NA	NA	NA	0	NA

I've also messaged you privately with the Excel file as this formats strangely when copying.

Thanks for all the help
Tom
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: Error in Mixed Latent Class model

Post by stephanehess »

Hi

it's clear that both your latent class models end up in very weird solutions if you look at the parameter estimates. But looking in detail, I noticed that you are making the constant in the class allocation model follow a normal distribution. Was that intentional? If so, you also seem to have missed a normalisation there as you are still estimating sigma_delta_b in the two class model. Did you try a model with non-random deltas?

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
Post Reply