[R] simulation data with dichotomous variables

thanoon younis thanoon.younis80 at gmail.com
Sat Aug 23 17:22:06 CEST 2014

```dear all members
i have a problem with the code below, my problem in this code i want to put
a high correlation between variables in group R1 and also put a high
correlation between variables in group R2. after checking the correlation
between variables in R1 also between variables in R2 i didn't find any
correlation btween variables in R1 and between variables in R2.
many thanks to Dr. William to help me to write this code and i hope to help
me to complete it.

many thanks to all

library(psych)
ords <- seq(0,1)
p <- 10
N <- 1000
percent_change <- 0.9
R1 <- sim.irt(10,1000,a=3,low = -2, high=2)
R2 <-  sim.irt(10,1000,a=3,low = -2, high=2)
R12 <- data.frame(R1\$items,R2\$items)
#this gives you 20 items, grouped with high correlations within the first
10, and the second 10, no correlation between the first and second sets.
rho <- tetrachoric(R12)\$rho  #find the tetrachoric correlation between the
items
lowerMat(rho)  #show the correlations
cor.plot(rho,numbers=TRUE)   #show a heat map of the correlations

R1 <- as.data.frame(replicate(p, sample(ords, N, replace = T)))
R2 <- as.data.frame(replicate(p, sample(ords, N, replace = T)))
rho <- tetrachoric(R12)\$rho  #find the tetrachoric correlation between the
items
lowerMat(rho)  #show the correlations
R1
R2

[[alternative HTML version deleted]]

```