/** * Generates a random value from the {@link TDistribution T Distribution}. * * @param df the degrees of freedom of the T distribution * @return random value from the T(df) distribution * @throws NotStrictlyPositiveException if {@code df <= 0} */ public double nextT(double df) throws NotStrictlyPositiveException { return new TDistribution(getRandomGenerator(), df, TDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).sample(); }
public double [] pValues(){ double [] res = zValues(); RealDistribution rd = _dispersionEstimated?new TDistribution(_training_metrics.residual_degrees_of_freedom()):new NormalDistribution(); for(int i = 0; i < res.length; ++i) res[i] = 2*rd.cumulativeProbability(-Math.abs(res[i])); return res; } double[][] _global_beta_multinomial;
/** * Computes p-value for 2-sided, 1-sample t-test. * * @param m sample mean * @param mu constant to test against * @param v sample variance * @param n sample n * @return p-value * @throws MaxCountExceededException if an error occurs computing the p-value * @throws MathIllegalArgumentException if n is not greater than 1 */ protected double tTest(final double m, final double mu, final double v, final double n) throws MaxCountExceededException, MathIllegalArgumentException { final double t = FastMath.abs(t(m, mu, v, n)); // pass a null rng to avoid unneeded overhead as we will not sample from this distribution final TDistribution distribution = new TDistribution(null, n - 1); return 2.0 * distribution.cumulativeProbability(-t); }
/** * Computes p-value for 2-sided, 2-sample t-test, under the assumption * of equal subpopulation variances. * <p> * The sum of the sample sizes minus 2 is used as degrees of freedom.</p> * * @param m1 first sample mean * @param m2 second sample mean * @param v1 first sample variance * @param v2 second sample variance * @param n1 first sample n * @param n2 second sample n * @return p-value * @throws MaxCountExceededException if an error occurs computing the p-value * @throws NotStrictlyPositiveException if the estimated degrees of freedom is not * strictly positive */ protected double homoscedasticTTest(double m1, double m2, double v1, double v2, double n1, double n2) throws MaxCountExceededException, NotStrictlyPositiveException { final double t = FastMath.abs(homoscedasticT(m1, m2, v1, v2, n1, n2)); final double degreesOfFreedom = n1 + n2 - 2; // pass a null rng to avoid unneeded overhead as we will not sample from this distribution final TDistribution distribution = new TDistribution(null, degreesOfFreedom); return 2.0 * distribution.cumulativeProbability(-t); }
TDistribution distribution = new TDistribution(n - 2); return getSlopeStdErr() * distribution.inverseCumulativeProbability(1d - alpha / 2d);
/** * Computes p-value for 2-sided, 2-sample t-test. * <p> * Does not assume subpopulation variances are equal. Degrees of freedom * are estimated from the data.</p> * * @param m1 first sample mean * @param m2 second sample mean * @param v1 first sample variance * @param v2 second sample variance * @param n1 first sample n * @param n2 second sample n * @return p-value * @throws MaxCountExceededException if an error occurs computing the p-value * @throws NotStrictlyPositiveException if the estimated degrees of freedom is not * strictly positive */ protected double tTest(final double m1, final double m2, final double v1, final double v2, final double n1, final double n2) throws MaxCountExceededException, NotStrictlyPositiveException { final double t = FastMath.abs(t(m1, m2, v1, v2, n1, n2)); final double degreesOfFreedom = df(v1, v2, n1, n2); // pass a null rng to avoid unneeded overhead as we will not sample from this distribution final TDistribution distribution = new TDistribution(null, degreesOfFreedom); return 2.0 * distribution.cumulativeProbability(-t); }
TDistribution distribution = new TDistribution(n - 2); return 2d * (1.0 - distribution.cumulativeProbability( FastMath.abs(getSlope()) / getSlopeStdErr()));
TDistribution tDistribution = new TDistribution(nObs - 2); int nVars = correlationMatrix.getColumnDimension(); double[][] out = new double[nVars][nVars];
public static double getPvalue(final double corr, final double n) { double t = Math.abs(corr * Math.sqrt( (n-2.0) / (1.0 - (corr * corr)) )); System.out.println(" t = "+ t); TDistribution tdist = new TDistribution(n-2); double pvalue = 2* (1.0 - tdist.cumulativeProbability(t)); // p-value worked. return pvalue; }
public static double getPvalue(double corr, double n) { double t = Math.abs(corr * Math.sqrt( (n-2.0) / (1.0 - (corr * corr)) )); System.out.println(" t = "+ t); TDistribution tdist = new TDistribution(n-2); double pvalue = 2.0 * (1.0 - tdist.cumulativeProbability(t)); // p-value worked. return pvalue; }
/** * @param param * degrees of freedom * @return T-distribution */ protected TDistribution getTDistribution(double param) { if (t == null || t.getDegreesOfFreedom() != param) { t = new TDistribution(param); } return t; }
private static double getMarginOfError(double sd, double n, double confLevel) throws ArithmeticException { TDistribution tDist = new TDistribution(n - 1); double a = tDist.inverseCumulativeProbability((confLevel + 1d) / 2); return a * sd / Math.sqrt(n); }
/** * @param df The degrees of freedom. See any stats book. * @return Ibid. */ public double nextT(double df) { return new TDistribution(randomGenerator, df).sample(); }
/** * Generates a random value from the {@link TDistribution T Distribution}. * * @param df the degrees of freedom of the T distribution * @return random value from the T(df) distribution * @throws NotStrictlyPositiveException if {@code df <= 0} */ public double nextT(double df) throws NotStrictlyPositiveException { return new TDistribution(getRandomGenerator(), df, TDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).sample(); }
/** * Generates a random value from the {@link TDistribution T Distribution}. * * @param df the degrees of freedom of the T distribution * @return random value from the T(df) distribution * @throws NotStrictlyPositiveException if {@code df <= 0} */ public double nextT(double df) throws NotStrictlyPositiveException { return new TDistribution(getRandomGenerator(), df, TDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).sample(); }
public double [] pValues(){ double [] res = zValues(); RealDistribution rd = _dispersionEstimated?new TDistribution(_training_metrics.residual_degrees_of_freedom()):new NormalDistribution(); for(int i = 0; i < res.length; ++i) res[i] = 2*rd.cumulativeProbability(-Math.abs(res[i])); return res; } double[][] _global_beta_multinomial;
public double evaluate(Context context) { RandomGenerator randomGenerator = RandomUtil.getInstance().getRandomGenerator(); Expression exp1 = getExpressions().get(0); double e1 = exp1.evaluate(context); return new TDistribution(randomGenerator, e1).sample(); }
private void testLogPdfAtGivenDegreesOfFreedom(int v) { TDistribution apache = new TDistribution(v); StudentTVertex studentT = new StudentTVertex(v); for (double t = -4.5; t <= 4.5; t += 0.5) { double expected = apache.logDensity(t); double actual = studentT.logPdf(t); assertEquals(expected, actual, DELTA); } }
@Test public void logProbGraphMatchesKnownLogDensityOfScalar() { IntegerVertex v = ConstantVertex.of(1); StudentTVertex studentT = new StudentTVertex(v); LogProbGraph logProbGraph = studentT.logProbGraph(); LogProbGraphValueFeeder.feedValue(logProbGraph, v, v.getValue()); LogProbGraphValueFeeder.feedValue(logProbGraph, studentT, DoubleTensor.scalar(-4.5)); TDistribution distribution = new TDistribution(1); double expectedDensity = distribution.logDensity(-4.5); LogProbGraphContract.matchesKnownLogDensity(logProbGraph, expectedDensity); }
@Test public void logProbGraphMatchesKnownLogDensityOfVector() { IntegerVertex v = ConstantVertex.of(1, 1); StudentTVertex studentT = new StudentTVertex(v); LogProbGraph logProbGraph = studentT.logProbGraph(); LogProbGraphValueFeeder.feedValue(logProbGraph, v, v.getValue()); LogProbGraphValueFeeder.feedValue(logProbGraph, studentT, DoubleTensor.create(-4.5, 4.5)); TDistribution distribution = new TDistribution(1); double expectedDensity = distribution.logDensity(-4.5) + distribution.logDensity(4.5); LogProbGraphContract.matchesKnownLogDensity(logProbGraph, expectedDensity); }