Re: [R] Nested structure data simulation

2019-05-21 Thread Linus Chen
Dear varin sacha On Sun, May 19, 2019 at 5:14 PM varin sacha via R-help wrote: > > Dear Boris, > > Great But what about Mark in your R code ? Don't we have to precise in > the R code that mark ranges between 1 to 6 (1 ; 1.5 ; 2 ; 2.5 ; 3 ; 3.5 ; 4 ; > 4.5 ; 5 ; 5.5 ; 6) ? I think Boris

Re: [R] Nested structure data simulation

2019-05-21 Thread Linus Chen
Dear varin sacha, I think it will help us help you, if you give a clearer description of what exactly you want. I assume the situation is that you know what a data structure you want, but do not know how to conveniently create such structure. And that is where others can help you. So, please,

Re: [R] Nested structure data simulation

2019-05-21 Thread Linus Chen
Dear varin sacha, Not very sure what you want, but will the following help a little? tmp <- rep(c("C1","C2","C3","C4","C5","C6"), 50) # make a character vector, with 50 "C1", 50 "C2", ... classroom <- tmp[sample(1:300)] # make a random permutation. Certainly you may also make it into one line:

Re: [R] Nested structure data simulation

2019-05-19 Thread Boris Steipe
My mental model for such a simulation is that you create data from a known distribution, then use your model to check that you can recover the known parameters from the data. Thus how the marks are created depends on what influences them. Here is a toy model to illustrate this - expanding on my

Re: [R] Nested structure data simulation

2019-05-19 Thread varin sacha via R-help
Dear Boris, Great But what about Mark in your R code ? Don't we have to precise in the R code that mark ranges between 1 to 6 (1 ; 1.5 ; 2 ; 2.5 ; 3 ; 3.5 ; 4 ; 4.5 ; 5 ; 5.5 ; 6) ? By the way, to fit a linear mixed model, I use lme4 package and then the lmer function works with the

Re: [R] Nested structure data simulation

2019-05-19 Thread Boris Steipe
Fair enough - there are additional assumptions needed, which I make as follows: - each class has the same size - each teacher teaches the same number of classes - the number of boys and girls is random within a class - there are 60% girls (just for illustration that it does not have to

Re: [R] Nested structure data simulation

2019-05-19 Thread varin sacha via R-help
Many thanks to all of you for your responses. So, I will try to be clearer with a larger example. Te end of my mail is the more important to understand what I am trying to do. I am trying to simulate data to fit a linear mixed model (nested not crossed). More precisely, I would love to get at

Re: [R] Nested structure data simulation

2019-05-18 Thread Daniel Nordlund
On 5/18/2019 1:03 PM, varin sacha via R-help wrote: Dear Boris, Yes, top-down, no problem. Many thanks, but in your code did you not forget "teacher" ? As a reminder teacher has to be nested with classes. I mean the 50 pupils belonging to C1 must be with (teacher 1) T1, the 50 pupils

Re: [R] Nested structure data simulation

2019-05-18 Thread varin sacha via R-help
Dear Boris, Yes, top-down, no problem. Many thanks, but in your code did you not forget "teacher" ? As a reminder teacher has to be nested with classes. I mean the 50 pupils belonging to C1 must be with (teacher 1) T1, the 50 pupils belonging to C2 with T2, the 50 pupils belonging to C3 with

Re: [R] Nested structure data simulation

2019-05-18 Thread Boris Steipe
Can you build your data top-down? schools <- paste("s", 1:6, sep="") classes <- character() for (school in schools) { classes <- c(classes, paste(school, paste("c", 1:5, sep=""), sep = ".")) } pupils <- character() for (class in classes) { pupils <- c(pupils, paste(class, paste("p", 1:10,

Re: [R] Nested structure data simulation

2019-05-18 Thread varin sacha via R-help
Many thanks Jeff and Linus, Yes to Jeff, OK with Linus but classroom <- rep(c("C1","C2","C3","C4","C5","C6"), 50) [sample(1:300)] how can I include the nested structure, I mean the teacher. Now, I would like the 50 pupils belonging to C1 with T1, the 50 pupils belonging to C2 with T2,

Re: [R] Nested structure data simulation

2019-05-18 Thread Jeff Newmiller
Wouldn't the students/teachers/schools be enumerated and the properties you are studying be random/correlated according to the enumerated values? On May 18, 2019 6:57:06 AM PDT, varin sacha via R-help wrote: >Dear R-Experts, > >In a data simulation, I would like a balanced distribution with a

[R] Nested structure data simulation

2019-05-18 Thread varin sacha via R-help
Dear R-Experts, In a data simulation, I would like a balanced distribution with a nested structure for classroom and teacher (not for school). I mean 50 pupils belonging to C1, 50 other pupils belonging to C2, 50 other pupils belonging to C3 and so on. Then I want the 50 pupils belonging to C1