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. We check the forum at least twice a week. It may thus take a couple of days for your post to appear and before we reply. There is no need to submit the post multiple times.

Subgroup analysis for MMNL

Ask questions about how to estimate models and how to change your settings for estimation.
Post Reply
Heinz
Posts: 1
Joined: 21 Aug 2024, 13:01

Subgroup analysis for MMNL

Post by Heinz »

Hello,
I have questions concerning subgroup analysis using interaction in MMNL. My MMNL model includes two dummy coded attributes (with four levels coresponding to bx11*V6+bx12*V7+bx13*V8 and three levels corresponding to bx21*V9+bx22*V10, each for alternative 1) and one binary covariate cv (levels 0 and 1). For a subgroup analysis with respect to the two groups defined by the covariate.
I used the following input:

library(apollo)
apollo_initialise()

### Set core controls
apollo_control = list(
modelName ="MMNL Interaktion Job",
indivID ="V1",
modelDescr ="MMNL Interaktion Job",
mixing = TRUE,
nCores = 5
)

database=datafinaldummyredcv

apollo_beta=c(
mu_bx11=0, mu_bx12=0, mu_bx13=0,
mu_bx21=0, mu_bx22=0,
sigma_bx11=0, sigma_bx12=0, sigma_bx13=0,
sigma_bx21=0, sigma_bx22=0,
mu_bx11_cv=0, mu_bx12_cv=0, mu_bx13_cv=0,
mu_bx21_cv=0, mu_bx22_cv=0,
sigma_bx11_cv=0, sigma_bx12_cv=0, sigma_bx13_cv=0,
sigma_bx21_cv=0, sigma_bx22_cv=0
)

apollo_fixed=c()

apollo_draws = list(
interDrawsType = "mlhs", # use mlhs when using 5 or more distributions
interNDraws = 1000,
interUnifDraws = c(),
interNormDraws = c("draws_b11","draws_b12","draws_b13","draws_b21","draws_b22",
"draws_b11_cv","draws_b12_cv","draws_b13_cv","draws_b21_cv","draws_b22_cv"),
intraDrawsType = "mlhs",
intraNDraws = 0,
intraUnifDraws = c(),
intraNormDraws = c()
)

apollo_randCoeff = function(apollo_beta, apollo_inputs){
randcoeff = list()

randcoeff[["bx11"]] = mu_bx11 + sigma_bx11 * draws_b11 + cv * (mu_bx11_cv + sigma_bx11_cv * draws_b11_cv)
randcoeff[["bx12"]] = mu_bx12 + sigma_bx12 * draws_b12 + cv * (mu_bx12_cv + sigma_bx12_cv * draws_b12_cv)
randcoeff[["bx13"]] = mu_bx13 + sigma_bx13 * draws_b13 + cv * (mu_bx13_cv + sigma_bx13_cv * draws_b13_cv)
randcoeff[["bx21"]] = mu_bx21 + sigma_bx21 * draws_b21 + cv * (mu_bx21_cv + sigma_bx21_cv * draws_b21_cv)
randcoeff[["bx22"]] = mu_bx22 + sigma_bx22 * draws_b22 + cv * (mu_bx22_cv + sigma_bx22_cv * draws_b22_cv)

return(randcoeff)
}

apollo_inputs = apollo_validateInputs()

apollo_probabilities=function(apollo_beta, apollo_inputs, functionality="estimate"){

apollo_attach(apollo_beta, apollo_inputs)
on.exit(apollo_detach(apollo_beta, apollo_inputs))

P = list()
V = list()

V[['alt1']]=
bx11*V6+bx12*V7+bx13*V8+
bx21*V9+bx22*V10

V[['alt2']]=
bx11*V28+bx12*V29+bx13*V30+
bx21*V31+bx22*V32

mnl_settings = list(
alternatives = c(alt1=1, alt2=2),
avail = list(alt1=1, alt2=1),
choiceVar = V5,
V = V
)

P[['model']] = apollo_mnl(mnl_settings, functionality)
P = apollo_panelProd(P, apollo_inputs, functionality)
P = apollo_avgInterDraws(P, apollo_inputs, functionality)
P = apollo_prepareProb(P, apollo_inputs, functionality)
return(P)
}

