Page 1 of 1

panel data for latent class model

Posted: 12 Dec 2024, 07:27
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

Re: panel data for latent class model

Posted: 13 Dec 2024, 09:29
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

Re: panel data for latent class model

Posted: 16 Dec 2024, 06:50
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

Re: panel data for latent class model

Posted: 16 Dec 2024, 08:47
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

Re: panel data for latent class model

Posted: 18 Dec 2024, 07:02
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

Re: panel data for latent class model

Posted: 16 Jan 2025, 12:56
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