Re: [R] generating clustered data

From: Hamilton, Cody <>
Date: Wed 12 Jul 2006 - 09:35:13 EST


What about creating the covariance matrix with the help of the kronecker product? For instance, suppose your intercepts are ~ N(0,var1) and your residual errors are ~ N(0,var2). Suppose further that you want 10 clusters of 5 observations each. I believe you can create the overall covariance matrix with kronecker(diag(10),matrix(var1,5,5)) + var2*diag(50). This can then be fed as the variance to the mvtnorm function. Hope this helps.



-----Original Message-----
[] On Behalf Of Brian Perron Sent: Tuesday, July 11, 2006 15:59 PM
Subject: [R] generating clustered data

Hello R folks,

Does anybody have code to share for generating (via simulation) clustered data? The type of data I am looking to simulate would allow fitting of a multilevel model with random intercepts. I looked at the mvtnorm package but am not quite sure how to create clusters. (Can this

be done by simply changing the seed?) If somebody could point me where to look for the relevant code or perhaps send some sample code, that would be great.

Brian mailing list PLEASE do read the posting guide!

This e-mail, facsimile, or letter and any files or attachmen...{{dropped}} mailing list PLEASE do read the posting guide! Received on Wed Jul 12 09:39:32 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 12 Jul 2006 - 12:18:13 EST.

Mailing list information is available at Please read the posting guide before posting to the list.