我是 R 的初学者,我正在做一项模拟研究,我设法制作了一个我想做的样本。但是,我不知道应该如何复制我所做的。
这是我到目前为止编写的程序:
I <- 500 # number of observations
J <- 18 # total number of items
K <- 6 # number of testlets
JK <-3 # number of items within a testlet
response <- matrix(0, I, J) # null binary (0, 1) response matrix
unit <- matrix(1, JK, 1) # unit vector
set.seed(1234)
# Multidimensional 3-pl model
pij <- function(a,b,c,theta,gamma) {c+(1-c)*(1/(1+exp(-1.7*a*(theta-b-gamma))))}
# Assigning a and b parameter values
a <- c(.8,.9,.7,.8,.9,.7,.8,.9,.7,.8,.9,.7,.8,.9,.7,.8,.9,.7)
b <-c(1,0,-1.5,1,0,-1.5,1,0,-1.5,1,0,-1.5,1,0,-1.5,1,0,-1.5)
# Assigning c-parameter, each 3 items (c-parameter & testlet effect)
#(small&small, small&large, large&small, large&large, mixed&small, mixed&large)
c <- c(.2,.2,.2,.2,.2,.2,.5,.5,.5,.5,.5,.5,.2,.33,.5,.2,.33,.5)
theta <- rnorm(I, 0, 1) # random sampling theta-values from normal dist. M=0, SD=1
gamma1 <- rnorm(I, 0, .2) # small testlet effect: random sampling gamma from normal dist. M=0, SD=.2
gamma2 <- rnorm(I, 0, 1) # large testlet effect: random sampling gamma from normal dist. M=0, SD=1
gamma3 <- rnorm(I, 0, .2) # small testlet effect: random sampling gamma from normal dist. M=0, SD=.2
gamma4 <- rnorm(I, 0, 1) # large testlet effect: random sampling gamma from normal dist. M=0, SD=1
gamma5 <- rnorm(I, 0, .2) # small testlet effect: random sampling gamma from normal dist. M=0, SD=.2
gamma6 <- rnorm(I, 0, 1) # large testlet effect: random sampling gamma from normal dist. M=0, SD=1
# implementing that the testlet effect is same for the items within a testlet
gamma1T <- gamma1 %*% t(unit)
gamma2T <- gamma2 %*% t(unit)
gamma3T <- gamma3 %*% t(unit)
gamma4T <- gamma4 %*% t(unit)
gamma5T <- gamma5 %*% t(unit)
gamma6T <- gamma6 %*% t(unit)
gammaT <- matrix(c(gamma1T, gamma2T, gamma3T, gamma4T, gamma5T, gamma6T), I, J) # getting all the gammas together in a large matrix
# Generating data using the information above
for(i in 1:I) {
for(j in 1:J) {
response[i, j] <- ifelse(pij(a=a[j], b=b[j], c=c[j], theta=theta[i], gamma=gammaT[i,j]) < runif(1), 0, 1)
}
}
因此,我得到了一个数据集“响应”。我想要做的是复制它并获得 1000 个“响应”数据集。我认为这可以通过复制“theta”和“gamma”的随机抽样来完成,但我不知道实际这样做。
非常非常感谢提前,
韩乔。