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. In addition, help files are available for all functions, using e.g. ?apollo_mnl
- 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.
parameter does not influence LL
parameter does not influence LL
Dear Apollo team,
I am working on a CNL with 12 alternatives. However, I face some challenges in specifying the asc. In your CNL example on the website, you defined acs of different travel modes based on the socioeconomic attributes. In my case, my alternatives are a combination of residential locations (e.g. urban, suburb, rural) and vehicle ownership (no vehicle, less than one vehicle per driver, etc). I do not have specific variables relating to the constants in mind. Therefore, I have fixed one asc to 0, but did not define others. However, the results say: the asc does not influence the likelihood (I saw this in the Q and A on the website). If I understand correctly, as long as I fixed one asc to 0, that is fine. The function will get the other ascs for me.
I look forward to your reply. Thank you!
Best,
Alex
I am working on a CNL with 12 alternatives. However, I face some challenges in specifying the asc. In your CNL example on the website, you defined acs of different travel modes based on the socioeconomic attributes. In my case, my alternatives are a combination of residential locations (e.g. urban, suburb, rural) and vehicle ownership (no vehicle, less than one vehicle per driver, etc). I do not have specific variables relating to the constants in mind. Therefore, I have fixed one asc to 0, but did not define others. However, the results say: the asc does not influence the likelihood (I saw this in the Q and A on the website). If I understand correctly, as long as I fixed one asc to 0, that is fine. The function will get the other ascs for me.
I look forward to your reply. Thank you!
Best,
Alex
-
- Site Admin
- Posts: 998
- Joined: 24 Apr 2020, 16:29
Re: alternative specific constant (asc) in CNL
Hi
please include your model specification/code so we can help you
Thanks
Stephane
please include your model specification/code so we can help you
Thanks
Stephane
Re: alternative specific constant (asc) in CNL
Thank you, Stephane. Please see my code for the model specification as follows (This is a cross-nested structure with two nests: residential location denoted by Ru (rural), SEC(secondary city), SUB(suburb), and URB (urban); car ownership denoted by D (car deficit), N (no car), S (car sufficient). All specifications for alternatives are the same except for the constants. I have fixed one constant to 0). Thank you for your help!
Specification:
### List of utilities: these must use the same names as in nl_settings, order is irrelevant
V = list()
V[['Ru_D']] = acs_Ru_D + b_age_65 * (age_65_74_1==1) + b_age_75 * (age_75_1==1) + b_AA * (race_AA_1==1) + b_HIS * (race_HIS_1==1) +
b_OTHERS * (race_OTHERS_1==1) + b_inc * (income_1) + b_med*(medc_1==1) + b_retire_o * (retire_one_1==1) +
b_retire_t * (retire_two_1==1) + b_alonem * (alonem_1==1) + b_alonef * (alonef_1==1)+ b_incm * (data$incomem_1==1)
V[['Ru_N']] = acs_Ru_N + b_age_65 * (age_65_74_2==1) + b_age_75 * (age_75_2==1) + b_AA * (race_AA_2==1) + b_HIS * (race_HIS_2==1) +
b_OTHERS * (race_OTHERS_2==1) + b_inc * (income_2) + b_med*(medc_2==1) + b_retire_o * (retire_one_2==1) +
b_retire_t * (retire_two_2==1) + b_alonem * (alonem_2==1) + b_alonef * (alonef_2==1)+ b_incm * (data$incomem_2==1)
V[['Ru_S']] = acs_Ru_S + b_age_65 * (age_65_74_3==1) + b_age_75 * (age_75_3==1) + b_AA * (race_AA_3==1) + b_HIS * (race_HIS_3==1) +
b_OTHERS * (race_OTHERS_3==1) + b_inc * (income_3) + b_med*(medc_3==1) + b_retire_o * (retire_one_3==1) +
b_retire_t * (retire_two_3==1) + b_alonem * (alonem_3==1) + b_alonef * (alonef_3==1)+ b_incm * (data$incomem_3==1)
V[['SEC_D']] = acs_SEC_D + b_age_65 * (age_65_74_4==1) + b_age_75 * (age_75_4==1) + b_AA * (race_AA_4==1) + b_HIS * (race_HIS_4==1) +
b_OTHERS * (race_OTHERS_4==1) + b_inc * (income_4) + b_med*(medc_4==1) + b_retire_o * (retire_one_4==1) +
b_retire_t * (retire_two_4==1) + b_alonem * (alonem_4==1) + b_alonef * (alonef_4==1)+ b_incm * (data$incomem_4==1)
V[['SEC_N']] = acs_SEC_N + b_age_65 * (age_65_74_5==1) + b_age_75 * (age_75_5==1) + b_AA * (race_AA_5==1) + b_HIS * (race_HIS_5==1) +
b_OTHERS * (race_OTHERS_5==1) + b_inc * (income_5) + b_med*(medc_5==1) + b_retire_o * (retire_one_5==1) +
b_retire_t * (retire_two_5==1) + b_alonem * (alonem_5==1) + b_alonef * (alonef_5==1)+ b_incm * (data$incomem_5==1)
V[['SEC_S']] = acs_SEC_S + b_age_65 * (age_65_74_6==1) + b_age_75 * (age_75_6==1) + b_AA * (race_AA_6==1) + b_HIS * (race_HIS_6==1) +
b_OTHERS * (race_OTHERS_6==1) + b_inc * (income_6) + b_med*(medc_6==1) + b_retire_o * (retire_one_6==1) +
b_retire_t * (retire_two_6==1) + b_alonem * (alonem_6==1) + b_alonef * (alonef_6==1)+ b_incm * (data$incomem_6==1)
V[['SUB_D']] = b_age_65 * (age_65_74_7==1) + b_age_75 * (age_75_7==1) + b_AA * (race_AA_7==1) + b_HIS * (race_HIS_7==1) +
b_OTHERS * (race_OTHERS_7==1) + b_inc * (income_7) + b_med*(medc_7==1) + b_retire_o * (retire_one_7==1) +
b_retire_t * (retire_two_7==1) + b_alonem * (alonem_7==1) + b_alonef * (alonef_7==1)+ b_incm * (data$incomem_7==1)
V[['SUB_N']] = acs_SUB_N + b_age_65 * (age_65_74_8==1) + b_age_75 * (age_75_8==1) + b_AA * (race_AA_8==1) + b_HIS * (race_HIS_8==1) +
b_OTHERS * (race_OTHERS_8==1) + b_inc * (income_8) + b_med*(medc_8==1) + b_retire_o * (retire_one_8==1) +
b_retire_t * (retire_two_8==1) + b_alonem * (alonem_8==1) + b_alonef * (alonef_8==1)+ b_incm * (data$incomem_8==1)
V[['SUB_S']] = acs_SUB_S + b_age_65 * (age_65_74_9==1) + b_age_75 * (age_75_9==1) + b_AA * (race_AA_9==1) + b_HIS * (race_HIS_9==1) +
b_OTHERS * (race_OTHERS_9==1) + b_inc * (income_9) + b_med*(medc_9==1) + b_retire_o * (retire_one_9==1) +
b_retire_t * (retire_two_9==1) + b_alonem * (alonem_9==1) + b_alonef * (alonef_9==1)+ b_incm * (data$incomem_9==1)
V[['URB_D']] = acs_URB_D + b_age_65 * (age_65_74_10==1) + b_age_75 * (age_75_10==1) + b_AA * (race_AA_10==1) + b_HIS * (race_HIS_10==1) +
b_OTHERS * (race_OTHERS_10==1) + b_inc * (income_10) + b_med*(medc_10==1) + b_retire_o * (retire_one_10==1) +
b_retire_t * (retire_two_10==1) + b_alonem * (alonem_10==1) + b_alonef * (alonef_10==1)+ b_incm * (data$incomem_10==1)
V[['URB_N']] = acs_URB_N + b_age_65 * (age_65_74_11==1) + b_age_75 * (age_75_11==1) + b_AA * (race_AA_11==1) + b_HIS * (race_HIS_11==1) +
b_OTHERS * (race_OTHERS_11==1) + b_inc * (income_11) + b_med*(medc_11==1) + b_retire_o * (retire_one_11==1) +
b_retire_t * (retire_two_11==1) + b_alonem * (alonem_11==1) + b_alonef * (alonef_11==1)+ b_incm * (data$incomem_11==1)
V[['URB_S']] = acs_URB_S + b_age_65 * (age_65_74_12==1) + b_age_75 * (age_75_12==1) + b_AA * (race_AA_12==1) + b_HIS * (race_HIS_12==1) +
b_OTHERS * (race_OTHERS_12==1) + b_inc * (income_12) + b_med*(medc_12==1) + b_retire_o * (retire_one_12==1) +
b_retire_t * (retire_two_12==1) + b_alonem * (alonem_12==1) + b_alonef * (alonef_12==1)+ b_incm * (data$incomem_12==1)
### Specify nests for CNL model
cnlNests = list(rural=lambda_rural, second=lambda_second,suburb=lambda_suburb,town=lambda_town,urban=lambda_urban,
DEF=lambda_DEF,NO=lambda_NO,SUF=lambda_SUF)
### Specify tree structure, showing membership in nests (one row per nest, one column per alternative)
cnlStructure = matrix(0, nrow=length(cnlNests), ncol=length(V))
cnlStructure[1,] = c(.5,.5,.5,0,0,0,0,0,0,0,0,0)
cnlStructure[2,] = c(0,0,0,.5,.5,.5,0,0,0,0,0,0)
cnlStructure[3,] = c(0,0,0,0,0,0,.5,.5,.5,0,0,0)
cnlStructure[4,] = c(0,0,0,0,0,0,0,0,0,.5,.5,.5)
cnlStructure[5,] = c(.5,0,0,.5,0,0,.5,0,0,.5,0,0)
cnlStructure[6,] = c(0,.5,0,0,.5,0,0,.5,0,0,.5,0)
cnlStructure[7,] = c(0,0,.5,0,0,.5,0,0,.5,0,0,.5)
### Define settings for NL model
cnl_settings <- list(
alternatives = c(Ru_D=1, Ru_N=2, Ru_S=3, SEC_D=4,SEC_N=5,SEC_S=6,
SUB_D=7, SUB_N=8, SUB_S=9, URB_D=10,URB_N=11,URB_S=12),
avail = list(Ru_D=av_Ru_D, Ru_N=av_Ru_N, Ru_S=av_Ru_S, SEC_D=av_SEC_D,SEC_N=av_SEC_N,SEC_S=av_SEC_S,
SUB_D=av_SUB_D, SUB_N=av_SUB_N, SUB_S=av_SUB_S,
URB_D=av_URB_D,URB_N=av_URB_N,URB_S=av_URB_S),
choiceVar = choice,
V = V,
cnlNests = cnlNests,
cnlStructure = cnlStructure
)
Specification:
### List of utilities: these must use the same names as in nl_settings, order is irrelevant
V = list()
V[['Ru_D']] = acs_Ru_D + b_age_65 * (age_65_74_1==1) + b_age_75 * (age_75_1==1) + b_AA * (race_AA_1==1) + b_HIS * (race_HIS_1==1) +
b_OTHERS * (race_OTHERS_1==1) + b_inc * (income_1) + b_med*(medc_1==1) + b_retire_o * (retire_one_1==1) +
b_retire_t * (retire_two_1==1) + b_alonem * (alonem_1==1) + b_alonef * (alonef_1==1)+ b_incm * (data$incomem_1==1)
V[['Ru_N']] = acs_Ru_N + b_age_65 * (age_65_74_2==1) + b_age_75 * (age_75_2==1) + b_AA * (race_AA_2==1) + b_HIS * (race_HIS_2==1) +
b_OTHERS * (race_OTHERS_2==1) + b_inc * (income_2) + b_med*(medc_2==1) + b_retire_o * (retire_one_2==1) +
b_retire_t * (retire_two_2==1) + b_alonem * (alonem_2==1) + b_alonef * (alonef_2==1)+ b_incm * (data$incomem_2==1)
V[['Ru_S']] = acs_Ru_S + b_age_65 * (age_65_74_3==1) + b_age_75 * (age_75_3==1) + b_AA * (race_AA_3==1) + b_HIS * (race_HIS_3==1) +
b_OTHERS * (race_OTHERS_3==1) + b_inc * (income_3) + b_med*(medc_3==1) + b_retire_o * (retire_one_3==1) +
b_retire_t * (retire_two_3==1) + b_alonem * (alonem_3==1) + b_alonef * (alonef_3==1)+ b_incm * (data$incomem_3==1)
V[['SEC_D']] = acs_SEC_D + b_age_65 * (age_65_74_4==1) + b_age_75 * (age_75_4==1) + b_AA * (race_AA_4==1) + b_HIS * (race_HIS_4==1) +
b_OTHERS * (race_OTHERS_4==1) + b_inc * (income_4) + b_med*(medc_4==1) + b_retire_o * (retire_one_4==1) +
b_retire_t * (retire_two_4==1) + b_alonem * (alonem_4==1) + b_alonef * (alonef_4==1)+ b_incm * (data$incomem_4==1)
V[['SEC_N']] = acs_SEC_N + b_age_65 * (age_65_74_5==1) + b_age_75 * (age_75_5==1) + b_AA * (race_AA_5==1) + b_HIS * (race_HIS_5==1) +
b_OTHERS * (race_OTHERS_5==1) + b_inc * (income_5) + b_med*(medc_5==1) + b_retire_o * (retire_one_5==1) +
b_retire_t * (retire_two_5==1) + b_alonem * (alonem_5==1) + b_alonef * (alonef_5==1)+ b_incm * (data$incomem_5==1)
V[['SEC_S']] = acs_SEC_S + b_age_65 * (age_65_74_6==1) + b_age_75 * (age_75_6==1) + b_AA * (race_AA_6==1) + b_HIS * (race_HIS_6==1) +
b_OTHERS * (race_OTHERS_6==1) + b_inc * (income_6) + b_med*(medc_6==1) + b_retire_o * (retire_one_6==1) +
b_retire_t * (retire_two_6==1) + b_alonem * (alonem_6==1) + b_alonef * (alonef_6==1)+ b_incm * (data$incomem_6==1)
V[['SUB_D']] = b_age_65 * (age_65_74_7==1) + b_age_75 * (age_75_7==1) + b_AA * (race_AA_7==1) + b_HIS * (race_HIS_7==1) +
b_OTHERS * (race_OTHERS_7==1) + b_inc * (income_7) + b_med*(medc_7==1) + b_retire_o * (retire_one_7==1) +
b_retire_t * (retire_two_7==1) + b_alonem * (alonem_7==1) + b_alonef * (alonef_7==1)+ b_incm * (data$incomem_7==1)
V[['SUB_N']] = acs_SUB_N + b_age_65 * (age_65_74_8==1) + b_age_75 * (age_75_8==1) + b_AA * (race_AA_8==1) + b_HIS * (race_HIS_8==1) +
b_OTHERS * (race_OTHERS_8==1) + b_inc * (income_8) + b_med*(medc_8==1) + b_retire_o * (retire_one_8==1) +
b_retire_t * (retire_two_8==1) + b_alonem * (alonem_8==1) + b_alonef * (alonef_8==1)+ b_incm * (data$incomem_8==1)
V[['SUB_S']] = acs_SUB_S + b_age_65 * (age_65_74_9==1) + b_age_75 * (age_75_9==1) + b_AA * (race_AA_9==1) + b_HIS * (race_HIS_9==1) +
b_OTHERS * (race_OTHERS_9==1) + b_inc * (income_9) + b_med*(medc_9==1) + b_retire_o * (retire_one_9==1) +
b_retire_t * (retire_two_9==1) + b_alonem * (alonem_9==1) + b_alonef * (alonef_9==1)+ b_incm * (data$incomem_9==1)
V[['URB_D']] = acs_URB_D + b_age_65 * (age_65_74_10==1) + b_age_75 * (age_75_10==1) + b_AA * (race_AA_10==1) + b_HIS * (race_HIS_10==1) +
b_OTHERS * (race_OTHERS_10==1) + b_inc * (income_10) + b_med*(medc_10==1) + b_retire_o * (retire_one_10==1) +
b_retire_t * (retire_two_10==1) + b_alonem * (alonem_10==1) + b_alonef * (alonef_10==1)+ b_incm * (data$incomem_10==1)
V[['URB_N']] = acs_URB_N + b_age_65 * (age_65_74_11==1) + b_age_75 * (age_75_11==1) + b_AA * (race_AA_11==1) + b_HIS * (race_HIS_11==1) +
b_OTHERS * (race_OTHERS_11==1) + b_inc * (income_11) + b_med*(medc_11==1) + b_retire_o * (retire_one_11==1) +
b_retire_t * (retire_two_11==1) + b_alonem * (alonem_11==1) + b_alonef * (alonef_11==1)+ b_incm * (data$incomem_11==1)
V[['URB_S']] = acs_URB_S + b_age_65 * (age_65_74_12==1) + b_age_75 * (age_75_12==1) + b_AA * (race_AA_12==1) + b_HIS * (race_HIS_12==1) +
b_OTHERS * (race_OTHERS_12==1) + b_inc * (income_12) + b_med*(medc_12==1) + b_retire_o * (retire_one_12==1) +
b_retire_t * (retire_two_12==1) + b_alonem * (alonem_12==1) + b_alonef * (alonef_12==1)+ b_incm * (data$incomem_12==1)
### Specify nests for CNL model
cnlNests = list(rural=lambda_rural, second=lambda_second,suburb=lambda_suburb,town=lambda_town,urban=lambda_urban,
DEF=lambda_DEF,NO=lambda_NO,SUF=lambda_SUF)
### Specify tree structure, showing membership in nests (one row per nest, one column per alternative)
cnlStructure = matrix(0, nrow=length(cnlNests), ncol=length(V))
cnlStructure[1,] = c(.5,.5,.5,0,0,0,0,0,0,0,0,0)
cnlStructure[2,] = c(0,0,0,.5,.5,.5,0,0,0,0,0,0)
cnlStructure[3,] = c(0,0,0,0,0,0,.5,.5,.5,0,0,0)
cnlStructure[4,] = c(0,0,0,0,0,0,0,0,0,.5,.5,.5)
cnlStructure[5,] = c(.5,0,0,.5,0,0,.5,0,0,.5,0,0)
cnlStructure[6,] = c(0,.5,0,0,.5,0,0,.5,0,0,.5,0)
cnlStructure[7,] = c(0,0,.5,0,0,.5,0,0,.5,0,0,.5)
### Define settings for NL model
cnl_settings <- list(
alternatives = c(Ru_D=1, Ru_N=2, Ru_S=3, SEC_D=4,SEC_N=5,SEC_S=6,
SUB_D=7, SUB_N=8, SUB_S=9, URB_D=10,URB_N=11,URB_S=12),
avail = list(Ru_D=av_Ru_D, Ru_N=av_Ru_N, Ru_S=av_Ru_S, SEC_D=av_SEC_D,SEC_N=av_SEC_N,SEC_S=av_SEC_S,
SUB_D=av_SUB_D, SUB_N=av_SUB_N, SUB_S=av_SUB_S,
URB_D=av_URB_D,URB_N=av_URB_N,URB_S=av_URB_S),
choiceVar = choice,
V = V,
cnlNests = cnlNests,
cnlStructure = cnlStructure
)
-
- Site Admin
- Posts: 998
- Joined: 24 Apr 2020, 16:29
Re: alternative specific constant (asc) in CNL
Thanks, could you please also show the output you're receiving, and confirm which version of Apollo you are using
Re: alternative specific constant (asc) in CNL
Hi Stephan,
Here is my output:
Testing likelihood function...
Overview of choices for CNL model component :
Ru_D Ru_N Ru_S SEC_D SEC_N SEC_S SUB_D SUB_N SUB_S URB_D URB_N URB_S
Times available 2685.00 819 37156.00 1398.0 893.00 13148.00 1284.00 463.00 15871.00 1015.00 818 6562.00
Times chosen 2685.00 819 37156.00 1398.0 893.00 13148.00 1284.00 463.00 15871.00 1015.00 818 6562.00
Percentage chosen overall 3.27 1 45.25 1.7 1.09 16.01 1.56 0.56 19.33 1.24 1 7.99
Percentage chosen when available 100.00 100 100.00 100.0 100.00 100.00 100.00 100.00 100.00 100.00 100 100.00
Structure for CNL model component :
Ru_D (alpha) Ru_N (alpha) Ru_S (alpha) SEC_D (alpha) SEC_N (alpha) SEC_S (alpha) SUB_D (alpha) SUB_N (alpha) SUB_S (alpha)
rural nest 0.5000 0.5000 0.5000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
second nest 0.0000 0.0000 0.0000 0.5000 0.5000 0.5000 0.0000 0.0000 0.0000
suburb nest 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.5000 0.5000 0.5000
town nest 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
urban nest 0.5000 0.0000 0.0000 0.5000 0.0000 0.0000 0.5000 0.0000 0.0000
DEF nest 0.0000 0.5000 0.0000 0.0000 0.5000 0.0000 0.0000 0.5000 0.0000
NO nest 0.0000 0.0000 0.5000 0.0000 0.0000 0.5000 0.0000 0.0000 0.5000
SUF nest 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
URB_D (alpha) URB_N (alpha) URB_S (alpha) lambda
rural nest 0.0000 0.0000 0.0000 0.9500
second nest 0.0000 0.0000 0.0000 0.9500
suburb nest 0.0000 0.0000 0.0000 0.9500
town nest 0.5000 0.5000 0.5000 0.9500
urban nest 0.5000 0.0000 0.0000 0.9500
DEF nest 0.0000 0.5000 0.0000 0.9500
NO nest 0.0000 0.0000 0.5000 0.9500
SUF nest 0.0000 0.0000 0.0000 0.9500
Pre-processing likelihood function...
Testing influence of parametersError in apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, :
Parameter acs_Ru_N does not influence the log-likelihood of your model!
>
It works in some steps, but stops due to the constant. I wonder whether there is something wrong with my specification of the constant, but I assume that it is fine to define constants without specifications.
I use the version Apollo 0.2.4 (I guess it is the latest?)
Thank you!
Best,
Alex
Here is my output:
Testing likelihood function...
Overview of choices for CNL model component :
Ru_D Ru_N Ru_S SEC_D SEC_N SEC_S SUB_D SUB_N SUB_S URB_D URB_N URB_S
Times available 2685.00 819 37156.00 1398.0 893.00 13148.00 1284.00 463.00 15871.00 1015.00 818 6562.00
Times chosen 2685.00 819 37156.00 1398.0 893.00 13148.00 1284.00 463.00 15871.00 1015.00 818 6562.00
Percentage chosen overall 3.27 1 45.25 1.7 1.09 16.01 1.56 0.56 19.33 1.24 1 7.99
Percentage chosen when available 100.00 100 100.00 100.0 100.00 100.00 100.00 100.00 100.00 100.00 100 100.00
Structure for CNL model component :
Ru_D (alpha) Ru_N (alpha) Ru_S (alpha) SEC_D (alpha) SEC_N (alpha) SEC_S (alpha) SUB_D (alpha) SUB_N (alpha) SUB_S (alpha)
rural nest 0.5000 0.5000 0.5000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
second nest 0.0000 0.0000 0.0000 0.5000 0.5000 0.5000 0.0000 0.0000 0.0000
suburb nest 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.5000 0.5000 0.5000
town nest 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
urban nest 0.5000 0.0000 0.0000 0.5000 0.0000 0.0000 0.5000 0.0000 0.0000
DEF nest 0.0000 0.5000 0.0000 0.0000 0.5000 0.0000 0.0000 0.5000 0.0000
NO nest 0.0000 0.0000 0.5000 0.0000 0.0000 0.5000 0.0000 0.0000 0.5000
SUF nest 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
URB_D (alpha) URB_N (alpha) URB_S (alpha) lambda
rural nest 0.0000 0.0000 0.0000 0.9500
second nest 0.0000 0.0000 0.0000 0.9500
suburb nest 0.0000 0.0000 0.0000 0.9500
town nest 0.5000 0.5000 0.5000 0.9500
urban nest 0.5000 0.0000 0.0000 0.9500
DEF nest 0.0000 0.5000 0.0000 0.9500
NO nest 0.0000 0.0000 0.5000 0.9500
SUF nest 0.0000 0.0000 0.0000 0.9500
Pre-processing likelihood function...
Testing influence of parametersError in apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, :
Parameter acs_Ru_N does not influence the log-likelihood of your model!
>
It works in some steps, but stops due to the constant. I wonder whether there is something wrong with my specification of the constant, but I assume that it is fine to define constants without specifications.
I use the version Apollo 0.2.4 (I guess it is the latest?)
Thank you!
Best,
Alex
-
- Site Admin
- Posts: 998
- Joined: 24 Apr 2020, 16:29
Re: alternative specific constant (asc) in CNL
Hi Alex
the problem is not your ASCs, actually. The problem is clearly visible from this part of the output
You seem to have set up the model in such a way that in each observation, only a single alternative is available, as reflected in the final line of this output. There is no model to be estimated in that case
Stephane
the problem is not your ASCs, actually. The problem is clearly visible from this part of the output
Code: Select all
Times available 2685.00 819 37156.00 1398.0 893.00 13148.00 1284.00 463.00 15871.00 1015.00 818 6562.00
Times chosen 2685.00 819 37156.00 1398.0 893.00 13148.00 1284.00 463.00 15871.00 1015.00 818 6562.00
Percentage chosen overall 3.27 1 45.25 1.7 1.09 16.01 1.56 0.56 19.33 1.24 1 7.99
Percentage chosen when available 100.00 100 100.00 100.0 100.00 100.00 100.00 100.00 100.00 100.00 100 100.00
Stephane
Re: parameter does not influence LL
Hi Stephane,
You are correct. I just debugged, and found out that I falsely set my availabilities. I should set full availability. Now, every observation has full flexibility of choices, however, the same error message still shows up. I just paste the result here:
I wonder what I did wrongly. So let us assume that it is not the problem of the asc. I compared my codes with yours very carefully, and found that what I did differently is that I did not set the alpha function. I simply let the allocation parameters to be 0 or 0.5, as what you did in your paper published on Transportation, and many other transportation planners. So I guess Apollo will not consider that as a problem. I just copy/paste my code here so that you can see clearly what is evidently wrong:
Thank you,
Alex
You are correct. I just debugged, and found out that I falsely set my availabilities. I should set full availability. Now, every observation has full flexibility of choices, however, the same error message still shows up. I just paste the result here:
Code: Select all
Testing likelihood function...
Setting "avail" is missing, so full availability is assumed.
WARNING: Availability not provided (or some elements are NA). Full availability assumed.
Overview of choices for CNL model component :
Ru_D Ru_N Ru_S SEC_D SEC_N SEC_S SUB_D SUB_N SUB_S URB_D URB_N URB_S
Times available 82112.00 82112 82112.00 82112.0 82112.00 82112.00 82112.00 82112.00 82112.00 82112.00 82112 82112.00
Times chosen 2685.00 819 37156.00 1398.0 893.00 13148.00 1284.00 463.00 15871.00 1015.00 818 6562.00
Percentage chosen overall 3.27 1 45.25 1.7 1.09 16.01 1.56 0.56 19.33 1.24 1 7.99
Percentage chosen when available 3.27 1 45.25 1.7 1.09 16.01 1.56 0.56 19.33 1.24 1 7.99
Structure for CNL model component :
Ru_D (alpha) Ru_N (alpha) Ru_S (alpha) SEC_D (alpha) SEC_N (alpha) SEC_S (alpha) SUB_D (alpha) SUB_N (alpha) SUB_S (alpha)
rural nest 0.5000 0.5000 0.5000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
second nest 0.0000 0.0000 0.0000 0.5000 0.5000 0.5000 0.0000 0.0000 0.0000
suburb nest 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.5000 0.5000 0.5000
town nest 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
urban nest 0.5000 0.0000 0.0000 0.5000 0.0000 0.0000 0.5000 0.0000 0.0000
DEF nest 0.0000 0.5000 0.0000 0.0000 0.5000 0.0000 0.0000 0.5000 0.0000
NO nest 0.0000 0.0000 0.5000 0.0000 0.0000 0.5000 0.0000 0.0000 0.5000
SUF nest 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
URB_D (alpha) URB_N (alpha) URB_S (alpha) lambda
rural nest 0.0000 0.0000 0.0000 0.9500
second nest 0.0000 0.0000 0.0000 0.9500
suburb nest 0.0000 0.0000 0.0000 0.9500
town nest 0.5000 0.5000 0.5000 0.9500
urban nest 0.5000 0.0000 0.0000 0.9500
DEF nest 0.0000 0.5000 0.0000 0.9500
NO nest 0.0000 0.0000 0.5000 0.9500
SUF nest 0.0000 0.0000 0.0000 0.9500
Pre-processing likelihood function...
Testing influence of parameters..........Error in apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, :
Parameter b_age_65 does not influence the log-likelihood of your model!
Code: Select all
apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){
### 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 nl_settings, order is irrelevant
V = list()
V[['Ru_D']] = acs_Ru_D + b_age_65 * (age_65_74==1) + b_age_75 * (age_75==1) + b_AA * (race_AA==1) + b_HIS * (race_HIS==1) +
b_OTHERS * (race_OTHERS==1) + b_inc * (income) + b_med*(medc==1) + b_retire_o * (retire_one==1) +
b_retire_t * (retire_two==1) + b_alonem * (alonem==1) + b_alonef * (alonef==1)+ b_incm * (data$incomem==1)
V[['Ru_N']] = acs_Ru_N + b_age_65 * (age_65_74==1) + b_age_75 * (age_75==1) + b_AA * (race_AA==1) + b_HIS * (race_HIS==1) +
b_OTHERS * (race_OTHERS==1) + b_inc * (income) + b_med*(medc==1) + b_retire_o * (retire_one==1) +
b_retire_t * (retire_two==1) + b_alonem * (alonem==1) + b_alonef * (alonef==1)+ b_incm * (data$incomem==1)
V[['Ru_S']] = acs_Ru_S + b_age_65 * (age_65_74==1) + b_age_75 * (age_75==1) + b_AA * (race_AA==1) + b_HIS * (race_HIS==1) +
b_OTHERS * (race_OTHERS==1) + b_inc * (income) + b_med*(medc==1) + b_retire_o * (retire_one==1) +
b_retire_t * (retire_two==1) + b_alonem * (alonem==1) + b_alonef * (alonef==1)+ b_incm * (data$incomem==1)
V[['SEC_D']] = acs_SEC_D + b_age_65 * (age_65_74==1) + b_age_75 * (age_75==1) + b_AA * (race_AA==1) + b_HIS * (race_HIS==1) +
b_OTHERS * (race_OTHERS==1) + b_inc * (income) + b_med*(medc==1) + b_retire_o * (retire_one==1) +
b_retire_t * (retire_two==1) + b_alonem * (alonem==1) + b_alonef * (alonef==1)+ b_incm * (data$incomem==1)
V[['SEC_N']] = acs_SEC_N + b_age_65 * (age_65_74==1) + b_age_75 * (age_75==1) + b_AA * (race_AA==1) + b_HIS * (race_HIS==1) +
b_OTHERS * (race_OTHERS==1) + b_inc * (income) + b_med*(medc==1) + b_retire_o * (retire_one==1) +
b_retire_t * (retire_two==1) + b_alonem * (alonem==1) + b_alonef * (alonef==1)+ b_incm * (data$incomem==1)
V[['SEC_S']] = acs_SEC_S + b_age_65 * (age_65_74==1) + b_age_75 * (age_75==1) + b_AA * (race_AA==1) + b_HIS * (race_HIS==1) +
b_OTHERS * (race_OTHERS==1) + b_inc * (income) + b_med*(medc==1) + b_retire_o * (retire_one==1) +
b_retire_t * (retire_two==1) + b_alonem * (alonem==1) + b_alonef * (alonef==1)+ b_incm * (data$incomem==1)
V[['SUB_D']] = b_age_65 * (age_65_74==1) + b_age_75 * (age_75==1) + b_AA * (race_AA==1) + b_HIS * (race_HIS==1) +
b_OTHERS * (race_OTHERS==1) + b_inc * (income) + b_med*(medc==1) + b_retire_o * (retire_one==1) +
b_retire_t * (retire_two==1) + b_alonem * (alonem==1) + b_alonef * (alonef==1)+ b_incm * (data$incomem==1)
V[['SUB_N']] = acs_SUB_N + b_age_65 * (age_65_74==1) + b_age_75 * (age_75==1) + b_AA * (race_AA==1) + b_HIS * (race_HIS==1) +
b_OTHERS * (race_OTHERS==1) + b_inc * (income) + b_med*(medc==1) + b_retire_o * (retire_one==1) +
b_retire_t * (retire_two==1) + b_alonem * (alonem==1) + b_alonef * (alonef==1)+ b_incm * (data$incomem==1)
V[['SUB_S']] = acs_SUB_S + b_age_65 * (age_65_74==1) + b_age_75 * (age_75==1) + b_AA * (race_AA==1) + b_HIS * (race_HIS==1) +
b_OTHERS * (race_OTHERS==1) + b_inc * (income) + b_med*(medc==1) + b_retire_o * (retire_one==1) +
b_retire_t * (retire_two==1) + b_alonem * (alonem==1) + b_alonef * (alonef==1)+ b_incm * (data$incomem==1)
V[['URB_D']] = acs_URB_D + b_age_65 * (age_65_74==1) + b_age_75 * (age_75==1) + b_AA * (race_AA==1) + b_HIS * (race_HIS==1) +
b_OTHERS * (race_OTHERS==1) + b_inc * (income) + b_med*(medc==1) + b_retire_o * (retire_one==1) +
b_retire_t * (retire_two==1) + b_alonem * (alonem==1) + b_alonef * (alonef==1)+ b_incm * (data$incomem==1)
V[['URB_N']] = acs_URB_N + b_age_65 * (age_65_74==1) + b_age_75 * (age_75==1) + b_AA * (race_AA==1) + b_HIS * (race_HIS==1) +
b_OTHERS * (race_OTHERS==1) + b_inc * (income) + b_med*(medc==1) + b_retire_o * (retire_one==1) +
b_retire_t * (retire_two==1) + b_alonem * (alonem==1) + b_alonef * (alonef==1)+ b_incm * (data$incomem==1)
V[['URB_S']] = acs_URB_S + b_age_65 * (age_65_74==1) + b_age_75 * (age_75==1) + b_AA * (race_AA==1) + b_HIS * (race_HIS==1) +
b_OTHERS * (race_OTHERS==1) + b_inc * (income) + b_med*(medc==1) + b_retire_o * (retire_one==1) +
b_retire_t * (retire_two==1) + b_alonem * (alonem==1) + b_alonef * (alonef==1)+ b_incm * (data$incomem==1)
### Specify nests for CNL model
cnlNests = list(rural=lambda_rural, second=lambda_second,suburb=lambda_suburb,town=lambda_town,urban=lambda_urban,
DEF=lambda_DEF,NO=lambda_NO,SUF=lambda_SUF)
### Specify tree structure, showing membership in nests (one row per nest, one column per alternative)
cnlStructure = matrix(0, nrow=length(cnlNests), ncol=length(V))
cnlStructure[1,] = c(.5,.5,.5,0,0,0,0,0,0,0,0,0)
cnlStructure[2,] = c(0,0,0,.5,.5,.5,0,0,0,0,0,0)
cnlStructure[3,] = c(0,0,0,0,0,0,.5,.5,.5,0,0,0)
cnlStructure[4,] = c(0,0,0,0,0,0,0,0,0,.5,.5,.5)
cnlStructure[5,] = c(.5,0,0,.5,0,0,.5,0,0,.5,0,0)
cnlStructure[6,] = c(0,.5,0,0,.5,0,0,.5,0,0,.5,0)
cnlStructure[7,] = c(0,0,.5,0,0,.5,0,0,.5,0,0,.5)
### Define settings for NL model
cnl_settings <- list(
alternatives = c(Ru_D=1, Ru_N=2, Ru_S=3, SEC_D=4,SEC_N=5,SEC_S=6,
SUB_D=7, SUB_N=8, SUB_S=9, URB_D=10,URB_N=11,URB_S=12),
choiceVar = choice,
V = V,
cnlNests = cnlNests,
cnlStructure = cnlStructure
)
### Compute probabilities using CNL model
P[["model"]] = apollo_cnl(cnl_settings, functionality)
### Prepare and return outputs of function
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}
Alex
-
- Site Admin
- Posts: 998
- Joined: 24 Apr 2020, 16:29
Re: parameter does not influence LL
Alex
from what I can see, you have included b_age_65 * (age_65_74==1) in every utility function. Then it will just drop out of the model, that's why you're getting that message. You can't estimate a value for a parameter that multiplies the exact same value in each utility function
Stephane
from what I can see, you have included b_age_65 * (age_65_74==1) in every utility function. Then it will just drop out of the model, that's why you're getting that message. You can't estimate a value for a parameter that multiplies the exact same value in each utility function
Stephane
Re: parameter does not influence LL
Hi Stephane,
That is interesting. I would appreciate it if you can further elaborate. Let me explain further what I am trying to do here. As I can see from the manual, I should change all categorical variables to dummy variables. As you can see in my specifications, this is what I did, and I just dropped of one category to avoid multilinearity. For example, whether a person's age is 55-64, 65-74, or 75 and over affect the utility of all alternatives. Therefore, I just include the dummy of being the age group of 65-74 and 75 and over in my specification. This is what I want to do. And the error message comes. In this case, did I do anything wrong? How should I include the categorical variables in the specifications?
Thank you,
Alex
That is interesting. I would appreciate it if you can further elaborate. Let me explain further what I am trying to do here. As I can see from the manual, I should change all categorical variables to dummy variables. As you can see in my specifications, this is what I did, and I just dropped of one category to avoid multilinearity. For example, whether a person's age is 55-64, 65-74, or 75 and over affect the utility of all alternatives. Therefore, I just include the dummy of being the age group of 65-74 and 75 and over in my specification. This is what I want to do. And the error message comes. In this case, did I do anything wrong? How should I include the categorical variables in the specifications?
Thank you,
Alex
-
- Site Admin
- Posts: 998
- Joined: 24 Apr 2020, 16:29
Re: parameter does not influence LL
Alex
it is of course a requirement to apply a normalisation to a categorical variable, which is what you do here by dummy coding it, as only differences across levels matter. However, an essential characteristics of random utility models is that only differences in utility matter. If you include the term b_age_65 * (age_65_74==1) in the utility for each alternative, with the same parameter, then it cannot uncover any differences across the alternatives. Is your aim to test whether the mode preferences depend on age? If so, you will need to make these age parameters mode specific too, just like your alternative specific constants, and set them to zero for one mode
Stephane
it is of course a requirement to apply a normalisation to a categorical variable, which is what you do here by dummy coding it, as only differences across levels matter. However, an essential characteristics of random utility models is that only differences in utility matter. If you include the term b_age_65 * (age_65_74==1) in the utility for each alternative, with the same parameter, then it cannot uncover any differences across the alternatives. Is your aim to test whether the mode preferences depend on age? If so, you will need to make these age parameters mode specific too, just like your alternative specific constants, and set them to zero for one mode
Stephane