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.

errors in Latent class model

Ask questions about errors you encouunter. Please make sure to include full details about your model specifications, and ideally your model file.
georkapo
Posts: 10
Joined: 15 May 2023, 16:49

Re: errors in Latent class model

Post by georkapo »

Hi again,

In addition, I have estimated the LC model with two classes and got the willingness to pay. However, since I kept some attribute levels as fixed, can I calculate the wtp for the fixed ones? Is it possible to get the wtp for all of the attributes?
Also, the wtp that I calculated is the relative wtp since it is always compared with the fixed attributes?

Sorry, if this is a silly question!

Thank you in advance.
Best regards,
Georgios
dpalma
Posts: 190
Joined: 24 Apr 2020, 17:54

Re: errors in Latent class model

Post by dpalma »

Hi Georgios,

I'm not sure I fully understand all your questions, but will do my best to answer.

I understand you are modelling a health-related choice using latent classes, and you have data from different countries. So the country is not the dependent variable. I am not sure what you mean by the "posterior probability". Is it the posterior probability of the class allocation? And when you say "I can calculate the posterior probability for the aggregate data (all countries)", do you mean you can calculate the class allocation probability for each observation in your pooled data (the data including observations from all countries)?

If you want to calculate an average posterior class allocation probability for each country, I would simply take the average posterior for all individuals from each country. You can do that with the following code:

Code: Select all

# Calculate conditional (posterior) class allocation probabilities per indiv
conditionals <- apollo_conditionals(model,apollo_probabilities, apollo_inputs)
# Add country of origin to conditionals
tmp <- unique(database[,c("ID", "country")]) # create database with ID and country
conditionals <- merge(conditionals, tmp, by="ID") # merge the two databases
rm(tmp) # delete temporal database
# Get average conditionals by country
aggregate(conditionals[,c("X1","X2")], by=conditionals["country"], FUN=mean)
In the code, I am assuming you have variable in your database called "country" that indicates what country each observation is from. I also assume that there are only two classes, and that their posterior class allocation are called "X1" and "X2" when returned by apollo_conditionals.

You could also create a different model for each country, but I would not recommend it, as you would loose efficiency (each individual model would not as precise as your larger model).

I would recommend you include the country in the class allocation probability. But you should only keep it if it has a significant effect.

You can calculate the average posterior class allocation probability for other socio-demographics in the same way that you do for country of origin. So if you wanted to do it by income level (I am assuming you have a variable called "incomeLevel" in your database), you could use the following code:

Code: Select all

# Calculate conditional (posterior) class allocation probabilities per indiv
conditionals <- apollo_conditionals(model,apollo_probabilities, apollo_inputs)
# Add income level to conditionals
tmp <- unique(database[,c("ID", "incomeLevel")]) # create database with ID and country
conditionals <- merge(conditionals, tmp, by="ID") # merge the two databases
rm(tmp) # delete temporal database
# Get average conditionals by income level
aggregate(conditionals[,c("X1","X2")], by=conditionals["incomeLevel"], FUN=mean)
Finally, when you say "I kept some attribute levels as fixed", do you mean you fixed their corresponding parameters to zero, so you used them as base? If so, no, you cannot calculate the WTP for the base level, as all other WTP are with respect to that level. For example, if you have a categorical variable that can take three levels: red, green, and blue. And you fix the coefficient of b_red=0, but estimate b_green and b_blue. Then b_green/b_cost (where b_cost is the non-random coefficient of price) is the WTP for a green alternative with respect to a red one. The only thing you can say about the WTP for a red alternative is that it is b_green/b_cost lower than the WTP for a green alternative, a statement that doesn't really add any new information.

Best wishes
David
georkapo
Posts: 10
Joined: 15 May 2023, 16:49

Re: errors in Latent class model

Post by georkapo »

Dear David,

Thank you very much. I really appreciate your help.

Indeed, I want to calculate the average posterior class allocation probability for each country and for some other sociodemographic variables. What you recommended works fine.

Another question I have is about the heterogeneity. In the model I calculated, I found some deterministic heterogeneity and then also random heterogeneity (in the class allocation). However, I am not sure if I need to use the determinist heterogeneity in my final model. Should I keep the variables with deterministic heterogeneity (e.g. female, elderly), or should I just keep the random heterogeneity? Does it make any sense to keep both (deterministic and random)?

Best regards,
Georgios
stephanehess
Site Admin
Posts: 998
Joined: 24 Apr 2020, 16:29

Re: errors in Latent class model

Post by stephanehess »

Georgios

it's always best to have deterministic heterogeneity too. That means you're actually explaining things

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