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.

What is delta in latent class model?

Ask questions about model specifications. Ideally include a mathematical explanation of your proposed model.
Post Reply
syeed
Posts: 3
Joined: 21 Mar 2022, 15:37

What is delta in latent class model?

Post by syeed »

Dear Prof. Hess,

I am developing a latent class model containing two latent classes. In the example model, I have noticed two parameters, "delta_a" and "delta_b" in the apollo beta and the output has provided the estimated for the deltas. My question is: do we need to employ deltas in the apollo beta, how do they affect the outcome estimates, and how to interpret them? Are they default mandatory variables to keep in the latent class model? And are they proportionate to the number of classes, for example, three deltas for three latent classes model?
We have run the same model in the NLogit, but we did not have to use deltas or any variables equivalent to deltas. FYI, our data has an opt-out option. Below is the code we have used to develop the model.
Thank you for your help.

apollo_beta = c(asc_1 = 0,
asc_2 = 0,
asc_optout = 0,
beta_rec_a = 0,
beta_rec_b = 0,
beta_eff_a = 0,
beta_eff_b = 0,
beta_sideno_a =0,
beta_sideno_b =0,
beta_sidemild_a =0,
beta_sidemild_b =0,
beta_sidesev_a =0,
beta_sidesev_b =0,
beta_cost_a=0,
beta_cost_b=0,
delta_a = 0,
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("asc_optout","delta_b")

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

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

lcpars[["beta_rec"]] = list(beta_rec_a, beta_rec_b)
lcpars[["beta_eff"]] = list(beta_eff_a, beta_eff_b)
lcpars[["beta_sideno"]] = list(beta_sideno_a, beta_sideno_b)
lcpars[["beta_sidemild"]] = list(beta_sidemild_a, beta_sidemild_b)
lcpars[["beta_sidesev"]] = list(beta_sidesev_a, beta_sidesev_b)
lcpars[["beta_cost"]] = list(beta_cost_a, beta_cost_b)

V=list()
V[["class_a"]] = delta_a
V[["class_b"]] = delta_b

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(alt1=1, alt2=2, alt3=3),
avail = list(alt1=1, alt2=1, alt3=1),
choiceVar = Choice
)

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

### Compute class-specific utilities
V=list()
V[["alt1"]] = asc_1+beta_rec[[s]]*REC1 + beta_eff[[s]]*Eff1 + beta_sideno[[s]]*sideno1 + beta_sidemild[[s]]*sidemild1+beta_sidesev[[s]]*sidesev1+beta_cost[[s]]*cost1
V[["alt2"]] = asc_2+beta_rec[[s]]*REC2 + beta_eff[[s]]*Eff2 + beta_sideno[[s]]*sideno2 + beta_sidemild[[s]]*sidemild2+beta_sidesev[[s]]*sidesev2+beta_cost[[s]]*cost2
V[["alt3"]] = asc_optout

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)
}

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

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

# ################################################################# #
#### MODEL ESTIMATION ####
# ################################################################# #

### Optional starting values search
# apollo_beta=apollo_searchStart(apollo_beta, apollo_fixed,apollo_probabilities, apollo_inputs)

model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)

# ################################################################# #
#### MODEL OUTPUTS ####
# ################################################################# #

# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO SCREEN) ----
# ----------------------------------------------------------------- #

apollo_modelOutput(model)

apollo_beta = apollo_searchStart(apollo_beta,
apollo_fixed,
apollo_probabilities,
apollo_inputs)
# searchStart_settings)

# ----------------------------------------------------------------- #
#---- FORMATTED OUTPUT (TO FILE, using model name) ----
# ----------------------------------------------------------------- #

apollo_saveOutput(model)
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: What is delta in latent class model?

Post by stephanehess »

Hi

a latent class model uses a class allocation model. This needs to have constants in it. Please look at the details in the manual (http://apollochoicemodelling.com/manual.html) and the references to the theory on latent class models therein

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