Page 1 of 1

Binary/Multinomial logit in the measurement model for HCM

Posted: 08 Jul 2020, 15:29
by hrrichard
Hi Stephane,

I am estimating a HCM, and instead of the conventional approach such as Likert-scale indicators, I would like to use other variables as indicators for the latent variable. In this case, I would use a binary/multinomial logit in the measurement equations. I have two questions regarding these:
1. Do you think I should create a different lists for these MNLs other than the list of "V" that is used for the stated choice data?
2. Would you recommend to specify constants in these MNLs to capture the overall preference for the choice options of the indicators alongside the zeta parameters capturing the impact of the LV?

For the binary case, I have implemented the following code:

Code: Select all

I= list()
  
  I[['op1']] = Constant_1_1+ zeta_ind_1_1*LV
  I[['op2']] = Constant_1_2+ zeta_ind_1_2*LV
  
  mnl_settings_2 = list(
    alternatives = c(op1=0, op2=1),
    avail        = list(op1=1, op2=1),
    choiceVar    = Ind_1,
    V            = I,
    rows=(Sequence==1)
  )
  P[["ind_1"]] = apollo_mnl(mnl_settings_2, functionality)
While I implemented the following code for the MNL:

Code: Select all

J= list()
  
  J[['op1']] = Constant_2_1+ zeta_ind_2_1*LV
  J[['op2']] = Constant_2_2+ zeta_ind_2_2*LV
  J[['op3']] = Constant_2_3+ zeta_ind_2_3*LV

  mnl_settings_2 = list(
    alternatives = c(op1=0, op2=1,op3=2),
    avail        = list(op1=1, op2=1,op3=1),
    choiceVar    = Ind_2,
    V            = J,
    rows=(Sequence==1)
  )
  P[["ind_2"]] = apollo_mnl(mnl_settings3, functionality)
Thank you for your help!

Best wishes,
Richard

Re: Binary/Multinomial logit in the measurement model for HCM

Posted: 08 Jul 2020, 22:29
by stephanehess
Hi Richard

on point 1, what you do is indeed the easiest and best way of doing it. You could use the same list for the different components, but you would need to reset it in between each component (so you start with an empty one). While that would save a little memory compared to creating new lists and keeping the others in memory, the coding is more convoluted and the risk of mistakes is larger.

on point 2, yes, when I've used binary (or multinomial) indicators for LVs, I include constants, obviously with a normalisation for identification.

Best wishes

Stephane

Re: Binary/Multinomial logit in the measurement model for HCM

Posted: 05 Jan 2021, 12:48
by Sissi
Hi Stephanehess,

I have a related question. I plan to use HCM for joint estimation of stated choice and perception/attitude data.
Attitude contains 8 statements, and their answers are binary;i.e., 1 if a statement is selected or 0 otherwise.
I follow your example in apollo_example_24 for drug choice, using ordered measurement model for indicators.

Code: Select all

apollo_beta = c(lambda  = 1, # respondent choose a favorite photo, no other attributes available.
                gamma_gender     = 0, 
                gamma_birth   	   = 0, 
		gamma_edu    	   = 0,
                zeta_aesthetic     = 1, 
                zeta_access    	  = 1, 
                zeta_forestry      = 1, 
                zeta_grazing       = 1, 
                zeta_bio  		  = 1, 
                zeta_culture       = 1, 
                zeta_carbon        = 1, 
                tau_aesthetic_1    = 0, # the number of different levels in the dependent variable -1
                tau_access_1  	   = 0, 
                tau_forestry_1     = 0, 
                tau_grazing_1      = 0, 
                tau_bio_1 	   =0, 
                tau_culture_1      = 0, 
                tau_carbon_1       = 0) 
