darkstar-42 avatar

The Chi-Squared-Distribution - Compute and visualize in Java

darkstar-42

Published: 21 Mar 2018 › Updated: 21 Mar 2018The Chi-Squared-Distribution - Compute and visualize in Java

The Chi-Squared-Distribution - Compute and visualize in Java

ChiQuadratVerteilung.png

Today I add the chi-square distribution to my collection.

Since the same parameters are used here as for the student's t-distribution, the GUI does not need to be extended.

Calculation of the distribution

    double dchisq(double x, int df) {
        if (x<=0) {
            return 0.0;
        }
        
        return
            (Math.pow(x, df/2.0 - 1.0) * Math.exp(-(x/2.0))) / 
            (Math.pow(2, df/2.0) * XMath.gamma(df/2.0));
    }
    
    public double qchisq(double alpha, int df) {
        double sum = 0;
        double pos = 0;
        double stepSize = 0.01;
        while (sum<alpha) {
            sum += dchisq(pos, df)*stepSize;
            pos += stepSize;
        }
        return pos;
    }

Other distributions:

Leave The Chi-Squared-Distribution - Compute and visualize in Java to:

Written by

Read more #programming posts


Best Posts From darkstar-42

We have not curated any of darkstar-42's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From darkstar-42