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
y <- cut(y, c(-Inf, -1, .5, 1.5, Inf))
polyserial(x, y) # 2-step estimate
polyserial(x, y, ML=TRUE, std.err=TRUE) # ML estimate
Run the code above in your browser using DataLab