Ruby setup for polychoric correlation
download GSL
install GSL by './configure && make && sudo make install'
gem install gsl
gem install statsample
gem install statsample-bivariate-extension
Afterwards, let's try some toy examples. I am interest in polychoric correlation between two variables/raters.
calculate the polychoric correlation of the following cross table:
------------------- | y=0 | y=1 | y=2 | ------------------- x = 0 | 1 | 10 | 20 | ------------------- x = 1 | 20 | 20 | 50 | -------------------
matrix=Matrix[[1,10,20],[20,20,50]] poly=Statsample::Bivariate::Polychoric.new(matrix, :method=>:joint) puts poly.r
or
poly=Statsample::Bivariate::Polychoric.new_with_vectors([1,10,20].to_scale, [20,20,50].to_scale) puts poly.r
Replace Polychoric with Tetrachoric if your data is dichotomous instead of ordinal.
For more detail about polychoric/tetrachoric correlation, please see http://www.john-uebersax.com/stat/tetra.htm












