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.

Some levels in 'outcomeOrdered' do not exist in 'coding' for model component

Ask questions about model specifications. Ideally include a mathematical explanation of your proposed model.
Post Reply
infiniteugi
Posts: 7
Joined: 02 Feb 2021, 07:06

Some levels in 'outcomeOrdered' do not exist in 'coding' for model component

Post by infiniteugi »

I got an error message like, "Some levels in 'outcomeOrdered' do not exist in 'coding' for model component "Ind_PT01" !

My code is written as:

Code: Select all

ol_PT01 = list(outcomeOrdered=PT01, 
                 V=zeta_PT01*LV_tl, 
                 tau=c(tau_PT01_1, tau_PT01_2, tau_PT01_3, tau_PT01_4),
                 rows=((PT01!=-99) & (Exp==1)),
                 componentName  = "Ind_PT01")
Note:
Variable PT01 has the following values: [-99, 1, 2, 3, 4, 5], and -99 should be read N/A.

Could anyone help me resolve this error?
dpalma
Posts: 190
Joined: 24 Apr 2020, 17:54

Re: Some levels in 'outcomeOrdered' do not exist in 'coding' for model component

Post by dpalma »

Hi,

First, I would recommend updating to Apollo v0.2.5. This version is not yet on CRAN, but you can download it from http://www.apollochoicemodelling.com/code.html . Note that you need to download the appropriate file for your operating system.

If you are using RStudio, you install this file simply by selecting Tool > Install Packages... in the menu bar, and then selecting Install from: Package Archive File, and select the file you downloaded.

If you are not using RStudio, then you can run the following code:

Code: Select all

install.packages("C:/path/to/file/apollo_0.2.5.zip", repos=NULL)
Where you need to change "C:/path/to/file/apollo_0.2.5.zip" to the appropriate path to the downloaded file.

Please let us know if that doesn't solve the issue.

Cheers
David
janak12_jp
Posts: 6
Joined: 08 Sep 2021, 16:52

Re: Some levels in 'outcomeOrdered' do not exist in 'coding' for model component

Post by janak12_jp »

Hii!!

I came across the same error. Updated the Apollo to v0.2.5. But the same error is occurring.
dpalma
Posts: 190
Joined: 24 Apr 2020, 17:54

Re: Some levels in 'outcomeOrdered' do not exist in 'coding' for model component

Post by dpalma »

Hi,

Does the error only happens when using multiple cores? If it does, then could you share your code and data so we can look at the problem in more detail? If you don't want to post your code or data in the forum, you can email it to me to D.Palma [at] leeds.ac.uk . We will treat the data confidentially and delete it after solving the issue.

If the problem happens when running on a single core, then I'd recommend checking your data. It may be that one level of the ordered outcome is never chosen in your data.

Cheers
David
janak12_jp
Posts: 6
Joined: 08 Sep 2021, 16:52

Re: Some levels in 'outcomeOrdered' do not exist in 'coding' for model component

Post by janak12_jp »

The problem occurs on single as well as multiple cores. I have mailed the code as well as my data to your mail ID since it is a part of my research.

Thank you!
dpalma
Posts: 190
Joined: 24 Apr 2020, 17:54

Re: Some levels in 'outcomeOrdered' do not exist in 'coding' for model component

Post by dpalma »

Hi,

Using ordered logit is a bit tricky, as it requires very careful coding, making sure that all the inputs are consistent. Things you should look for:
  • Make sure that you are using the correct number of thresholds for each dependant variable. You should provide as many threshold parameters as OBSERVED number of levels minus one. Keep in mind that you cannot estimate thresholds for levels not observed (i.e. chosen) in your data. For example, imagine your dependant variable is a 5-point Likert scale, but no one chose level 1. So your dependant variable contains values 2, 3, 4 and 5. Then, you will only need three thresholds, as levels 1 and two become the new lower level.
  • If the levels of your dependant variable are not 1, 2, 3, ... , then you need to provide an explicit "coding" setting. Continuing with the example before, where no one chose level 1, your coding is no longer standard (it is 2 to 5 instead of 1 to 5). Therefore, you will need to provide the "coding" setting. See the example at the end.
  • Make sure to exclude unnecessary rows and those with missing data. It is common to exclude some rows from the ordered logit likelihood. For example, some observations (i.e. rows) may have missing data, or maybe you only want to keep the first row of each individual (as it is often done when using LV associated to each individual, not each observation). To do this, you can use the setting "rows" to tell the model which lines to consider. You need to indicate a condition that is TRUE for every row of the data that you want to be considered.
So, let's imagine you have a dependant variable "y" on a Likert scale from 1 to 5, but only levels 2 to 5 are actually observed in the data. Also, variable "y" can take the value 0 if the data is missing. You would code this model as follows:

Code: Select all

ol_settings= list(outcomeOrdered = y,
                  V      = zeta*LV,
                  tau    = c(tau1, tau2, tau3), # only three thresholds are needed as there are only four different observed levels
                  coding = c(2,3,4,5), # there are only four levels: 2, 3, 4 and 5
                  rows   = y!=0) # ignore lines where the dependant is equal to zero
Hope this helps.

Cheers
David
janak12_jp
Posts: 6
Joined: 08 Sep 2021, 16:52

Re: Some levels in 'outcomeOrdered' do not exist in 'coding' for model component

Post by janak12_jp »

Thank you Dr David for posting reply.

The issue is resolved with minor improvement in what you have suggested regarding "coding" in ol_settings. I need to make sure that the levels should start from 1 only, even if none of the respondents in my data have selected 1. So in that case, if my latent indicator has four levels- 2, 3, 4 and 5, then I need to convert them into 1, 2, 3 and 4 respectively in my data. So my coding will remain c(1, 2, 3, 4) in ol_settings instead of c(2, 3, 4, 5). Then we are good to go!!
dpalma
Posts: 190
Joined: 24 Apr 2020, 17:54

Re: Some levels in 'outcomeOrdered' do not exist in 'coding' for model component

Post by dpalma »

Hi,

Yes, if your dependant variable "y" takes values 2, 3, 4 and 5, you can either use coding=c(2,3,4,5), or you can simply transform it before running the model as y = y-1, and then you don't need to specify "coding".

The "coding" setting is particularly useful when the levels of the dependant variable are not numeric, for example "low", "medium" and "high".

Cheers
David
hamiltonconnie
Posts: 1
Joined: 24 Nov 2021, 10:15

Re: Some levels in 'outcomeOrdered' do not exist in 'coding' for model component

Post by hamiltonconnie »

Your question help me too) thanks!
Post Reply