Important: Read this before posting to this forum
 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.
 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.
 Before asking a question on the forum, users are kindly requested to follow these steps:
 Check that the same issue has not already been addressed in the forum  there is a search tool.
 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
 Check the frequently asked questions section on the Apollo website, which discusses some common issues/failures. Please see http://www.apollochoicemodelling.com/faq.html
 Make sure that R is using the latest official release of Apollo.
 Users can check which version they are running by entering packageVersion("apollo").
 Then check what is the latest full release (not development version) at http://www.ApolloChoiceModelling.com/code.html.
 To update to the latest official version, just enter install.packages("apollo"). To update to a development version, download the appropriate binary file from http://www.ApolloChoiceModelling.com/code.html, and install the package from file
 If the above steps do not resolve the issue, then users should follow these steps when posting a question:
 provide full details on the issue, including the entire code and output, including any error messages
 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.
delta method to calculate WTP (normal and lognormal parameters)
delta method to calculate WTP (normal and lognormal parameters)
Dear apolloteam,
I estimated a mixed logit with the noncost attributes beeing normally distributed and the cost attribute negative lognormal in preference space.
Now I want to calculate the WTPs. I understand the cost attribute needs a "correction" and I can not directly apply the ratio operation within the deltamethod between a normal distributed and a negative lognormal distributed parameter.
How do I proceed? I thought of applying the apollo_delta "twice"? First, use apollo_delta to get the mean and s.d. for the cost attribute parameter for the underlying normal by using the operation "lognormal".
But how do I proceed then? How can I now use these results then in a second step to calculate the WTPs for my noncostattributes? I assume I must somehow access the values of the mean and s.d. for the cost attribute of the underlying normal that are stored somewhere in apollo? I tried to look at what is stored in apollo_delta, but I could not find it there?
I hope for some support. Sorry, if this is a very trivial question!
Thank you very much in advance.
Rea
I estimated a mixed logit with the noncost attributes beeing normally distributed and the cost attribute negative lognormal in preference space.
Now I want to calculate the WTPs. I understand the cost attribute needs a "correction" and I can not directly apply the ratio operation within the deltamethod between a normal distributed and a negative lognormal distributed parameter.
How do I proceed? I thought of applying the apollo_delta "twice"? First, use apollo_delta to get the mean and s.d. for the cost attribute parameter for the underlying normal by using the operation "lognormal".
But how do I proceed then? How can I now use these results then in a second step to calculate the WTPs for my noncostattributes? I assume I must somehow access the values of the mean and s.d. for the cost attribute of the underlying normal that are stored somewhere in apollo? I tried to look at what is stored in apollo_delta, but I could not find it there?
I hope for some support. Sorry, if this is a very trivial question!
Thank you very much in advance.
Rea
Re: delta method to calculate WTP (normal and lognormal parameters)
Hi Rea,
apollo_deltaMethod cannot do what you want (at least for now). What I recommend is simulating the distribution of the WTP.
Let's imagine the attribute you are interested in is called "attr". Its coefficient follows a normal distribution with mean mu_attr and standard deviation sg_attr. On the other hand, your cost coefficient follows a negative lognormal distribution, where the underlying normal has a mean of mu_cost and a standard deviation of sg_cost. Therefore, your apollo_randCoeff function may look as follows:
Now let's consider you already estimated your model, so the value of all parameters is available inside model$estimate. You can now generate a large number of draws from the distribution of each coefficient, calculate the ratio between them, and calculate the mean and s.e. of the ratio, which will be the mean and s.e. of the WTP, as follows:
For more details and other more elegant approaches to calculate the same you can look at
Daly, A.; Hess, S. and Train, K. (2012) Assuring finite moments for willingness to pay in random coefficient models. Transportation 39, 1931.
Cheers
David
apollo_deltaMethod cannot do what you want (at least for now). What I recommend is simulating the distribution of the WTP.
Let's imagine the attribute you are interested in is called "attr". Its coefficient follows a normal distribution with mean mu_attr and standard deviation sg_attr. On the other hand, your cost coefficient follows a negative lognormal distribution, where the underlying normal has a mean of mu_cost and a standard deviation of sg_cost. Therefore, your apollo_randCoeff function may look as follows:
Code: Select all
apollo_randCoeff = function(apollo_beta, apollo_inputs){
randcoeff = list()
randcoeff[["b_attr"]] = mu_attr + sg_attr*draws_attr
randcoeff[["b_cost"]] = exp( mu_cost + sg_cost*draws_cost )
return(randcoeff)
}
Code: Select all
N = 1000
b_attr = rnorm(N, mean=model$estimate["mu_attr"], sd=model$estimate["sg_attr"])
b_cost = exp(rnorm(N, mean=model$estimate["mu_cost"], sd=model$estimate["sg_cost"]))
wtp_attr = b_attr/b_cost
mean(wtp_attr); sd(wtp_attr)
Daly, A.; Hess, S. and Train, K. (2012) Assuring finite moments for willingness to pay in random coefficient models. Transportation 39, 1931.
Cheers
David

 Posts: 6
 Joined: 03 Mar 2022, 18:36
