コード例 #1
0
ファイル: TTestImpl.java プロジェクト: mfwzan/astor
 /**
  * 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.
  *
  * @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 MathException if an error occurs computing the p-value
  */
 protected double homoscedasticTTest(
     double m1, double m2, double v1, double v2, double n1, double n2) throws MathException {
   double t = Math.abs(homoscedasticT(m1, m2, v1, v2, n1, n2));
   double degreesOfFreedom = n1 + n2 - 2;
   distribution.setDegreesOfFreedom(degreesOfFreedom);
   return 2.0 * distribution.cumulativeProbability(-t);
 }
コード例 #2
0
ファイル: TTestImpl.java プロジェクト: mfwzan/astor
 /**
  * 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.
  *
  * @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 MathException if an error occurs computing the p-value
  */
 protected double tTest(double m1, double m2, double v1, double v2, double n1, double n2)
     throws MathException {
   double t = Math.abs(t(m1, m2, v1, v2, n1, n2));
   double degreesOfFreedom = 0;
   degreesOfFreedom = df(v1, v2, n1, n2);
   distribution.setDegreesOfFreedom(degreesOfFreedom);
   return 2.0 * distribution.cumulativeProbability(-t);
 }
コード例 #3
0
 /**
  * Returns a matrix of p-values associated with the (two-sided) null hypothesis that the
  * corresponding correlation coefficient is zero.
  *
  * <p><code>getCorrelationPValues().getEntry(i,j)</code> is the probability that a random variable
  * distributed as <code>t<sub>n-2</sub></code> takes a value with absolute value greater than or
  * equal to <br>
  * <code>|r|((n - 2) / (1 - r<sup>2</sup>))<sup>1/2</sup></code>
  *
  * <p>The values in the matrix are sometimes referred to as the <i>significance</i> of the
  * corresponding correlation coefficients.
  *
  * @return matrix of p-values
  * @throws MathException if an error occurs estimating probabilities
  */
 public RealMatrix getCorrelationPValues() throws MathException {
   TDistribution tDistribution = new TDistributionImpl(nObs - 2);
   int nVars = correlationMatrix.getColumnDimension();
   double[][] out = new double[nVars][nVars];
   for (int i = 0; i < nVars; i++) {
     for (int j = 0; j < nVars; j++) {
       if (i == j) {
         out[i][j] = 0d;
       } else {
         double r = correlationMatrix.getEntry(i, j);
         double t = Math.abs(r * Math.sqrt((nObs - 2) / (1 - r * r)));
         out[i][j] = 2 * (1 - tDistribution.cumulativeProbability(t));
       }
     }
   }
   return new BlockRealMatrix(out);
 }
コード例 #4
0
 /**
  * Returns the significance level of the slope (equiv) correlation.
  *
  * <p>Specifically, the returned value is the smallest <code>alpha</code> such that the slope
  * confidence interval with significance level equal to <code>alpha</code> does not include <code>
  * 0</code>. On regression output, this is often denoted <code>Prob(|t| > 0)</code>
  *
  * <p><strong>Usage Note</strong>:<br>
  * The validity of this statistic depends on the assumption that the observations included in the
  * model are drawn from a <a href="http://mathworld.wolfram.com/BivariateNormalDistribution.html">
  * Bivariate Normal Distribution</a>.
  *
  * <p>If there are fewer that <strong>three</strong> observations in the model, or if there is no
  * variation in x, this returns <code>Double.NaN</code>.
  *
  * @return significance level for slope/correlation
  * @throws MathException if the significance level can not be computed.
  */
 public double getSignificance() throws MathException {
   return 2d * (1.0 - distribution.cumulativeProbability(Math.abs(getSlope()) / getSlopeStdErr()));
 }
コード例 #5
0
ファイル: TTestImpl.java プロジェクト: mfwzan/astor
 /**
  * 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 MathException if an error occurs computing the p-value
  */
 protected double tTest(double m, double mu, double v, double n) throws MathException {
   double t = Math.abs(t(m, mu, v, n));
   distribution.setDegreesOfFreedom(n - 1);
   return 2.0 * distribution.cumulativeProbability(-t);
 }