Specifying interaction terms for ordered response model

Welcome to the forum for R2MLwiN users. Feel free to post your question about R2MLwiN here. The Centre for Multilevel Modelling take no responsibility for the accuracy of these posts, we are unable to monitor them closely. Do go ahead and post your question and thank you in advance if you find the time to post any answers!

Go to R2MLwiN: Running MLwiN from within R >> http://www.bris.ac.uk/cmm/software/r2mlwin/
Post Reply
adeldaoud
Posts: 63
Joined: Sat Aug 15, 2015 4:00 pm

Specifying interaction terms for ordered response model

Post by adeldaoud »

Hi

I am trying to specify an interaction term for a logistic ordered response model in R2mlwin. My response has three categories. I am trying to interact one continues variable and one factor level variable.

However, there is a strange behaviour when and where I add the extra term [1:2] to specify a common term.

1) When I only have the interaction term, with no main terms, the term is doing what it is supposed to:

(full.model.2_MCMC =runMLwiN(logit(AFgpWHO, cons, 3) ~ 1 + Price[1:2]:Mother_educ[1:2] + (1[1:2] | Region) ,
D='Ordered Multinomial', estoptions=list(mcmcMeth = list(iterations = 100000, burnin=5000), resi.store =T, EstM=0),data = df.sm))

-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
MLwiN (version: 2.32) multilevel model (Multinomial)
N min mean max
Region 48 NA NA NA
Estimation algorithm: IGLS MQL1 Elapsed time : 0.81s
Number of obs: 10000 (from total 10000) The model converged after 5 iterations.
Log likelihood: NA
Deviance statistic: NA
---------------------------------------------------------------------------------------------------
The model formula:
logit(AFgpWHO, cons, 3) ~ 1 + Price[1:2]:Mother_educ[1:2] + (1[1:2] |
Region)
Level 2: Region Level 1: l1id
---------------------------------------------------------------------------------------------------
The fixed part estimates:
Coef. Std. Err. z Pr(>|z|) [95% Conf. Interval]
Intercept_A_multipleAF -1.06191 0.08840 -12.01 3.066e-33 *** -1.23517 -0.88864
Intercept_B_singel_AF 0.17232 0.08763 1.97 0.04926 * 0.00056 0.34407
Price:Mother_educPrimary_12 -0.07493 0.01378 -5.44 5.437e-08 *** -0.10194 -0.04791
Price:Mother_educSecondary_12 -0.13823 0.01375 -10.05 8.913e-24 *** -0.16518 -0.11128
Price:Mother_educHigher_12 -0.28135 0.02586 -10.88 1.424e-27 *** -0.33203 -0.23067
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
---------------------------------------------------------------------------------------------------
The random part estimates at the Region level:
Coef. Std. Err.
var_Intercept_12 0.24306 0.06032
---------------------------------------------------------------------------------------------------
The random part estimates at the l1id level:
Coef. Std. Err.
bcons_1 1.00000 0.00000
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-


But when I add all the terms as one should. he r2mlwin function adds an extra price term (Price_1 or Price_12) where there should not be one: and the interactions disappear. Additionally, NAs: are introduced.

(runMLwiN(logit(AFgpWHO, cons, 3) ~ 1 + Mother_educ[1:2] + Price[1:2] + Price:Mother_educ[1:2] + (1[1:2] | Region) ,
D='Ordered Multinomial', estoptions=list(mcmcMeth = list(iterations = 100000, burnin=5000), resi.store =T, EstM=0),data = df.sm))

-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
MLwiN (version: 2.32) multilevel model (Multinomial)
N min mean max
Region 48 NA NA NA
Estimation algorithm: IGLS MQL1 Elapsed time : 0.91s
Number of obs: 10000 (from total 10000) The model converged after 5 iterations.
Log likelihood: NA
Deviance statistic: NA
---------------------------------------------------------------------------------------------------
The model formula:
logit(AFgpWHO, cons, 3) ~ 1 + Mother_educ[1:2] + Price[1:2] +
Price:Mother_educ[1:2] + (1[1:2] | Region)
Level 2: Region Level 1: l1id
---------------------------------------------------------------------------------------------------
The fixed part estimates:
Coef. Std. Err. z Pr(>|z|) [95% Conf. Interval]
Intercept_A_multipleAF -1.12338 0.11775 -9.54 1.423e-21 *** -1.35417 -0.89260
Intercept_B_singel_AF 0.44594 0.10806 4.13 3.678e-05 *** 0.23415 0.65772
Price_12 -0.05842 0.01831 -3.19 0.001418 ** -0.09431 -0.02254
Price_1 0.08855 0.01969 4.50 6.889e-06 *** 0.04996 0.12715
Mother_educPrimary_12 -0.34320 0.05415 -6.34 2.33e-10 *** -0.44933 -0.23707
Mother_educSecondary_12 -0.62165 0.05651 -11.00 3.821e-28 *** -0.73242 -0.51089
Mother_educHigher_12 -1.18916 0.10245 -11.61 3.762e-31 *** -1.38995 -0.98837
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
---------------------------------------------------------------------------------------------------
The random part estimates at the Region level:
Coef. Std. Err.
var_Intercept_12 0.22293 0.05543
---------------------------------------------------------------------------------------------------
The random part estimates at the l1id level:
Coef. Std. Err.
bcons_1 1.00000 0.00000
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
Warning message:
NAs introduced by coercion




