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. We check the forum at least twice a week. It may thus take a couple of days for your post to appear and before we reply. There is no need to submit the post multiple times.

panel data for latent class model

Ask questions about model specifications. Ideally include a mathematical explanation of your proposed model.
Post Reply
georkapo
Posts: 11
Joined: 15 May 2023, 16:49

panel data for latent class model

Post by georkapo »

Dear Stephane, Dear David,

I have a data set from a stated experiment in which each respondent answered 4 choice tasks. Now, I want to estimate a latent class model, and my question is whether I need to take into account the panel effect of the multiple answers by the same respondent. In the Appollo manual, equation 6.17 seems to incorporate the panel effect. Is it correct? Do I need to make another implementation or explicitly specify this in Appollo?

Thank you for your help in advance.

Best regards,
Giorgos
stephanehess
Site Admin
Posts: 1235
Joined: 24 Apr 2020, 16:29

Re: panel data for latent class model

Post by stephanehess »

Giorgos

yes, you need the panel product inside the classes. Have a look at the online example (https://apollochoicemodelling.com/files ... variates.r) which shows you how to do that

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
jeorge
Posts: 1
Joined: 12 Dec 2024, 08:03

Re: panel data for latent class model

Post by jeorge »

Dear Stephane,

Does this case require creating an error component for each alternative, and then multiplying the class-specific but alternative-unspecific coefficients by the alternative-specific error components and adding them to the corresponding utility functions? I've seen articles with class generic coefficients and class specific ones, which one is better please?
Also, may I ask what it means if the coefficient on the estimated error component is negative? Is this result normal?
Thanks in advance!

Best wishes,
Jeorge
stephanehess
Site Admin
Posts: 1235
Joined: 24 Apr 2020, 16:29

Re: panel data for latent class model

Post by stephanehess »

Jeorge

it would help if you could show me your code. You are talking about LC, but then also about error components, so it sounds like latent class with mixed logit.

Sign of sigma is not relevant as the draws are symmetric around zero. You could also find that by looking at https://apollochoicemodelling.com/faq.html

Thanks

Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
jeorge
Posts: 1
Joined: 12 Dec 2024, 08:03

Re: panel data for latent class model

Post by jeorge »

Dear Stephane,
Thank you very much for you response!
My model is hybrid latent class, also class-specific error components are included in the choice model. The error component estimation results indicate that, one class is insignificant, one class is siginificant positive, one class is siginificant negative. I look the link you provided, maybe it is normal to get negative coefficient, but I am not sure whether my result is normal? Since both positive and negative are in my results, is there a specific meaning of positive and negative here?
In addition, I find some literature set the error component as class invariant, which one is better?
Below is my code, thank you very much!

Best wishes,
Jeorge

apollo_draws = list(
interDrawsType="halton",
interNDraws=1000,
interUnifDraws=c(),
interNormDraws=c("eta1","eta2","draws_pc","draws_pt","draws_tx")
)
### Create random parameters
apollo_randCoeff=function(apollo_beta, apollo_inputs){
randcoeff = list()

randcoeff[["EM"]] = em_pro1 * pro1 + eta1
randcoeff[["ET"]] = et_in1 * in1 + eta2
randcoeff[["ec_pc"]] = draws_pc
randcoeff[["ec_pt"]] = draws_pt
randcoeff[["ec_tx"]] = draws_tx
return(randcoeff)
}
#### DEFINE LATENT CLASS COMPONENTS####
apollo_lcPars=function(apollo_beta, apollo_inputs){
lcpars = list()
lcpars[["beta_pr"]] = list(beta_pr_a, beta_pr_b, beta_pr_c)
lcpars[["beta_co"]] = list(beta_co_a, beta_co_b, beta_co_c)
lcpars[["beta_tt"]] = list(beta_tt_a, beta_tt_b, beta_tt_c)
lcpars[["beta_ttp"]] = list(beta_ttp_a, beta_ttp_b, beta_ttp_c)
lcpars[["beta_ttx"]] = list(beta_ttx_a, beta_ttx_b, beta_ttx_c)
lcpars[["beta_wat"]] = list(beta_wat_a, beta_wat_b, beta_wat_c)
lcpars[["asc_pt"]] = list(asc_pt_a, asc_pt_b, asc_pt_c)
lcpars[["asc_tx"]] = list(asc_tx_a, asc_tx_b, asc_tx_c)
lcpars[["sigma_panel"]] = list(sigma_panel_a, sigma_panel_b, sigma_panel_c)

### Utilities of class allocation model
V=list(class_a= delta_a + beta_male_a * gender + beta_edu2_a*edu2 + beta_em_a*EM + beta_et_a * ET,
class_b = delta_b + beta_male_b * gender + beta_edu2_b*edu2 + beta_em_b*EM + beta_et_b * ET,
class_c = delta_c + beta_male_c * gender + beta_edu2_c*edu2 + beta_em_c*EM + beta_et_c * ET)

### Settings for class allocation models
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"){

### Initialise
apollo_attach(apollo_beta, apollo_inputs)
on.exit(apollo_detach(apollo_beta, apollo_inputs))
P = list()

### Likelihood of indicators
ol_settings1 = list(outcomeOrdered = EM1,
V = zeta_EM1*EM,
tau = list(tau_EM1_1, tau_EM1_2, tau_EM1_3, tau_EM1_4),
rows = (scenario==1),
componentName = "indic_EM1")
ol_settings2 = list(outcomeOrdered = EM2,
V = zeta_EM2*EM,
tau = list(tau_EM2_1, tau_EM2_2, tau_EM2_3, tau_EM2_4),
rows = (scenario==1),
componentName = "indic_EM2")
ol_settings3 = list(outcomeOrdered = ET1,
V = zeta_ET1*ET,
tau = list(tau_ET1_1, tau_ET1_2, tau_ET1_3, tau_ET1_4),
rows = (scenario==1),
componentName = "indic_ET1")
ol_settings4 = list(outcomeOrdered = ET2,
V = zeta_ET2*ET,
tau = list(tau_ET2_1, tau_ET2_2, tau_ET2_3, tau_ET2_4),
rows = (scenario==1),
componentName = "indic_ET2")
ol_settings5 = list(outcomeOrdered = ET3,
V = zeta_ET3*ET,
tau = list(tau_ET3_1, tau_ET3_2, tau_ET3_3, tau_ET3_4),
rows = (scenario==1),
componentName = "indic_ET3")
P[["indic_EM1"]] = apollo_ol(ol_settings1, functionality)
P[["indic_EM2"]] = apollo_ol(ol_settings2, functionality)
P[["indic_ET1"]] = apollo_ol(ol_settings3, functionality)
P[["indic_ET2"]] = apollo_ol(ol_settings4, functionality)
P[["indic_ET3"]] = apollo_ol(ol_settings5, functionality)
P[["indic_EM1"]] = apollo_panelProd(P[["indic_EM1"]], apollo_inputs, functionality)
P[["indic_EM2"]] = apollo_panelProd(P[["indic_EM2"]], apollo_inputs, functionality)
P[["indic_ET1"]] = apollo_panelProd(P[["indic_ET1"]], apollo_inputs, functionality)
P[["indic_ET2"]] = apollo_panelProd(P[["indic_ET2"]], apollo_inputs, functionality)
P[["indic_ET3"]] = apollo_panelProd(P[["indic_ET3"]], apollo_inputs, functionality)
### Loop over classes
S <- 3
for(s in 1:S){

### Compute class-specific utilities
V=list()
V[["pc"]] = asc_pv + beta_pr[[s]]*pr + beta_co[[s]]*co_pc + beta_tt[[s]] * tm_pc + sigma_panel[[s]]*draws_pc
V[["pt"]] = asc_pt[[s]] + beta_co[[s]]*co_pt + beta_tts[[s]]*tm_pt + beta_wat[[s]]*wait_pt + sigma_panel[[s]]*draws_pt
V[["tx"]] = asc_tx[[s]] + beta_co[[s]]*co_tx + beta_ttx[[s]]*tm_tx + beta_wat[[s]]*wait_tx + sigma_panel[[s]]*draws_tx
Last edited by jeorge on 18 Dec 2024, 07:38, edited 3 times in total.
stephanehess
Site Admin
Posts: 1235
Joined: 24 Apr 2020, 16:29

Re: panel data for latent class model

Post by stephanehess »

Hi

sorry for the slow reply

Can you please show the entire code (including apollo_beta and apollo_fixed) and your outputs?

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