这是否有理由仅适用于一个样本量,但增加时不起作用?经过一段时间的努力,n = 100运行正常。这是一种模拟,它针对X1,X2和错误生成数据,然后使用这些值来计算Y值。
###Change to sample size n2=300
n1<-100
n2<- 300
n3 <- 1000
ITER <- 500
#set beta coefficients
B0 <- 1
B1 <- 1
B2 <- 1
B3_1 <-1
B3_2 <- 2
B3_3 <- 5
#set gamma values
c1 <-.1
c2 <- .25
c3 <- .75
sim10 <- matrix(data = 0, nrow = ITER, ncol = 4)
colnames(sim10) <- c("Y", "X1", "X2", "E")
# simulate X1s,
for (i in 1:ITER){
sim10[,2] <-runif(n2, -3, 3)
}
# simulate X2s
for(i in 1:ITER){
sim10[,3] <- (c1*sim10[,2])+ rnorm(n2,0,1)
}
# simulate error
for(i in 1:ITER){
sim10[,4] <- dnorm(300, 0,1)
}
# y's
for(i in 1:ITER)
sim10[,1] <- B0+ B1*sim10[,2] + B2*sim10[,3] + B3_1*(sim10[,3]^2) +
sim10[,4]