I have two 4*4 matrices in JAVA, where one matrix holds observed counts and the other expected counts.
I need an automated way to calculate the p-value from the chi-square statistic between these two matrices; however, JAVA has no such function as far as I am aware.
I can calculate the chi-square and its p-value by reading the two matrices into R as .csv file formats, and then using the chisq.test function as follows:
obs<-read.csv("obs.csv")
exp<-read.csv("exp.csv")
chisq.test(obs,exp)
where the format of the .csv files would as follows:
A, C, G, T
A, 197.136, 124.32, 63.492, 59.052
C, 124.32, 78.4, 40.04, 37.24
G, 63.492, 40.04, 20.449, 19.019
T, 59.052, 37.24, 19.019, 17.689
Given these commands, R will give an output of the format:
X-squared = 20.6236, df = 9, p-value = 0.01443
which includes the p-value I was looking for.
Does anyone know of an efficient way to automate the process of:
1) Outputting my matrices from JAVA into .csv files 2) Uploading the .csv files into R 3) Calling the chisq.test on the .csv files into R 4) Returning the outputted p-value back into JAVA?
Thanks for any help....