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.

WTP for mixed logit with random parameters

Ask questions about post-estimation functions (e.g. prediction, conditionals, etc) or other processing of results.
stephanehess
Site Admin
Posts: 998
Joined: 24 Apr 2020, 16:29

Re: WTP for mixed logit with random parameters

Post by stephanehess »

Sorry for the slow reply, I was travelling.

the delta method calculation gives you standard errors for functions of model parameters. These relate to the fact that you have a finite sample. You can use the delta method for any functions, including moments of wtp.

If you have a normally distributed numerator (with mean mu_A2 and standard deivation sd_A2) and a fixed denominator (b_price), then you would get the following moments for wtp

mean: mu_A2/b_price
sd: sd_A2/b_price

with a lognormal, it's more difficult as you would need to apply the formula to get the mean and sd of the lognormal.

The second part in your message relates to the distribution in a population, but you are mixing up two things here in your answer, as you are dividing the distributed parameter by the mean and sd. What you probably want to do is

mean(un$b_A2/un$b_price)
sd(un$b_A2/un$b_price)

but it's getting a bit difficult to follow this - maybe just tell me what your final model actually is and what results you want to compute

Thanks
--------------------------------
Stephane Hess
www.stephanehess.me.uk
JuliavB
Posts: 42
Joined: 18 Aug 2021, 13:36

Re: WTP for mixed logit with random parameters

Post by JuliavB »

Dear Stephane,

please find below the final model with a normally distributed numerator (with mean mu_HoeheEEE and standard deviation sd_HoeheEEE) and a fixed denominator for price (b_Beitr).

I would like to compute the results for the WTP for the HoeheEEE attribute:

I would do the following:
I would calculate the moments of WTP like this:

mean: mu_HoeheEEE/b_Beitr
sd: sd_HoeheEEE/b_Beitr

and can get the standard errors for this moments via delta method:

deltaMethod_settings=list(expression=c(WTP_Hoehe="(mu_HoeheEEE/b_Beitr)"))
apollo_deltaMethod(model, deltaMethod_settings)

deltaMethod_settings=list(expression=c(sd_Hoehe="(sd_HoeheEEE/b_Beitr)"))
apollo_deltaMethod(model, deltaMethod_settings)

BUT: What is the WTP that needs to be reported? Are there any further calculations necessary OR is it just fine to report both mu_HoeheEEE/b_Beitr and sd_HoeheEEE/b_Beitr separately to show the heterogeneity?!

Your advice is highly appreciated.
Thanks and best,
J.
____________________

# ################################################################# #
#### DEFINE MODEL PARAMETERS ####
# ################################################################# #
### Vector of parameters, including any kept fixed during estimation
apollo_beta = c(b0 = 0,
sigma_panel = 0,
b_Beitr = 0,
mu_HoeheEEE = 0,
sigma_HoeheEEE = 0,
b_HoeheEEEunb = 0, # dummy
mu_ZeitEEE = 0,
sigma_ZeitEEE = 0,
b_ZeitEEEunb = 0) # dummy

### Vector with parameter names (in quotes) to be kept fixed at
# their starting values during estimation.
# Use apollo_beta_fixed = c() if none
apollo_fixed = c()

# ################################################################# #
#### DEFINE RANDOM COMPONENTS // RP ####
# ################################################################# #

### Set parameters for generating draws
apollo_draws = list(
interDrawsType = "mlhs",
interNDraws = 600,
interUnifDraws = c(),
interNormDraws = c("draws_HoeheEEE","draws_ZeitEEE","draws_alt1","draws_alt2","draws_alt3"),
intraDrawsType = "halton",
intraNDraws = 0,
intraUnifDraws = c(),
intraNormDraws = c()
)

### Create random parameters
apollo_randCoeff = function(apollo_beta, apollo_inputs){
randcoeff = list()

#randcoeff[["b_Beitr"]] = mu_Beitr + sigma_Beitr * draws_Beitr
#randcoeff[["b_Beitr"]] = -exp(mu_Beitr + sigma_Beitr * draws_Beitr)
randcoeff[["b_HoeheEEE"]] = mu_HoeheEEE + sigma_HoeheEEE * draws_HoeheEEE
randcoeff[["b_ZeitEEE"]] = mu_ZeitEEE + sigma_ZeitEEE * draws_ZeitEEE

randcoeff[["ec_alt1"]] = sigma_panel * draws_alt1
randcoeff[["ec_alt2"]] = sigma_panel * draws_alt2
randcoeff[["ec_alt3"]] = sigma_panel * draws_alt3

return(randcoeff)
}


