mixed logit model with truncated normal distribution
Posted: 19 Jun 2021, 21:34
Dear sir or madam,
Hi, I am trying to estimate mixed logit model w/ truncated normal distribution.
I made code based on example 14.
I had no problem when estimating mixed logit model w/ normal distribution or lognormal distribution. But confronted problem w/ truncated normal distribution.
I used truncated normal distribution random parameter reference with the previous apollo forum (https://groups.google.com/g/apollo-choi ... qyGEJsBQAJ)
I came up with "Error in value[[3L]](cond)" error during apollo_estimate().
Here's my code of random parameter part.
### Set parameters for generating draws
apollo_draws = list(
interDrawsType = "halton",
interNDraws = 500,
# interUnifDraws = c(),
interUnifDraws = c("eta1", "eta2"),
interNormDraws = c(),
# interNormDraws = c("draws_time","draws_fee"),
intraDrawsType = "halton",
intraNDraws = 0,
intraUnifDraws = c(),
intraNormDraws = c()
)
### Create random parameters
apollo_randCoeff = function(apollo_beta, apollo_inputs){
## truncated norm setting.
time_lower = pnorm(-Inf, mean=mu_beta_time, sd=sigma_beta_time)
time_upper = pnorm(0, mean=mu_beta_time, sd=sigma_beta_time)
fee_lower = pnorm(-Inf, mean=mu_beta_fee, sd=sigma_beta_fee)
fee_upper = pnorm(0, mean=mu_beta_fee, sd=sigma_beta_fee)
randcoeff = list()
## lognorm
# randcoeff[["beta_time_rd"]] = -exp( mu_beta_time + sigma_beta_time * draws_time )
# randcoeff[["beta_fee_rd"]] = -exp( mu_beta_fee + sigma_beta_fee * draws_fee )
## norm
# randcoeff[["beta_time_rd"]] = mu_beta_time + sigma_beta_time * draws_time
# randcoeff[["beta_fee_rd"]] = mu_beta_fee + sigma_beta_fee * draws_fee
## truncated norm variable
randcoeff[['beta_time_rd']] = qnorm(time_lower + eta1*(time_upper-time_lower), mu_beta_time, sigma_beta_time)
randcoeff[['beta_fee_rd']] = qnorm(fee_lower + eta2*(fee_upper-fee_lower), mu_beta_fee, sigma_beta_fee)
return(randcoeff)
}
Can you tell me what's wrong with my code? Thanks!
Best regards,
Hong
Hi, I am trying to estimate mixed logit model w/ truncated normal distribution.
I made code based on example 14.
I had no problem when estimating mixed logit model w/ normal distribution or lognormal distribution. But confronted problem w/ truncated normal distribution.
I used truncated normal distribution random parameter reference with the previous apollo forum (https://groups.google.com/g/apollo-choi ... qyGEJsBQAJ)
I came up with "Error in value[[3L]](cond)" error during apollo_estimate().
Here's my code of random parameter part.
### Set parameters for generating draws
apollo_draws = list(
interDrawsType = "halton",
interNDraws = 500,
# interUnifDraws = c(),
interUnifDraws = c("eta1", "eta2"),
interNormDraws = c(),
# interNormDraws = c("draws_time","draws_fee"),
intraDrawsType = "halton",
intraNDraws = 0,
intraUnifDraws = c(),
intraNormDraws = c()
)
### Create random parameters
apollo_randCoeff = function(apollo_beta, apollo_inputs){
## truncated norm setting.
time_lower = pnorm(-Inf, mean=mu_beta_time, sd=sigma_beta_time)
time_upper = pnorm(0, mean=mu_beta_time, sd=sigma_beta_time)
fee_lower = pnorm(-Inf, mean=mu_beta_fee, sd=sigma_beta_fee)
fee_upper = pnorm(0, mean=mu_beta_fee, sd=sigma_beta_fee)
randcoeff = list()
## lognorm
# randcoeff[["beta_time_rd"]] = -exp( mu_beta_time + sigma_beta_time * draws_time )
# randcoeff[["beta_fee_rd"]] = -exp( mu_beta_fee + sigma_beta_fee * draws_fee )
## norm
# randcoeff[["beta_time_rd"]] = mu_beta_time + sigma_beta_time * draws_time
# randcoeff[["beta_fee_rd"]] = mu_beta_fee + sigma_beta_fee * draws_fee
## truncated norm variable
randcoeff[['beta_time_rd']] = qnorm(time_lower + eta1*(time_upper-time_lower), mu_beta_time, sigma_beta_time)
randcoeff[['beta_fee_rd']] = qnorm(fee_lower + eta2*(fee_upper-fee_lower), mu_beta_fee, sigma_beta_fee)
return(randcoeff)
}
Can you tell me what's wrong with my code? Thanks!
Best regards,
Hong