Subgroup analysis for MMNL
Posted: 21 Aug 2024, 14:35
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!
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!