# ################################################################# #
#### GROUP AND VALIDATE INPUTS ####
# ################################################################# #

apollo_inputs = apollo_validateInputs()

# ################################################################# #
#### DEFINE MODEL AND LIKELIHOOD FUNCTION ####
# ################################################################# #

apollo_probabilities=function(apollo_beta, apollo_inputs,
functionality="estimate"){

### Function initialisation: do not change the following three commands
### 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()

### List of utilities: these must use the same names as in mnl_settings, order is irrelevant
V = list()


V[["SQ"]] = b0 + b_Beitr*Beitr_1 + b_HoeheEEE*HoeheEEE_1*(HoeheEEE_1!=4) + b_HoeheEEEunb*(HoeheEEE_1==4) + b_ZeitEEE*ZeitEEE_1*(ZeitEEE_1!=4)+ b_ZeitEEEunb*(ZeitEEE_1==4)+ ec_alt1
V[["RefA"]] = b_Beitr*Beitr_2 + b_HoeheEEE*(HoeheEEE_2==3|HoeheEEE_2==6|HoeheEEE_2==9)*HoeheEEE_2 + b_HoeheEEEunb*(HoeheEEE_2==4) +b_ZeitEEE*ZeitEEE_2*(ZeitEEE_2!=4)+ b_ZeitEEEunb*(ZeitEEE_2==4)+ ec_alt2
V[["RefB"]] = b_Beitr*Beitr_3 + b_HoeheEEE*(HoeheEEE_3==3|HoeheEEE_3==6|HoeheEEE_3==9)*HoeheEEE_3 + b_HoeheEEEunb*(HoeheEEE_3==4) + b_ZeitEEE*ZeitEEE_3*(ZeitEEE_3!=4)+ b_ZeitEEEunb*(ZeitEEE_3==4)+ ec_alt3


### Define settings for MNL model component
mnl_settings = list(
alternatives = c(SQ=1, RefA=2, RefB=3),
choiceVar = Choice,
utilities = V
)
____________________________
stephanehess
Site Admin
Posts: 998
Joined: 24 Apr 2020, 16:29

Re: WTP for mixed logit with random parameters

Post by stephanehess »

Yes, that works, if you are indeed happy with a fixed cost coefficient, which is likely an inferior model specification.

also, you can do it all in one

Code: Select all

deltaMethod_settings=list(expression=c(WTP_Hoehe="(mu_HoeheEEE/b_Beitr)",sd_Hoehe="(sd_HoeheEEE/b_Beitr)"))
Stephane
--------------------------------
Stephane Hess
www.stephanehess.me.uk
Rodrigo_Z
Posts: 1
Joined: 03 Apr 2024, 06:10

Re: WTP for mixed logit with random parameters

Post by Rodrigo_Z »

Hi professor Stephane,

I have a follow-up question regarding this quote:
with a lognormal, it's more difficult as you would need to apply the formula to get the mean and sd of the lognormal.
In my case, I'm running MMNL models in the preference space, using normal distributions for the non-cost attributes and a negative log-normal distribution for the price attribute. My approach to estimating the WTP values and their standard errors (S.E.) is to use the Delta method. Therefore, I would appreciate it if you could elaborate more on what you mean by this. Is there any available example of how to use the Delta Method to estimate WTP when using these distributions? Otherwise, what formula should be used and you refer to?

Thank you!!
Rodrigo
stephanehess
Site Admin
Posts: 998
Joined: 24 Apr 2020, 16:29

Re: WTP for mixed logit with random parameters

Post by stephanehess »

Hi

the delta method in Apollo is for individual model parameters, not for distributed coefficients. In your case, you would need to use apollo_unconditionals to obtain the draws for the coefficients and calculate WTP moments that way, but you would not be able to use apollo_deltaMethod as you cannot analytically express the moments of the WTP distribution if you're dividing Normal by Lognormal

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