# NOT RUN {
if(require(mvtnorm)){
set.seed(12345)
data <- rmvnorm(1000, c(0, 0), matrix(c(1, .5, .5, 1), 2, 2))
x <- data[,1]
y <- data[,2]
cor(x, y) # sample correlation
}
if(require(mvtnorm)){
x <- cut(x, c(-Inf, .75, Inf))
y <- cut(y, c(-Inf, -1, .5, 1.5, Inf))
print(polychor(x, y, ML=TRUE, std.err=TRUE),
digits=3) # polychoric correlation, ML estimate
}
if(require(mvtnorm)){
coef(polychor(x, y, ML=TRUE, std.err=TRUE))
}
if(require(mvtnorm)){
vcov(polychor(x, y, ML=TRUE, std.err=TRUE))
}
# }
Run the code above in your browser using DataLab