model = apollo_estimate(apollo_beta, apollo_fixed, apollo_probabilities, apollo_inputs)
apollo_modelOutput(model)

This is the output:

Model name : MMNL Interaktion Job
Model description : MMNL Interaktion Job
Model run at : 2024-08-21 15:10:33
Estimation method : bfgs
Model diagnosis : successful convergence
Optimisation diagnosis : Maximum found
hessian properties : Negative definitive
maximum eigenvalue : -2.251335
Number of individuals : 329
Number of rows in database : 3290
Number of modelled outcomes : 3290

Number of cores used : 5
Number of inter-individual draws : 1000 (mlhs)

LL(start) : -2280.45
LL at equal shares, LL(0) : -2280.45
LL at observed shares, LL(C) : -2211.34
LL(final) : -2221.56
Rho-squared vs equal shares : 0.0258
Adj.Rho-squared vs equal shares : 0.0171
Rho-squared vs observed shares : -0.0046
Adj.Rho-squared vs observed shares : -0.0132
AIC : 4483.11
BIC : 4605.09

Estimated parameters : 20
Time taken (hh:mm:ss) : 00:07:30.45
pre-estimation : 00:01:43.15
estimation : 00:01:44.6
initial estimation : 00:01:37.92
estimation after rescaling : 00:00:6.69
post-estimation : 00:04:2.69
Iterations : 38
initial estimation : 37
estimation after rescaling : 1

Unconstrained optimisation.

Estimates:
Estimate s.e. t.rat.(0) Rob.s.e. Rob.t.rat.(0)
mu_bx11 -0.022579 0.1012 -0.223185 0.10562 -0.21378
mu_bx12 0.365961 0.1066 3.432663 0.11440 3.19898
mu_bx13 0.408809 0.1190 3.435896 0.12669 3.22697
mu_bx21 0.354098 0.1134 3.122217 0.11872 2.98271
mu_bx22 0.596520 0.1057 5.643412 0.11502 5.18624
sigma_bx11 0.003102 0.3773 0.008224 0.05248 0.05912
sigma_bx12 -0.098015 0.3567 -0.274811 0.16749 -0.58521
sigma_bx13 -0.535400 0.1417 -3.777238 0.14306 -3.74239
sigma_bx21 -0.661321 0.1821 -3.631836 0.18555 -3.56406
sigma_bx22 -0.186263 0.4944 -0.376769 0.55193 -0.33747
mu_bx11_cv 0.271375 0.1600 1.695950 0.16750 1.62013
mu_bx12_cv -0.254476 0.1777 -1.432287 0.19109 -1.33173
mu_bx13_cv 0.011861 0.1859 0.063805 0.20404 0.05813
mu_bx21_cv -0.086023 0.1870 -0.459978 0.19188 -0.44832
mu_bx22_cv 0.199461 0.1774 1.124490 0.18540 1.07582
sigma_bx11_cv -0.006626 0.2581 -0.025675 0.02046 -0.32380
sigma_bx12_cv -0.477671 0.2332 -2.048060 0.20512 -2.32874
sigma_bx13_cv -0.002255 0.3440 -0.006556 0.02937 -0.07678
sigma_bx21_cv 0.454815 0.4459 1.019996 0.45997 0.98879
sigma_bx22_cv 0.077226 0.6500 0.118811 0.22419 0.34446


My first question: Is this input correct to estimate the main effects and the interaction effects?
Secondly: It is known, that in MLN models the main effects correspond to the regression weights of the first group (coded with 0) and the sum of the main effects and the interaction effects to the regression weights of the second group.
Is the following rule valid analogously here: The main effects correspond to the expectations and standard deviations of the first group and the sum of the main effects and the interaction effects to the expectations and standard deviations of the first group.
If this would be correct, how to deal with the signs of the coefficients corresponding to the standard deviations, since the signs are arbitrary.
If I run separate MMNL analyses for the two subgroups then I get other results than those expected by the MMNL model including interaction effects when applying the rule stated above.

Thank you very much for your help in advance!
stephanehess
Site Admin
Posts: 1367
Joined: 24 Apr 2020, 16:29

Re: Subgroup analysis for MMNL

Post by stephanehess »

Hi

this looks fine. For the interaction sd, you would use the sqrt of the sum of squares, so sqrt(sigma_bx11^2+sigma_bx11_cv^2)

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