[R] trouble double looping to generate data for a meta-analysis
Marietta Suarez
marietta0423 at gmail.com
Fri Jul 1 19:28:26 CEST 2016
i'm trying to generate data for a meta analysis. 1- generate data following
a normal distribution, 2- generate data following a skewed distribution, 3-
generate data following a logistic distribution. i need to loop this
because the # of studies in each meta will be either 10 or 15. k or total
number of studies in the meta will be 5. i need to loop twice to repeat
this process 10 times. database should be 3 columns (distributions) by 65
rows x 10 reps
here's my code, not sure what's not working:
library(fGarch)
#n reps =10
rep=10
#begin function here, need to vary n and k, when k=2 n=10, when k3 n=15
fun=function(n, k){
#prepare to store data
data=matrix(0,nrow=10*k, ncol=3)
db=matrix(0,nrow=650, ncol=3)
for (j in 1:rep)
{
for (i in 1:k)
{
#generate data under normal, skewed, and logistic distributions here
data[,1]=rnorm(n, 100, 15)
data[,2]=rsnorm(n, 100, 15, 1)
data[,3]=rlogis(n, 100, 15)
}
[j]=db
}
}
save=fun(10,2)
Please help!!!
[[alternative HTML version deleted]]
More information about the R-help
mailing list