• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java TDistributionImpl类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.commons.math.distribution.TDistributionImpl的典型用法代码示例。如果您正苦于以下问题:Java TDistributionImpl类的具体用法?Java TDistributionImpl怎么用?Java TDistributionImpl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TDistributionImpl类属于org.apache.commons.math.distribution包,在下文中一共展示了TDistributionImpl类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: calculateLogPosteriorPredictiveCDF

import org.apache.commons.math.distribution.TDistributionImpl; //导入依赖的package包/类
public double calculateLogPosteriorPredictiveCDF(double value, boolean upperTail){
    double mean = currentParameters[0];
    double sd = Math.sqrt(currentParameters[3]*(currentParameters[1]+1)
            /(currentParameters[2]*currentParameters[1]));
    double scaledValue = (value - mean)/sd;
    double out;

    if(2*currentParameters[2]<=normalApproximationThreshold) {
        TDistributionImpl tDist = new TDistributionImpl(2 * currentParameters[2]);

        try {
            out = upperTail ? Math.log(tDist.cumulativeProbability(-scaledValue))
                    : Math.log(tDist.cumulativeProbability(scaledValue));
        } catch (MathException e){
            throw new RuntimeException(e.toString());
        }

    } else {

        out =  upperTail ? NormalDistribution.standardCDF(-scaledValue, true) :
                NormalDistribution.standardCDF(scaledValue, true);

    }
    return out;
}
 
开发者ID:beast-dev,项目名称:beast-mcmc,代码行数:26,代码来源:NormalPeriodPriorDistribution.java


示例2: pairedTTest

import org.apache.commons.math.distribution.TDistributionImpl; //导入依赖的package包/类
/**
   * @return result of T-test between baseline and treatment
   */
  public double pairedTTest() {       
      double sampleSum = 0;
      double sampleSumSquares = 0;
      int n = baseline.length;
      
      for( int i=0; i<baseline.length; i++ ) {
          double delta = treatment[i] - baseline[i];
          sampleSum += delta;
          sampleSumSquares += delta*delta;
      }
     
      double sampleVariance = sampleSumSquares / (n - 1);
      double sampleMean = sampleSum / baseline.length;
      
      double sampleDeviation = Math.sqrt(sampleVariance);
      double meanDeviation = sampleDeviation / Math.sqrt(n);
      double t = sampleMean / meanDeviation;
      
      try {
	return 1.0 - new TDistributionImpl(n).cumulativeProbability(t);
} catch (MathException e) {
	throw new RuntimeException(e);
}
  }
 
开发者ID:openimaj,项目名称:openimaj,代码行数:28,代码来源:SetRetrievalComparator.java


示例3: getCorrelationPValues

import org.apache.commons.math.distribution.TDistributionImpl; //导入依赖的package包/类
/**
 * 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>
 * <p>The values in the matrix are sometimes referred to as the
 * <i>significance</i> of the corresponding correlation coefficients.</p>
 *
 * @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);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:31,代码来源:PearsonsCorrelation.java


示例4: testStdErrorConsistency

import org.apache.commons.math.distribution.TDistributionImpl; //导入依赖的package包/类
/**
 * Verify that direct t-tests using standard error estimates are consistent
 * with reported p-values
 */
public void testStdErrorConsistency() throws Exception {
    TDistribution tDistribution = new TDistributionImpl(45);
    RealMatrix matrix = createRealMatrix(swissData, 47, 5);
    PearsonsCorrelation corrInstance = new PearsonsCorrelation(matrix);
    RealMatrix rValues = corrInstance.getCorrelationMatrix();
    RealMatrix pValues = corrInstance.getCorrelationPValues();
    RealMatrix stdErrors = corrInstance.getCorrelationStandardErrors();
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < i; j++) {
            double t = Math.abs(rValues.getEntry(i, j)) / stdErrors.getEntry(i, j);
            double p = 2 * (1 - tDistribution.cumulativeProbability(t));
            assertEquals(p, pValues.getEntry(i, j), 10E-15);
        }
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:20,代码来源:PearsonsCorrelationTest.java


示例5: getCorrelationPValues