Any ideas what is going on?
Thanks

ChrisCharlton
Posts: 1193
Joined: Mon Oct 19, 2009 10:34 am

Re: Specifying interaction terms for ordered response model

Post by ChrisCharlton »

I notice that in your second example you have removed the [1:2] after Price in the interaction. Do you get the same problem if you add this back?

R has an alternative, more compact way of specifying the interaction structure that you have specified (see https://stat.ethz.ch/R-manual/R-devel/l ... rmula.html). If you change your command to:

Code: Select all

(runMLwiN(logit(AFgpWHO, cons, 3) ~ 1 + Price[1:2]*Mother_educ[1:2] + (1[1:2] | Region) ,
D='Ordered Multinomial', estoptions=list(mcmcMeth = list(iterations = 100000, burnin=5000), resi.store =T, EstM=0),data = df.sm))
do you get the same output?

adeldaoud
Posts: 63
Joined: Sat Aug 15, 2015 4:00 pm

Re: Specifying interaction terms for ordered response model

Post by adeldaoud »

Thanks for the reply.

The suggestion did not work:

> (runMLwiN(logit(AFgpWHO, cons, 3) ~ 1 + Price[1:2] + Mother_educ[1:2] + Price[1:2]*Mother_educ[1:2] + (1[1:2] | Region) ,
+ D='Ordered Multinomial', estoptions=list(mcmcMeth = list(iterations = 100000, burnin=5000), resi.store =T, EstM=0),data = df.sm))
Error in `rownames<-`(`*tmp*`, value = c("Price", "Intercept", "Mother_educPrimary", :
length of 'dimnames' [1] not equal to array extent
In addition: Warning message:
NAs introduced by coercion

Having [1:2] in front of price causes the same problem as with using the * operator:

> (runMLwiN(logit(AFgpWHO, cons, 3) ~ 1 + Price[1:2] + Mother_educ[1:2] + Price[1:2]:Mother_educ[1:2] + (1[1:2] | Region) ,
+ D='Ordered Multinomial', estoptions=list(mcmcMeth = list(iterations = 100000, burnin=5000), resi.store =T, EstM=0),data = df.sm))
Error in `rownames<-`(`*tmp*`, value = c("Price", "Intercept", "Mother_educPrimary", :
length of 'dimnames' [1] not equal to array extent
In addition: Warning message:
NAs introduced by coercion


Any further ideas? Thanks in advance

ChrisCharlton
Posts: 1193
Joined: Mon Oct 19, 2009 10:34 am

Re: Specifying interaction terms for ordered response model

Post by ChrisCharlton »

In your example with the * operator you have left in the main effects which shouldn't be necessary, however I have also been able to replicate the problem with an example dataset and am seeing the same behaviour. This probably indicates that there is a bug in R2MLwiN, so we will investigate whether this is the case and I hope provide a fix.

adeldaoud
Posts: 63
Joined: Sat Aug 15, 2015 4:00 pm

Re: Specifying interaction terms for ordered response model

Post by adeldaoud »

In your example with the * operator you have left in the main effects which shouldn't be necessary,
I tried without the main effect but the function does not automatically insert them.

Thanks for checking it with your own data as well. Please, let me know when you have an updated R2mlwin.

cheers
Adel

ChrisCharlton
Posts: 1193
Joined: Mon Oct 19, 2009 10:34 am

Re: Specifying interaction terms for ordered response model

Post by ChrisCharlton »

We have now been able to look into this and it turns out that there was a bug. This should now be fixed in the development version which, as described in http://www.bristol.ac.uk/cmm/software/r2mlwin/, can be installed with the following commands:

Code: Select all

library(devtools)
install_github("rforge/r2mlwin", subdir="R2MLwiN")
Alternatively the fix will be included in the next release of the package, which should happen fairly soon.

adeldaoud
Posts: 63
Joined: Sat Aug 15, 2015 4:00 pm

Re: Specifying interaction terms for ordered response model

Post by adeldaoud »

Thanks Chris! I will have a look at it asap.

Post Reply