p-value calculation using Java

1.8k Views Asked by At

I want to make a Java program to calculate the P-value of my data that I want to upload, but getting too much trouble to do so. The data is been read by the Java program, but next step is to solve data for getting p-value.

The input file is:

The input Should be:- 

Name A B C
a 1.7085586 0.73179674 3.3962722
b 0.092749596 -0.10030079 -0.47453594
c 1.1727467 0.15784931 0.0572958
d -0.91714764 -0.62808895 -0.6190882
e 0.34570503 0.10605621 0.30304766
f 2.333506 -0.2063818 0.4022169
g 0.7893815 1.449388 1.5907407

And the Output should be like this:-
  
Name pValue
a 0.129618298
b 0.4363544
c 0.323631285
d 0.017916658
e 0.076331828
f 0.385619995
g 0.035449488

I have run this data in R program but I want to write some Java to solve this.

My Java code till now is:

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
 
public class Abc {

 public static void main(String[] args) {
  // TODO Auto-generated method stub

  BufferedReader br = null;
   
  try {
 
   String sCurrentLine;
 
   br = new BufferedReader(new FileReader("C:/Documents and Settings/Admin/Desktop/test.txt"));
 
   while ((sCurrentLine = br.readLine()) != null) {
    System.out.println(sCurrentLine);
    //output  = BufferedReader.getParser().getAsDoubleArray("br");
    
   }
 
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    if (br != null)br.close();
   } catch (IOException ex) {
    ex.printStackTrace();
   }
  }
 }
}

This is only reading my data and showing it in the console of Java. How to proceed?

1

There are 1 best solutions below

2
On BEST ANSWER

I think your are facing problem with retrieving and printing values from file. Below program gives output in required format :

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class Abc {

    public static void main(String[] args) {

        BufferedReader br = null;
        String sCurrentLine;

        try {

            br = new BufferedReader(new FileReader("C:/Documents and Settings/Admin/Desktop/test.txt"));

            // Override Default Header Row
            br.readLine();
            System.out.println("Name" + "\t" + "pValue");

            while ((sCurrentLine = br.readLine()) != null) {
                int i = 0;
                String str[] = sCurrentLine.split("\t");

                System.out.print(str[i] + "\t");

                Double dValue1 = Double.parseDouble(str[++i]);
                Double dValue2 = Double.parseDouble(str[++i]);
                Double dValue3 = Double.parseDouble(str[++i]);

                // Do pValue Calc here
                Double pValue = 1.2334;

                System.out.println(pValue);
            }

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (br != null)
                    br.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }
}