import org.apache.commons.math.distribution.TDistributionImpl; //导入依赖的package包/类
/**
 * 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>
 * <p>The values in the matrix are sometimes referred to as the
 * <i>significance</i> of the corresponding correlation coefficients.</p>
 *
 * @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 = FastMath.abs(r * FastMath.sqrt((nObs - 2)/(1 - r * r)));
                out[i][j] = 2 * tDistribution.cumulativeProbability(-t);
            }
        }
    }
    return new BlockRealMatrix(out);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:31,代码来源:PearsonsCorrelation.java


示例6: addData

import org.apache.commons.math.distribution.TDistributionImpl; //导入依赖的package包/类
/**
 * Adds the observation (x,y) to the regression data set.
 * <p>
 * Uses updating formulas for means and sums of squares defined in
 * "Algorithms for Computing the Sample Variance: Analysis and
 * Recommendations", Chan, T.F., Golub, G.H., and LeVeque, R.J.
 * 1983, American Statistician, vol. 37, pp. 242-247, referenced in
 * Weisberg, S. "Applied Linear Regression". 2nd Ed. 1985.</p>
 *
 *
 * @param x independent variable value
 * @param y dependent variable value
 */
public void addData(double x, double y) {
    if (n == 0) {
        xbar = x;
        ybar = y;
    } else {
        double dx = x - xbar;
        double dy = y - ybar;
        sumXX += dx * dx * (double) n / (n + 1d);
        sumYY += dy * dy * (double) n / (n + 1d);
        sumXY += dx * dy * (double) n / (n + 1d);
        xbar += dx / (n + 1.0);
        ybar += dy / (n + 1.0);
    }
    sumX += x;
    sumY += y;
    n++;

    if (n > 2) {
        distribution = new TDistributionImpl(n - 2);
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:35,代码来源:SimpleRegression.java


示例7: removeData

import org.apache.commons.math.distribution.TDistributionImpl; //导入依赖的package包/类
/**
 * Removes the observation (x,y) from the regression data set.
 * <p>
 * Mirrors the addData method.  This method permits the use of
 * SimpleRegression instances in streaming mode where the regression
 * is applied to a sliding "window" of observations, however the caller is
 * responsible for maintaining the set of observations in the window.</p>
 *
 * The method has no effect if there are no points of data (i.e. n=0)
 *
 * @param x independent variable value
 * @param y dependent variable value
 */
public void removeData(double x, double y) {
    if (n > 0) {
        double dx = x - xbar;
        double dy = y - ybar;
        sumXX -= dx * dx * (double) n / (n - 1d);
        sumYY -= dy * dy * (double) n / (n - 1d);
        sumXY -= dx * dy * (double) n / (n - 1d);
        xbar -= dx / (n - 1.0);
        ybar -= dy / (n - 1.0);
        sumX -= x;
        sumY -= y;
        n--;

        if (n > 2) {
            distribution = new TDistributionImpl(n - 2);
        }
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:32,代码来源:SimpleRegression.java


示例8: testStdErrorConsistency

import org.apache.commons.math.distribution.TDistributionImpl; //导入依赖的package包/类
/**
 * Verify that direct t-tests using standard error estimates are consistent
 * with reported p-values
 */
public void testStdErrorConsistency() throws Exception {
    TDistribution tDistribution = new TDistributionImpl(45);
    RealMatrix matrix = createRealMatrix(swissData, 47, 5);
    PearsonsCorrelation corrInstance = new PearsonsCorrelation(matrix);
    RealMatrix rValues = corrInstance.getCorrelationMatrix();
    RealMatrix pValues = corrInstance.getCorrelationPValues();
    RealMatrix stdErrors = corrInstance.getCorrelationStandardErrors();
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < i; j++) {
            double t = FastMath.abs(rValues.getEntry(i, j)) / stdErrors.getEntry(i, j);
            double p = 2 * (1 - tDistribution.cumulativeProbability(t));
            assertEquals(p, pValues.getEntry(i, j), 10E-15);
        }
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:20,代码来源:PearsonsCorrelationTest.java


示例9: testStdErrorConsistency

import org.apache.commons.math.distribution.TDistributionImpl; //导入依赖的package包/类
/**
 * Verify that direct t-tests using standard error estimates are consistent
 * with reported p-values
 */
@Test
public void testStdErrorConsistency() throws Exception {
    TDistribution tDistribution = new TDistributionImpl(45);
    RealMatrix matrix = createRealMatrix(swissData, 47, 5);
    PearsonsCorrelation corrInstance = new PearsonsCorrelation(matrix);
    RealMatrix rValues = corrInstance.getCorrelationMatrix();
    RealMatrix pValues = corrInstance.getCorrelationPValues();
    RealMatrix stdErrors = corrInstance.getCorrelationStandardErrors();
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < i; j++) {
            double t = FastMath.abs(rValues.getEntry(i, j)) / stdErrors.getEntry(i, j);
            double p = 2 * (1 - tDistribution.cumulativeProbability(t));
            Assert.assertEquals(p, pValues.getEntry(i, j), 10E-15);
        }
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:21,代码来源:PearsonsCorrelationTest.java


示例10: getCorrelationPValues

import org.apache.commons.math.distribution.TDistributionImpl; //导入依赖的package包/类
/**
 * 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>
 * <p>The values in the matrix are sometimes referred to as the 
 * <i>significance</i> of the corresponding correlation coefficients.</p>
 * 
 * @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);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:31,代码来源:PearsonsCorrelation.java


示例11: testStdErrorConsistency

import org.apache.commons.math.distribution.TDistributionImpl; //导入依赖的package包/类
/**
 * Verify that direct t-tests using standard error estimates are consistent
 * with reported p-values
 */
public void testStdErrorConsistency() throws Exception {
    TDistribution tDistribution = new TDistributionImpl(45);
    RealMatrix matrix = createRealMatrix(swissData, 47, 5);
    PearsonsCorrelation corrInstance = new PearsonsCorrelation(matrix); 
    RealMatrix rValues = corrInstance.getCorrelationMatrix();
    RealMatrix pValues = corrInstance.getCorrelationPValues();
    RealMatrix stdErrors = corrInstance.getCorrelationStandardErrors();
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < i; j++) {
            double t = Math.abs(rValues.getEntry(i, j)) / stdErrors.getEntry(i, j);
            double p = 2 * (1 - tDistribution.cumulativeProbability(t));
            assertEquals(p, pValues.getEntry(i, j), 10E-15);
        }
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:20,代码来源:PearsonsCorrelationTest.java


示例12: getResultWithStatistics

import org.apache.commons.math.distribution.TDistributionImpl; //导入依赖的package包/类
private LeastSquaresRegressionResult getResultWithStatistics(final double[][] x, final double[][] w, final double[] y, final double[] betas,
    final double[] yModel, final DoubleMatrix2D transpose, final DoubleMatrix2D matrix, final boolean useIntercept) {
  double yMean = 0.;
  for (final double y1 : y) {
    yMean += y1;
  }
  yMean /= y.length;
  double totalSumOfSquares = 0.;
  double errorSumOfSquares = 0.;
  final int n = x.length;
  final int k = betas.length;
  final double[] residuals = new double[n];
  final double[] standardErrorsOfBeta = new double[k];
  final double[] tStats = new double[k];
  final double[] pValues = new double[k];
  for (int i = 0; i < n; i++) {
    totalSumOfSquares += w[i][i] * (y[i] - yMean) * (y[i] - yMean);
    residuals[i] = y[i] - yModel[i];
    errorSumOfSquares += w[i][i] * residuals[i] * residuals[i];
  }
  final double regressionSumOfSquares = totalSumOfSquares - errorSumOfSquares;
  final double[][] covarianceBetas = convertArray(_algebra.inverse(_algebra.mult(transpose, matrix)).toArray());
  final double rSquared = regressionSumOfSquares / totalSumOfSquares;
  final double adjustedRSquared = 1. - (1 - rSquared) * (n - 1) / (n - k);
  final double meanSquareError = errorSumOfSquares / (n - k);
  final ContinuousDistribution studentT = new TDistributionImpl(n - k);
  for (int i = 0; i < k; i++) {
    standardErrorsOfBeta[i] = Math.sqrt(meanSquareError * covarianceBetas[i][i]);
    tStats[i] = betas[i] / standardErrorsOfBeta[i];
    try {
      pValues[i] = 1 - studentT.cumulativeProbability(Math.abs(tStats[i]));
    } catch (final org.apache.commons.math.MathException e) {
      throw new com.opengamma.analytics.math.MathException(e);
    }
  }
  return new WeightedLeastSquaresRegressionResult(betas, residuals, meanSquareError, standardErrorsOfBeta, rSquared, adjustedRSquared, tStats, pValues,
      useIntercept);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:39,代码来源:WeightedLeastSquaresRegression.java


示例13: getResultWithStatistics

import org.apache.commons.math.distribution.TDistributionImpl; //导入依赖的package包/类
private LeastSquaresRegressionResult getResultWithStatistics(final double[][] x, final double[] y, final double[] betas, final double[] yModel, final DoubleMatrix2D transpose,
    final DoubleMatrix2D matrix, final boolean useIntercept) {
  double yMean = 0.;
  for (final double y1 : y) {
    yMean += y1;
  }
  yMean /= y.length;
  double totalSumOfSquares = 0.;
  double errorSumOfSquares = 0.;
  final int n = x.length;
  final int k = betas.length;
  final double[] residuals = new double[n];
  final double[] stdErrorBetas = new double[k];
  final double[] tStats = new double[k];
  final double[] pValues = new double[k];
  for (int i = 0; i < n; i++) {
    totalSumOfSquares += (y[i] - yMean) * (y[i] - yMean);
    residuals[i] = y[i] - yModel[i];
    errorSumOfSquares += residuals[i] * residuals[i];
  }
  final double regressionSumOfSquares = totalSumOfSquares - errorSumOfSquares;
  final double[][] covarianceBetas = convertArray(_algebra.inverse(_algebra.mult(transpose, matrix)).toArray());
  final double rSquared = regressionSumOfSquares / totalSumOfSquares;
  final double adjustedRSquared = 1. - (1 - rSquared) * (n - 1.) / (n - k);
  final double meanSquareError = errorSumOfSquares / (n - k);
  final ContinuousDistribution studentT = new TDistributionImpl(n - k);
  // final ProbabilityDistribution<Double> studentT = new
  // StudentTDistribution(n - k);
  for (int i = 0; i < k; i++) {
    stdErrorBetas[i] = Math.sqrt(meanSquareError * covarianceBetas[i][i]);
    tStats[i] = betas[i] / stdErrorBetas[i];
    try {
      pValues[i] = 1 - studentT.cumulativeProbability(Math.abs(tStats[i]));
    } catch (final org.apache.commons.math.MathException e) {
      throw new com.opengamma.analytics.math.MathException(e);
    }
  }
  return new LeastSquaresRegressionResult(betas, residuals, meanSquareError, stdErrorBetas, rSquared, adjustedRSquared, tStats, pValues, useIntercept);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:40,代码来源:OrdinaryLeastSquaresRegression.java


示例14: testNextT

import org.apache.commons.math.distribution.TDistributionImpl; //导入依赖的package包/类
public void testNextT() throws Exception {
    double[] quartiles = TestUtils.getDistributionQuartiles(new TDistributionImpl(10));
    long[] counts = new long[4];
    randomData.reSeed(1000);
    for (int i = 0; i < 1000; i++) {
        double value = randomData.nextT(10);
        TestUtils.updateCounts(value, counts, quartiles);
    }
    TestUtils.assertChiSquareAccept(expected, counts, 0.001);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:11,代码来源:RandomDataTest.java


示例15: testNextT

import org.apache.commons.math.distribution.TDistributionImpl; //导入依赖的package包/类
@Test
public void testNextT() throws Exception {
    double[] quartiles = TestUtils.getDistributionQuartiles(new TDistributionImpl(10));
    long[] counts = new long[4];
    randomData.reSeed(1000);
    for (int i = 0; i < 1000; i++) {
        double value = randomData.nextT(10);
        TestUtils.updateCounts(value, counts, quartiles);
    }
    TestUtils.assertChiSquareAccept(expected, counts, 0.001);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:12,代码来源:RandomDataTest.java


示例16: getDeltaBound

import org.apache.commons.math.distribution.TDistributionImpl; //导入依赖的package包/类
/**
 * Returns the delta between the mean and the lower(x1)/upper(x2) bound as
 * positive number. That is, the probabilistic bounds of x1 and x2 are given
 * by x1 <= mean <= x2 <=> mean-delta <= mean <= mean + delta
 * 
 * @param sdev
 *            the given standard deviation
 * @param n
 *            the given sample size
 * @param alpha
 *            the given significance level
 * @return the upper/lower bound as positive number
 */
public static double getDeltaBound(double sdev, int n, double alpha) {
	TDistribution tDist = new TDistributionImpl(n - 1);
	double errorConfCoeff = 1d - (alpha / 2);
	double delta;
	try {
		double t = Math.abs(tDist
				.inverseCumulativeProbability(errorConfCoeff));
		delta = t * sdev / Math.sqrt(n);
	} catch (MathException e) {
		throw new IllegalStateException(e);
	}
	return delta;
}
 
开发者ID:flyroom,项目名称:PeerfactSimKOM_Clone,代码行数:27,代码来源:ConfidenceInterval.java


示例17: TTestImpl

import org.apache.commons.math.distribution.TDistributionImpl; //导入依赖的package包/类
/**
 * Default constructor.
 */
public TTestImpl() {
    this(new TDistributionImpl(1.0));
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:7,代码来源:TTestImpl.java



注:本文中的org.apache.commons.math.distribution.TDistributionImpl类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Identifier类代码示例发布时间:2022-05-22
下一篇:
Java ColumnFamilyHandle类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap