Page 1 of 1

Level 2 residuals for ML cumulative logit model

Posted: Fri Aug 04, 2017 6:22 pm
by vivian1234
Hi, I was trying to replicate the analysis from module 9 Practice using R2MLwiN.
I used the following codes to calculate the residual for random intercept and slope:

Code: Select all

## to calculate random intercept residual
u0 <- model03@residual$lev_2_resi_est_Intercept.123/2 

## to calculate random slope residual
u1 <- model03@residual$lev_2_resi_est_agecen50.123/2
However, when I compared with the residuals calculated using MLwiN, u0 obtained from the above code correspond to the random slope residual (agecen50.123) from MLwiN while u1 obtained from R2MLwiN correspond to the random intercept (cons.123) from MLwiN.


Thanks a lot.

Regards,
Vivian

Re: Level 2 residuals for ML cumulative logit model

Posted: Fri Aug 04, 2017 6:36 pm
by vivian1234
The problem also exists in the random part estimations.

Result obtained by MLwiN

Code: Select all

Random Part			
Level: state_long			
cons.123/cons.123		0.24907945	0.06827134	1
agecen50^1.123/cons.123		0.00349785	0.0013245	0.65697408
agecen50^1.123/agecen50^1.123	0.00011381	0.00003864	1
Result by R2MLwin

Code: Select all

The random part estimates at the state1 level: 
var_Intercept_123		0.00013	0.00005
cov_Intercept_123_agecen50_123	0.004	0.00161
var_agecen50_123		0.28027	0.08268
In this case, should I reverse the random effect obtained from R2MLwin?

Thanks a lot.

Re: Level 2 residuals for ML cumulative logit model

Posted: Mon Aug 07, 2017 9:49 pm
by ChrisCharlton
Thank you for letting us know about this. I will look into it as soon as I get the chance. Can you please provide the syntax for the model that corresponds to these results?

Re: Level 2 residuals for ML cumulative logit model

Posted: Wed Aug 09, 2017 1:02 pm
by vivian1234
Hi, I'm using data (9.1wsz) from Module 9. The data is converted to dta and then imported to R. The categorical variable (occtype) is converted into dummy variables. Here is the syntax for replicating the random slope model:

Code: Select all

data9.1$occtype0 <- dummy.code(data9.1$occtype)

RSmodel <- runMLwiN(logit(electint, cons, 4) ~ 1 + female[1:3] +  agecen50[1:3] + 
                      agesq[1:3] + occtype01[1:3] + occtype02[1:3] +
                      occtype03[1:3] + occtype04[1:3] + occtype05[1:3] +
                      (1[1:3] + agecen50[1:3]  | state), 
                    D = "Ordered Multinomial", data = data9.1,
                    estoptions = list(EstM = 1, mcmcMeth = list(iterations = 5000, burnin = 500), 
                                      resi.store = TRUE, resi.store.levs = 2))
                                      
## to calculate random intercept residual
u0 <- RSmodel@residual$lev_2_resi_est_Intercept.123/2 

## to calculate random slope residual
u1 <- RSmodel@residual$lev_2_resi_est_agecen50.123/2    
Thank you very much.

Regards,
Vivian

Re: Level 2 residuals for ML cumulative logit model

Posted: Wed Aug 16, 2017 12:59 pm
by ChrisCharlton
I have had an initial look into this and it appears that the problem is that cons[1:3] term is in the random part, but not the fixed part. R2MLwiN is assuming that the parameters in MLwiN are in the order that they appear in the equation, however as agecen50[1:3] is in the fixed part, but 1[1:3] isn't the order is reversed due to the way the variables are added to the model. I will attempt to fix this for the next version of the software but in the mean time the workaround is to reorder the terms in the random part so that any terms shared with the fixed part come first and are in the same order. In your case this would mean changing the model to the following:

Code: Select all

RSmodel <- runMLwiN(logit(electint, cons, 4) ~ 1 + female[1:3] +  agecen50[1:3] + 
                      agesq[1:3] + occtype01[1:3] + occtype02[1:3] +
                      occtype03[1:3] + occtype04[1:3] + occtype05[1:3] +
                      ( agecen50[1:3] + 1[1:3]  | state), 
                    D = "Ordered Multinomial", data = data9.1,
                    estoptions = list(EstM = 1, mcmcMeth = list(iterations = 5000, burnin = 500), 
                                      resi.store = TRUE, resi.store.levs = 2))
Thanks again for letting us know about this, and sorry for the inconvenience.

Re: Level 2 residuals for ML cumulative logit model

Posted: Fri Sep 01, 2017 11:49 am
by ChrisCharlton
Just to let you know we have just released a new version of R2MLwiN (0.8-5) to CRAN which should fix both of the bugs that you reported. Please let us know if you find any further problems.