search for: samplecop

Displaying 1 result from an estimated 1 matches for "samplecop".

Did you mean: samplecode
2012 Sep 27
2
Generating an autocorrelated binary variable
...hat should be autocorrelated. The autocorrelation should be rho = 0.2. Furthermore, the overall probability to get either outcome of the binary variable should be 0.5. Below you can see the R code (I use for simplicity a diagonal matrix in rmvnorm even if it produces no correlated sample): "sampleCop" <- function(n = 1000, rho = 0.2) { require(splus2R) mvrs <- rmvnorm(n + 1, mean = rep(0, 3), cov = diag(3)) pmvrs <- pnorm(mvrs, 0, 1) var1 <- matrix(0, nrow = n + 1, ncol = 1) var1[1] <- qbinom(pmvrs[1, 1], 1, 0.5) if(var1[1] == 0) var1[nrow(mvrs)] <- -1 for(i in...