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
Posts: 1
Joined: Sat Nov 17, 2018 9:34 pm


Post by awnudino »

Hello, I have a problem with the output,i want to do on children nutritional status,i have three dependent continuous variables,haz,waz and whz,that i want to fit multivariate multilevel model using r2mlwin with r code. With level-1 variable correlation between the dependent,level 2 children,and level 3 as region,but it says ur covariance matrix is not positive definit.Many thanks.
My code is library(R2MLwiN)
# 1 Path to MLwiN executable
mlwin <- "C:\\Program Files (x86)\\MLwiN trial\\i386"

# 2 variables containing IDs
levID <- c("region", "childid")

# 3 Distribution to be modelled
D <- "Multivariate Normal"

# 4 Method of estimation (1 = MCMC)
estoptions <- list(EstM = 1)

# 5 The data file
indata <- cd
# 6 The model

f1 <- c(WHZ, HAZ, WAZ) ~ 1 + (1 | region) + (1 | childid)

mod1 <- runMLwiN(f1, data = cd, MLwiNPath = mlwin, D = D)
Am i right?
pls help me since its an urgent case i can send my data too!!!
And when i make region as level 1 variable it says its repeated generate unique id,but also i dont know how to generate the factor variable region!

Posts: 1165
Joined: Mon Oct 19, 2009 10:34 am

Re: urgent

Post by ChrisCharlton »

One possible cause of this is that you don't appear to have specified the level-1 identifier. You could do this as follows:

Code: Select all

# Generate a vector numbers 1..number of rows in the data
cd$id <- 1:nrow(cd)
and then adjust the model formula to include this:

Code: Select all

f1 <- c(WHZ, HAZ, WAZ) ~ 1 + (1 | region) + (1 | childid) + (1 | id)
You could also take a look at the models results fitted with (R)IGLS, as these are by default used as the starting values for MCMC, to see whether these look sensible. If not you could try specifying the starting values manually (see chapter 5 on http://www.bristol.ac.uk/cmm/software/r2mlwin/examples/).

Post Reply