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.
  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.

delta method to calculate WTP (normal and log-normal parameters)

Ask questions about post-estimation functions (e.g. prediction, conditionals, etc) or other processing of results.
Post Reply
Rea
Posts: 2
Joined: 21 Nov 2020, 13:06

delta method to calculate WTP (normal and log-normal parameters)

Post by Rea » 26 Apr 2021, 16:29

Dear apollo-team,

I estimated a mixed logit with the non-cost attributes beeing normally distributed and the cost attribute negative log-normal 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 delta-method between a normal distributed and a negative log-normal 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 non-cost-attributes? 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

dpalma
Posts: 125
Joined: 24 Apr 2020, 17:54

Re: delta method to calculate WTP (normal and log-normal parameters)

Post by dpalma » 10 May 2021, 17:48

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:

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)
}
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:

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)
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, 19-31.

Cheers
David

malemu588@gmail.com
Posts: 6
Joined: 03 Mar 2022, 18:36

Re: delta method to calculate WTP (normal and log-normal parameters)

Post by malemu588@gmail.com » 07 Mar 2022, 22:09

Dear David,

I have a random parameter logit model with price parameter fixed and other non-price 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 Apollo-bootstrap, 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

stephanehess
Site Admin
Posts: 558
Joined: 24 Apr 2020, 16:29

Re: delta method to calculate WTP (normal and log-normal parameters)

Post by stephanehess » 09 Mar 2022, 13:12

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 non-cost parameter divided by the fixed cost coefficient.

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

malemu588@gmail.com
Posts: 6
Joined: 03 Mar 2022, 18:36

Re: delta method to calculate WTP (normal and log-normal parameters)

Post by malemu588@gmail.com » 09 Mar 2022, 14:10

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 non-price attribute and the price attribute although the non-price 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

stephanehess
Site Admin
Posts: 558
Joined: 24 Apr 2020, 16:29

Re: delta method to calculate WTP (normal and log-normal parameters)

Post by stephanehess » 09 Mar 2022, 14:13

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
--------------------------------
Stephane Hess
www.stephanehess.me.uk

malemu588@gmail.com
Posts: 6
Joined: 03 Mar 2022, 18:36

Re: delta method to calculate WTP (normal and log-normal parameters)

Post by malemu588@gmail.com » 09 Mar 2022, 14:45

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 non-random parameters by the non-random parameters (cost), the same for the sd. The example provided in the manual is for non-random parameters if I am not mistaken. One suggestion was to use simulation which is fine. Thanks for your time.

stephanehess
Site Admin
Posts: 558
Joined: 24 Apr 2020, 16:29

Re: delta method to calculate WTP (normal and log-normal parameters)

Post by stephanehess » 09 Mar 2022, 14:52

Hi

you seem to be confusing two things here when you say about dividing the "non-random parameters". If your non-cost coefficients follow a random distribution, then your WTP follows a random distribution too.

If the denominator of WTP is fixed, i.e. a non-random 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
--------------------------------
Stephane Hess
www.stephanehess.me.uk

malemu588@gmail.com
Posts: 6
Joined: 03 Mar 2022, 18:36

Re: delta method to calculate WTP (normal and log-normal parameters)

Post by malemu588@gmail.com » 09 Mar 2022, 15:02

Stephane, thanks really for your help. I appreciate it very much, it helps a lot.

Best,
Mohammed

Post Reply