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.

accounting for 2 levels of panel data

Ask questions about model specifications. Ideally include a mathematical explanation of your proposed model.
Post Reply
sarah.hill.phmr
Posts: 2
Joined: 18 Mar 2022, 05:39

accounting for 2 levels of panel data

Post by sarah.hill.phmr »

hi,

I am trying to estimate a main-effects model with panel data but I have 2 levels of panel data and I am unsure how to account for this.

1) each respondent answered 7 choice questions within a survey - these are related by the surveyID
2) each respondent answered 2 surveys at different time points - these are related by the personID

I have the ID for my overall model set at the personID level so that all responses from the same person are considered panel data. However, I also expect there may be heterogeneity between the same person's responses over the two surveys completed at different time points but I am unsure how to capture this additional layer of heterogeneity. Or should I have the ID for the model set at the surveyID level instead and account for the repeated measures another way?

My choices are unlabelled and my main effects utility functions are as follows:

V[["alt1"]] = asc1 + b_mo * MO_A + b_sc * SC_A + b_ua * UA_A + b_pd * PD_A + b_ad * AD_A
V[["alt2"]] = b_mo * MO_B + b_sc * SC_B + b_ua * UA_B + b_pd * PD_B + b_ad * AD_B

MO, SC, UA, PD and AD all refer to the 5 dimensions of the EQ5D5l questionnaire.

Any guidance would be greatly appreciated :)

Sarah
dpalma
Posts: 190
Joined: 24 Apr 2020, 17:54

Re: accounting for 2 levels of panel data

Post by dpalma »

Hi Sarah,

There are different ways to account for the multiple levels of heterogenity. What I would recommend is keeping personID as the model main ID, while accounting for the difference in the two surveys through a scale parameter. Example MNL_RP_SP from the examples webpage shows how to estimate scale differences when using two data sources (in your case, the two surveys).

For reference, the relevant parts of your model script should look as below. I am assuming responses from survey 1 and survey 2 are in different rows in the data. If mu_2 is bigger than 1, it means that the second survey has lower noise than the first one. If mu_2 is smaller than 1 it means that the second survey has more noise than the first one. The estimated value of the scale factors (mu_1, mu_2 ) should always be positive.

Best wishes
David

Code: Select all

apollo_control = list(
  ...
  indivID         = "personID"
)

apollo_beta = c(asc1 = 0, 
                b_mo = 0, 
                b_sc = 0, 
                b_uo = 0, 
                b_pd = 0, 
                b_ad = 0, 
                mu_1 = 1, 
                mu_2 = 1)

apollo_fixed = c("mu_1")

...

apollo_probabilities=function(apollo_beta, apollo_inputs, 
                              functionality="estimate"){
  
  ### Initialise
  apollo_attach(apollo_beta, apollo_inputs)
  on.exit(apollo_detach(apollo_beta, apollo_inputs))
  P = list()
  
  ### List of utilities (before applying scales)
  V = list()
  V[["alt1"]] = asc1 + b_mo*MO_A + b_sc*SC_A + b_ua*UA_A + b_pd*PD_A + b_ad*AD_A
  V[["alt2"]] =        b_mo*MO_B + b_sc*SC_B + b_ua*UA_B + b_pd*PD_B + b_ad*AD_B
  
  ### Compute probabilities for the first survey
  mnl_settings_1 = list(
    alternatives  = c(alt1=1, alt2=2),  
    choiceVar     = choice, 
    utilities     = list(alt1 = mu_1*V[["alt1"]],
                         alt2 = mu_1*V[["alt2"]]),
    rows          = (surveyID==1)
  )
  P[["survey1"]] = apollo_mnl(mnl_settings_1, functionality)
  
  ### Compute probabilities for the second survey
  mnl_settings_2 = list(
    alternatives  = c(alt1=1, alt2=2),  
    choiceVar     = choice, 
    utilities     = list(alt1 = mu_2*V[["alt1"]],
                         alt2 = mu_2*V[["alt2"]]),
    rows          = (surveyID==2)
  )
  P[["survey2"]] = apollo_mnl(mnl_settings_2, functionality)
  
  ### Prepare probs and return
  P = apollo_combineModels(P, apollo_inputs, functionality)
  P = apollo_panelProd(P, apollo_inputs, functionality)
  P = apollo_prepareProb(P, apollo_inputs, functionality)
  return(P)
}
sarah.hill.phmr
Posts: 2
Joined: 18 Mar 2022, 05:39

Re: accounting for 2 levels of panel data

Post by sarah.hill.phmr »

Thanks David, that's really useful!

Just to be sure I am intpreting this correctly, by more "noise" do you mean that responses to survey 2 (mu_2 is <1) produce less reliable estimates than responses to survey 1?

Thanks,
Sarah
stephanehess
Site Admin
Posts: 974
Joined: 24 Apr 2020, 16:29

Re: accounting for 2 levels of panel data

Post by stephanehess »

Sarah

I wouldn't call the estimates less reliable. What it means is that from the perspective of the model, the choices are less deterministic

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