I'm trying to create a multilevel data structure for power simulation using 'simr' package.
The data has 5 columns: pupil, class, extroversion, teacher experience, pupil gender. Pupils are nested in class, extroversion (grand mean centered,range between -4.21 and 4.78) and gender are pupil level predictors, and teacher experience is class level predictor (grand mean centered, range from -12 to 11). I want the dataframe to contain 600 observation (pupils), 20 nested in each of the 30 classes.
I'm able to create the dataframe using the below code, but it's aesthetically unacceptable by many standards.Another issue is I hope pupil extraversion and teacher experience can be normally distributed, my code seems to output a smaller range..
library(truncnorm)
set.seed(123)
pupil <- as.factor(seq(1:600))
class <- as.factor(rep(1:30,20))
extrav<-rtruncnorm(n=600,a=-4.21,b=4.78)
X <- cbind(pupil=pupil,class=class, extrav=extrav)
class<-seq(1:30)
texp<-rtruncnorm(30,-12,11)
class_texp<-cbind(class,texp)
X<-merge(X,class_texp)
sex<-rep(1:2,300)
sex<-sex-1
X<-cbind(X,sex)
View(X)