java实现f检验

作者: lazyM | 来源:发表于2020-03-16 11:21 被阅读0次

    描述

    用于两个总体方差之间的比较。

    Demo

    public class FtestDemo {
    
        /**
         * two-sided test
         * @param args
         */
        public static void main(String[] args) {
            double[] x= {300,280,344,385,372,360,288,321,376,290,301,283};
            double[] y= {274,220,308,336,198,300,315,258,318,310,332,263};
            Ftest f=new Ftest(x, y);
            System.out.println(f.getPValue());
    
        }
    
    }
    
    

    代码

    package com.math.statistics;
    
    import org.apache.commons.math3.stat.descriptive.moment.Variance;
    
    import JSci.maths.statistics.FDistribution;
    /***
     * @author miaoyibo
     *
     */
    public class Ftest {
        private double[] x;
    
        private double[] y;
    
        Variance variance = new Variance();
    
        public Ftest(double[] x, double[] y) {
            super();
            this.x = x;
            this.y = y;
        }
    
        public double[] getX() {
            return x;
        }
    
        public void setX(double[] x) {
            this.x = x;
        }
    
        public double[] getY() {
            return y;
        }
    
        public void setY(double[] y) {
            this.y = y;
        }
    
        public double getXDegreesOfFreedom() {
            return x.length - 1;
        }
    
        public double getYDegreesOfFreedom() {
            return y.length - 1;
        }
    
        public double getXVariance() {
    
            return variance.evaluate(x);
        }
    
        public double getYVariance() {
    
            return variance.evaluate(y);
        }
    
        public double getPValue() {
            double q=getXVariance()*getXVariance();
            double p=getYVariance()*getYVariance();
            double f=q/p;
            FDistribution fd=new FDistribution(x.length - 1, y.length - 1);
            double cumulative = fd.cumulative(f);
            return (1-cumulative)*2;
        }
    }
    
    

    相关文章

      网友评论

        本文标题:java实现f检验

        本文链接:https://www.haomeiwen.com/subject/bnzwehtx.html