Re: delta method to calculate WTP (normal and lognormal parameters)
Dear David,
I have a random parameter logit model with price parameter fixed and other nonprice parameters normally distributed. I used the function you provided above to calculate WTP, and things went well. However, it seems to me that I need to also calculate standard errors separately using another function, probably Apollobootstrap, right? I am a bit confused with your last statement saying ".....which will be the mean and s.e. of the WTP..."
My code is below. Note that since my price parameter is fixed, I didn't generate draws for it. Hope this is alright?
## calculating WTP after model estimation ##
N = 1000
qgreeR = rnorm(N, mean=model$estimate["qgree"], sd=model$estimate["sigma_qgree"])
cost = model$estimate["cost"]
wtp_attr = qgreeR/cost
wtp_attr
summary(wtp_attr)
mean(wtp_attr); sd(wtp_attr)
Thank you in advance.
/Mohammed
I have a random parameter logit model with price parameter fixed and other nonprice parameters normally distributed. I used the function you provided above to calculate WTP, and things went well. However, it seems to me that I need to also calculate standard errors separately using another function, probably Apollobootstrap, right? I am a bit confused with your last statement saying ".....which will be the mean and s.e. of the WTP..."
My code is below. Note that since my price parameter is fixed, I didn't generate draws for it. Hope this is alright?
## calculating WTP after model estimation ##
N = 1000
qgreeR = rnorm(N, mean=model$estimate["qgree"], sd=model$estimate["sigma_qgree"])
cost = model$estimate["cost"]
wtp_attr = qgreeR/cost
wtp_attr
summary(wtp_attr)
mean(wtp_attr); sd(wtp_attr)
Thank you in advance.
/Mohammed

 Site Admin
 Posts: 558
 Joined: 24 Apr 2020, 16:29
Re: delta method to calculate WTP (normal and lognormal parameters)
Mohammed
the new version of Apollo allows you to use the Delta method for any function of estimated model parameters. So if you can write down a closed form version of the mean and sd of your WTP on the basis of estimated parameters, then you can use the Delta method for standard errors thereof. Full details are in the manual.
If your cost coefficient is fixed and the other parameters are normal, then the WTP is normal too, with mean and sd simply given by the mean and sd of the noncost parameter divided by the fixed cost coefficient.
Stephane
the new version of Apollo allows you to use the Delta method for any function of estimated model parameters. So if you can write down a closed form version of the mean and sd of your WTP on the basis of estimated parameters, then you can use the Delta method for standard errors thereof. Full details are in the manual.
If your cost coefficient is fixed and the other parameters are normal, then the WTP is normal too, with mean and sd simply given by the mean and sd of the noncost parameter divided by the fixed cost coefficient.
Stephane

 Posts: 6
 Joined: 03 Mar 2022, 18:36
