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.066e33 *** 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.437e08 *** 0.10194 0.04791
Price:Mother_educSecondary_12 0.13823 0.01375 10.05 8.913e24 *** 0.16518 0.11128
Price:Mother_educHigher_12 0.28135 0.02586 10.88 1.424e27 *** 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.423e21 *** 1.35417 0.89260
Intercept_B_singel_AF 0.44594 0.10806 4.13 3.678e05 *** 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.889e06 *** 0.04996 0.12715
Mother_educPrimary_12 0.34320 0.05415 6.34 2.33e10 *** 0.44933 0.23707
Mother_educSecondary_12 0.62165 0.05651 11.00 3.821e28 *** 0.73242 0.51089
Mother_educHigher_12 1.18916 0.10245 11.61 3.762e31 *** 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
Specifying interaction terms for ordered response model

 Posts: 1248
 Joined: Mon Oct 19, 2009 10:34 am
Re: Specifying interaction terms for ordered response model
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/Rmanual/Rdevel/l ... rmula.html). If you change your command to:
do you get the same output?
R has an alternative, more compact way of specifying the interaction structure that you have specified (see https://stat.ethz.ch/Rmanual/Rdevel/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))
Re: Specifying interaction terms for ordered response model
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
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

 Posts: 1248
 Joined: Mon Oct 19, 2009 10:34 am
Re: Specifying interaction terms for ordered response model
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.
Re: Specifying interaction terms for ordered response model
I tried without the main effect but the function does not automatically insert them.In your example with the * operator you have left in the main effects which shouldn't be necessary,
Thanks for checking it with your own data as well. Please, let me know when you have an updated R2mlwin.
cheers
Adel

 Posts: 1248
 Joined: Mon Oct 19, 2009 10:34 am
Re: Specifying interaction terms for ordered response model
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:
Alternatively the fix will be included in the next release of the package, which should happen fairly soon.
Code: Select all
library(devtools)
install_github("rforge/r2mlwin", subdir="R2MLwiN")
Re: Specifying interaction terms for ordered response model
Thanks Chris! I will have a look at it asap.