Page 1 of 1

R2MLwiN: Error while obeying batch file: Wrong number of output columns

Posted: Thu Oct 01, 2015 9:49 am
by edwardoughton
I'm trying to recreate MCMC Guide 06 with my data by setting up a random slopes model and then storing the residuals for prediction. I keep receiving the following error :

Error while obeying batch file... wrong number of output columns (full screen shot of error message attached).

Here's my code which sets up the data, specifies a variety of models (1-4), before focusing on how it's done in MCMC Guide 06. It's a three level model, with annual repeated broadband speed measurements (yrid), nested within local authorities (laid), nested within regions (rnid).

Data is attached = total.xlsx (sorry, it wouldn't let me upload the .csv!)

Any help would be much appreciated.

Code: Select all

mlwin = c("C:/Program Files (x86)/MLwiN v2.35/i386")
options(MLwiN_path = mlwin)
total<-read.csv("total.csv")
is.num <- sapply(total, is.numeric)
total[is.num] <- lapply(total[is.num], round, 2)
total$year <- total$year.num

## IGLS
(mymodel1 <- runMLwiN(speed ~ 1 + sfbb +  (1| rnid) + (1 | laid) + (1 | yrid), data = total))
## Gibbs (with diffuse priors/gamma priors, as standard) (MCMC)
(mymodel2 <- runMLwiN(speed ~ 1 + sfbb +  (1| rnid) + (1 | laid) + (1 | yrid), estoptions = list(EstM = 1), data = total))
## Diffuse priors (Uniform priors) (MCMC)
(mymodel3 <- runMLwiN(speed ~ 1 + sfbb + (1| rnid) + (1 | laid) + (1 | yrid), estoptions = list(EstM = 1, mcmcMeth = list(priorcode = 0)), data = total))
## slope at level 1 using sfbb (MCMC)
(mymodel4 <- runMLwiN(speed ~ 1 + sfbb +  (1| rnid) +(1 | laid) + (1 + sfbb| yrid), estoptions = list(EstM = 1), data = total))

-------------------
#Follow guide 06
## Choose MCMC algoritm for estimation (IGLS will be used to obtain starting values for MCMC)
(mymodel6 <- runMLwiN(speed ~ 1 + sfbb + rnid + laid + rnid:sfbb + (1 | yrid), estoptions = list(EstM = 1), data = total))

## Define the model Choose IGLS algoritm for estimation Fit the model
(mymodel6.1 <- runMLwiN(speed ~ 1 + sfbb + (1 | rnid) + (1 | laid) + (1  + sfbb| yrid), data = total))

## Choose MCMC algoritm for estimation (IGLS will be used to obtain starting values for MCMC)
(mymodel6.20 <- runMLwiN(speed ~ 1 + sfbb + (1 | rnid) + (1 | laid) + (1  + sfbb| yrid), estoptions = list(EstM = 1, mcmcMeth = list(iterations = 5001), resi.store.levs= 2),data = total))

Re: R2MLwiN: Error while obeying batch file: Wrong number of output columns

Posted: Thu Oct 01, 2015 2:53 pm
by ChrisCharlton
Thanks for this example, there was a bug in the generated code for extracting the residuals where it didn't take into account that there is always only one residual variable at level-1 for MCMC models. Because of this the fact that you specified complex level-1 variation meant that it was requesting two, which in turn was causing the error in MLwiN. Although you specified resi.store.levs= 2 this only changes whether residual chains are stored at a level (for backward compatibility reasons once you ask for residuals they are returned at all levels). I have now added a fix to the development version and this should be included in the next release of the software. If you need it sooner than this you can install this version with the following commands:

Code: Select all

library(devtools)
install_github("rforge/r2mlwin", subdir="R2MLwiN")
I also note that you mentioned a random slopes model (e.g. http://www.bristol.ac.uk/cmm/media/r2ml ... CGuide06.R), but the example you showed was modelling complex level-1 variation (e.g. mymodel1 in http://www.bristol.ac.uk/cmm/media/r2ml ... CGuide09.R) instead.

Re: R2MLwiN: Error while obeying batch file: Wrong number of output columns

Posted: Thu Oct 01, 2015 4:26 pm
by edwardoughton
Dear Chris,

That appears to have done it - thanks!

Also, I appreciate you pointing out the difference between this complex 1 variance model and the random slopes model. Once I've finished my analysis I must cross validate my code on this site.

Ed