Re: delta method to calculate WTP (normal and lognormal parameters)
Hi Stephane,
Thanks indeed for your response.
Okay good to know this. Given that my model is specified in preference space where utility is linear in parameters, can't I just take the ratio of the nonprice attribute and the price attribute although the nonprice parameters are random? In the following code, the cost parameter is not random while the others are random:
deltaMethod_settings=list(expression=c(WTP_qgree_mix = "(qgree/cost)",
WTP_qblue_mix = "(qblue/cost)",
WTP_anglng_mix = "(anglng/cost)",
WTP_acess_mix = "(acess/cost)",
WTP_suround_mix = "(suround/cost)"))
apollo_deltaMethod(model, deltaMethod_settings)
/Mohammed
Thanks indeed for your response.
Okay good to know this. Given that my model is specified in preference space where utility is linear in parameters, can't I just take the ratio of the nonprice attribute and the price attribute although the nonprice parameters are random? In the following code, the cost parameter is not random while the others are random:
deltaMethod_settings=list(expression=c(WTP_qgree_mix = "(qgree/cost)",
WTP_qblue_mix = "(qblue/cost)",
WTP_anglng_mix = "(anglng/cost)",
WTP_acess_mix = "(acess/cost)",
WTP_suround_mix = "(suround/cost)"))
apollo_deltaMethod(model, deltaMethod_settings)
/Mohammed

 Site Admin
 Posts: 558
 Joined: 24 Apr 2020, 16:29
Re: delta method to calculate WTP (normal and lognormal parameters)
Mohammed
your WTP will be normal too, like I say, so there is a mean and a standard deviation. So if qblue is the mean of the coefficient, then qblue/cost is the mean of the WTP
Stephane
your WTP will be normal too, like I say, so there is a mean and a standard deviation. So if qblue is the mean of the coefficient, then qblue/cost is the mean of the WTP
Stephane

 Posts: 6
 Joined: 03 Mar 2022, 18:36
Re: delta method to calculate WTP (normal and lognormal parameters)
Thank you Stephane.
Yes, that is true, there is a SD as WTP is normal. But my question was really how to estimate the WTP in Apollo when you have random parameters in your model. Sorry if I misunderstood something here. As you said, I need to specify a closed form for the mean and sd to use the delta method, and I was not entirely sure if it is correct just to divided the nonrandom parameters by the nonrandom parameters (cost), the same for the sd. The example provided in the manual is for nonrandom parameters if I am not mistaken. One suggestion was to use simulation which is fine. Thanks for your time.
Yes, that is true, there is a SD as WTP is normal. But my question was really how to estimate the WTP in Apollo when you have random parameters in your model. Sorry if I misunderstood something here. As you said, I need to specify a closed form for the mean and sd to use the delta method, and I was not entirely sure if it is correct just to divided the nonrandom parameters by the nonrandom parameters (cost), the same for the sd. The example provided in the manual is for nonrandom parameters if I am not mistaken. One suggestion was to use simulation which is fine. Thanks for your time.

 Site Admin
 Posts: 558
 Joined: 24 Apr 2020, 16:29
Re: delta method to calculate WTP (normal and lognormal parameters)
Hi
you seem to be confusing two things here when you say about dividing the "nonrandom parameters". If your noncost coefficients follow a random distribution, then your WTP follows a random distribution too.
If the denominator of WTP is fixed, i.e. a nonrandom cost coefficient, then the WTP distribution always has defined moments, and you can just divide the random distribution by the fixed cost coefficient. You do not need the Delta method for that, the Delta method simply gives you the standard errors
Does this help?
Stephane
you seem to be confusing two things here when you say about dividing the "nonrandom parameters". If your noncost coefficients follow a random distribution, then your WTP follows a random distribution too.
If the denominator of WTP is fixed, i.e. a nonrandom cost coefficient, then the WTP distribution always has defined moments, and you can just divide the random distribution by the fixed cost coefficient. You do not need the Delta method for that, the Delta method simply gives you the standard errors
Does this help?
Stephane

 Posts: 6
 Joined: 03 Mar 2022, 18:36
Re: delta method to calculate WTP (normal and lognormal parameters)
Stephane, thanks really for your help. I appreciate it very much, it helps a lot.
Best,
Mohammed
Best,
Mohammed