【问题标题】:p-value calculation using Java使用 Java 计算 p 值
【发布时间】:2015-06-01 06:58:07
【问题描述】:

我想编写一个 Java 程序来计算我要上传的数据的 P 值,但是这样做太麻烦了。 Java程序已读取数据,但下一步是求解数据以获得p值。

输入文件是:

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

我已经在 R 程序中运行了这些数据,但我想编写一些 Java 来解决这个问题。

到目前为止,我的 Java 代码是:

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();
			}
		}
	}
}

这只是读取我的数据并将其显示在 Java 控制台中。如何进行?

【问题讨论】:

    标签: rjava rcaller


    【解决方案1】:

    我认为您在从文件中检索和打印值时遇到了问题。以下程序以所需格式提供输出:

    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();
                }
            }
        }
    }
    

    【讨论】:

    • 再次感谢,但我想解决它以提供 P 值....帮我解决上面给出的数据的查询
    • 基本上我希望java代码计算P值来解决数据....而stackflow中有关p值的信息并没有给我任何具体的指导
    猜你喜欢
    • 2017-11-30
    • 2017-12-20
    • 2014-06-23
    • 2017-11-13
    • 2018-10-12
    • 2014-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多