cardillo / joinery

Data frames for Java
https://joinery.sh
GNU General Public License v3.0
697 stars 167 forks source link

Calculate covariance, is it posible? #54

Closed junajo10 closed 7 years ago

junajo10 commented 8 years ago

Could you show me a way to calculate the covariance of this Dataframe? 0 1 0_left 29789,00000000 29657,00000000 0_right 39140,00000000 26047,00000000 0 1380349,00000000 698550,00000000

Rgds,

JJ

junajo10 commented 8 years ago

I have tried to get double[][] and so i can use Apache Commons Math DataFrame mm = Conversion.toModelMatrixDataFrame(volumeTranspose); mm.apply(new Function() { public Number apply(Object value) { return Number.class.cast(value).doubleValue(); } }); System.out.println(mm); double[][] prueba = Conversion.toModelMatrix(mm, bin_size); System.out.println(mm)->argument type mismatch

RealMatrix mx = MatrixUtils.createRealMatrix(new double[][]{ {1, 2, 3}, {2, 4, 6} }); RealMatrix cov = new Covariance(mx).getCovarianceMatrix();

cardillo commented 7 years ago

I added a cov method which wraps up the process of converting the data to double[], calculating the covariance with commons math, and returning the results as a data frame. Upgrade to the 1.8 release to use it.