Here is the warning i have received:
Testing likelihood function...
Error in apollo_preprocess(inputs = ol_settings, modelType, functionality, :
If provided as scalars, need at least two thresholds for Ordered Logit for model component "indic_aesthetic"!


Because latent indicators are binary, I only specify one threshhold for each tau indicator in apollo_beta following the instruction in apollo manual.
Apparently, this is a wrong specification. How can I adapt my code so that I can run the HCM with binary attitude indicators? I have gone through the apollo manual, but did not find examples.

Many thanks in advance for your attentions.

Best regards,
Sissi

Re: Binary/Multinomial logit in the measurement model for HCM

Posted: 05 Jan 2021, 12:56
by stephanehess
Hi Sissi

if your dependent variable is binary, then you should just use an MNL model for it, rather than an OL.

Stephane

Re: Binary/Multinomial logit in the measurement model for HCM

Posted: 23 Oct 2024, 13:44
by LotteMuller
Hi all,

I have also been working on including a binary dependent variable in the measurement model for HCM, but getting stuck in the defining the model/likelihood function here. I have several variables about attribute non-attendance which I wanted to include in the analysis, but this is starting with one.

Questions:
1. have I correctly included the binary dependent variable (stated attribute non-attendance)? Not sure how to specify the 'P' - my code currently leads to the error: object 'P' not found.
2. If I am looking to account for attribute non-attendance, have I included the latent variable correctly in the utility model at the end? LV pertains to the stated attribute non-attendance of variable rainmean.

Hopefully I have overlooked something simple?

Code: Select all


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 I
  I = list()
  ### Likelihood of indicators
  I[['op1']] = kappa_rainfall_1 + zeta_NA_rainfall_1*LV # IGNORE
  I[['op2']] = kappa_rainfall_2 + zeta_NA_rainfall_2*LV # not ignore

  mnl_settings_1 = list(
    alternatives = c(op1=1, op2=0),
    avail        = list(op1=1, op2=1),
    choiceVar    = attribute_ignore.1,
    utilities    = I,
    rows=(question==1)
  )
  P[["indic_NA_rainfall"]] = apollo_mnl(mnl_settings_1, functionality)
  
  
  
  ### Likelihood of choices
  V = list()
  V[["option1"]] = (b_rainmean * rainMean_1 + b_variance * variance_1 
                    + b_fracI * fracI_1 + b_costI * costI_1 + b_payback * payback_1 
                    + lambda * LV) 
  
  V[["option2"]] = (b_rainmean * rainMean_2 + b_variance * variance_2 
                    + b_fracI * fracI_2 + b_costI * costI_2 + b_payback * payback_2 
                    + lambda * LV) 
  
  V[["sq"]]      = asc_sq
  
  
  ### Define settings for MNL model component
  mnl_settings_2  = list(
    alternatives  = c(option1=1, option2=2, sq=3), 
    avail         = list(option1=av_opt1, option2=av_opt2, sq=av_sq), 
    choiceVar     = best,
    utilities     = V,
    rows=(question==1)
  )
  
  
  ### Compute probabilities for MNL model component
  P[["best"]] = apollo_mnl(mnl_settings_2, functionality) 
  
  ### Likelihood of the whole model
  P = apollo_combineModels(P, apollo_inputs, functionality)
  
  ### Take product across observation for same individual
  P = apollo_panelProd(P, apollo_inputs, functionality)
  
  ### Average across inter-individual draws
  P = apollo_avgInterDraws(P, apollo_inputs, functionality) 
  
  ### Prepare and return outputs of function
  P = apollo_prepareProb(P, apollo_inputs, functionality)
  return(P)
}

Thanks for the space to post this question!

Best,
Lotte

Re: Binary/Multinomial logit in the measurement model for HCM

Posted: 23 Oct 2024, 22:00
by stephanehess
Hi

all Apollo models start with a definition of P as a list. Have a look at the examples online, which all have this.

Also, if you have a binary logit model, you cannnot estimate the parameters in both utilities, you need a normalisation.

Finally, in relation to their inclusion in the choice model, what you are doing at the moment is checking whether the LV has an impact on opt1 and opt2 vs the SQ. Is that what you want to do? It's not really about attribute non-attendance

Hope this helps

Stephane