当前位置: 首页>>代码示例>>Java>>正文


Java TDistribution类代码示例

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


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

示例1: testStdErrorConsistency

import org.apache.commons.math3.distribution.TDistribution; //导入依赖的package包/类
/**
 * Verify that direct t-tests using standard error estimates are consistent
 * with reported p-values
 */
@Test
public void testStdErrorConsistency() {
    TDistribution tDistribution = new TDistribution(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:Quanticol,项目名称:CARMA,代码行数:21,代码来源:PearsonsCorrelationTest.java

示例2: solveStudentNewsvendor

import org.apache.commons.math3.distribution.TDistribution; //导入依赖的package包/类
public static Newsvendor solveStudentNewsvendor (final double price, final double cost, final double mu, final double scale, final double deg, final double[] sample) {
	final TDistribution dist = new TDistribution(deg);
	return new Newsvendor(price,cost) {{
		_safetyfactor = dist.inverseCumulativeProbability((price-cost)/price);
		_quantity = mu+scale*Math.sqrt((deg/(deg-2)))*_safetyfactor;
		_profit = getProfit(_quantity);
	}
	@Override
	public double getProfit(double quantity) {
		double profit = -quantity*cost;
		for (int i=0; i<sample.length; i++) {
			double demand = sample[i];
			profit += Math.min(quantity,demand)*price/sample.length;
		}
		return profit;
	}};
}
 
开发者ID:loehndorf,项目名称:scengen,代码行数:18,代码来源:Newsvendor.java

示例3: testReductionToStudentT

import org.apache.commons.math3.distribution.TDistribution; //导入依赖的package包/类
@Test
public void testReductionToStudentT() {
    double mean = 0;
    double variance = 1;
    RealVector meanVector = new ArrayRealVector(1);
    meanVector.setEntry(0, mean);
    RealMatrix varianceMatrix = MatrixUtils.createRealIdentityMatrix(1).scalarMultiply(variance);

    int N = 4300;
    MultivariateTDistribution multiT = new MultivariateTDistribution(meanVector, varianceMatrix, N);
    TDistribution uniT = new TDistribution(N);

    double[] testPoints = {0.5, 1, 2, 3, 15, 13.3, 17.6, 19.2, 300.2, 10.4};

    RealVector v = new ArrayRealVector(1);
    for (double x : testPoints) {
        v.setEntry(0, x);
        assertEquals(uniT.density(x), multiT.density(v), 1e-5);
    }
}
 
开发者ID:stanford-futuredata,项目名称:macrobase,代码行数:21,代码来源:MultivariateTDistributionTest.java

示例4: getT

import org.apache.commons.math3.distribution.TDistribution; //导入依赖的package包/类
@Override
public RandomNumberDistribution<Double> getT(final RandomNumberStream rng,
		final Number degreesOfFreedom)
{
	final RealDistribution dist = new TDistribution(
			RandomNumberStream.Util.asCommonsRandomGenerator(rng),
			degreesOfFreedom.doubleValue());
	return new RandomNumberDistribution<Double>()
	{
		@Override
		public Double draw()
		{
			return dist.sample();
		}
	};
}
 
开发者ID:krevelen,项目名称:coala,代码行数:17,代码来源:RandomDistributionFactoryImpl.java

示例5: getCorrelationPValues

import org.apache.commons.math3.distribution.TDistribution; //导入依赖的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 org.apache.commons.math3.exception.MaxCountExceededException
 * if an error occurs estimating probabilities
 */
public RealMatrix getCorrelationPValues() {
    TDistribution tDistribution = new TDistribution(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,代码行数:32,代码来源:PearsonsCorrelation.java

示例6: getConfidenceIntervalAt

import org.apache.commons.math3.distribution.TDistribution; //导入依赖的package包/类
/**
 * Returns the interval c1, c2 of which there's an 1-alpha
 * probability of the mean being within the interval.
 *
 * @param confidence level
 * @return the confidence interval
 */
@Override
public double[] getConfidenceIntervalAt(double confidence) {
    double[] interval = new double[2];

    if (getN() <= 2) {
        interval[0] = interval[1] = Double.NaN;
        return interval;
    }

    TDistribution tDist = new TDistribution(getN() - 1);
    double a = tDist.inverseCumulativeProbability(1 - (1 - confidence) / 2);
    interval[0] = getMean() - a * getStandardDeviation() / Math.sqrt(getN());
    interval[1] = getMean() + a * getStandardDeviation() / Math.sqrt(getN());

    return interval;
}
 
开发者ID:msteindorfer,项目名称:jmh,代码行数:24,代码来源:AbstractStatistics.java

示例7: computeParameterSignificance

import org.apache.commons.math3.distribution.TDistribution; //导入依赖的package包/类
/**
 * Computes the T-stats and the P-Value for all regression parameters
 */
private void computeParameterSignificance(RealVector betaVector) {
    try {
        final double residualDF = frame.rows().count() - (regressors.size() + 1);
        final TDistribution distribution = new TDistribution(residualDF);
        final double interceptParam = betaVector.getEntry(0);
        final double interceptStdError = intercept.data().getDouble(0, Field.STD_ERROR);
        final double interceptTStat = interceptParam / interceptStdError;
        final double interceptPValue = distribution.cumulativeProbability(-Math.abs(interceptTStat)) * 2d;
        final double interceptCI = interceptStdError * distribution.inverseCumulativeProbability(1d - alpha / 2d);
        this.intercept.data().setDouble(0, Field.PARAMETER, interceptParam);
        this.intercept.data().setDouble(0, Field.T_STAT, interceptTStat);
        this.intercept.data().setDouble(0, Field.P_VALUE, interceptPValue);
        this.intercept.data().setDouble(0, Field.CI_LOWER, interceptParam - interceptCI);
        this.intercept.data().setDouble(0, Field.CI_UPPER, interceptParam + interceptCI);
        final int offset = hasIntercept() ? 1 : 0;
        for (int i=0; i<regressors.size(); ++i) {
            final C regressor = regressors.get(i);
            final double betaParam = betaVector.getEntry(i + offset);
            final double betaStdError = betas.data().getDouble(regressor, Field.STD_ERROR);
            final double tStat = betaParam / betaStdError;
            final double pValue = distribution.cumulativeProbability(-Math.abs(tStat)) * 2d;
            final double betaCI = betaStdError * distribution.inverseCumulativeProbability(1d - alpha / 2d);
            this.betas.data().setDouble(regressor, Field.PARAMETER, betaParam);
            this.betas.data().setDouble(regressor, Field.T_STAT, tStat);
            this.betas.data().setDouble(regressor, Field.P_VALUE, pValue);
            this.betas.data().setDouble(regressor, Field.CI_LOWER, betaParam - betaCI);
            this.betas.data().setDouble(regressor, Field.CI_UPPER, betaParam + betaCI);
        }
    } catch (Exception ex) {
        throw new DataFrameException("Failed to compute regression coefficient t-stats and p-values", ex);
    }
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:36,代码来源:XDataFrameLeastSquares.java

示例8: testNextT

import org.apache.commons.math3.distribution.TDistribution; //导入依赖的package包/类
@Test
public void testNextT() {
    double[] quartiles = TestUtils.getDistributionQuartiles(new TDistribution(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:Quanticol,项目名称:CARMA,代码行数:12,代码来源:RandomDataGeneratorTest.java

示例9: calcMeanCI

import org.apache.commons.math3.distribution.TDistribution; //导入依赖的package包/类
private static double calcMeanCI(SummaryStatistics stats, double level) {
    try {
        TDistribution tDist = new TDistribution(stats.getN() - 1);
        double critVal = tDist.inverseCumulativeProbability(1.0 - (1 - level) / 2);
        return critVal * stats.getStandardDeviation() / Math.sqrt(stats.getN());
    } catch (MathIllegalArgumentException e) {
        return Double.NaN;
    }
}
 
开发者ID:dbunibas,项目名称:BART,代码行数:10,代码来源:EstimateRepairability.java

示例10: calcMeanCI

import org.apache.commons.math3.distribution.TDistribution; //导入依赖的package包/类
private static double calcMeanCI( SummaryStatistics stats, double level )
{
    // Create T Distribution with N-1 degrees of freedom
    TDistribution tDist = new TDistribution( stats.getN() - 1 );
    // Calculate critical value
    double critVal = tDist.inverseCumulativeProbability( 1.0 - ( 1 - level ) / 2 );
    // Calculate confidence interval
    return critVal * stats.getStandardDeviation() / Math.sqrt( stats.getN() );
}
 
开发者ID:RUB-NDS,项目名称:WS-Attacker,代码行数:10,代码来源:StatisticTest.java

示例11: compare

import org.apache.commons.math3.distribution.TDistribution; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public ComparisonResult compare(DataSnapshot left, DataSnapshot right) {
	BenchmarkRunSummary leftSummary = computeMergedStatistic(left);
	BenchmarkRunSummary rightSummary = computeMergedStatistic(right);
	
	statistic = getStatistic(leftSummary, rightSummary);
	
	double freedomDeg = getDegreesOfFreedom(leftSummary, rightSummary);
	distribution = new TDistribution(freedomDeg);
	
	return new DistributionBasedComparisonResult(statistic, distribution);
}
 
开发者ID:D-iii-S,项目名称:spl-evaluation-java,代码行数:14,代码来源:WelchTestInterpretation.java

示例12: pValues

import org.apache.commons.math3.distribution.TDistribution; //导入依赖的package包/类
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;
}
 
开发者ID:h2oai,项目名称:h2o-3,代码行数:8,代码来源:GLMModel.java

示例13: getMeanErrorAt

import org.apache.commons.math3.distribution.TDistribution; //导入依赖的package包/类
@Override
public double getMeanErrorAt(double confidence) {
    if (getN() <= 2) return Double.NaN;
    TDistribution tDist = new TDistribution(getN() - 1);
    double a = tDist.inverseCumulativeProbability(1 - (1 - confidence) / 2);
    return a * getStandardDeviation() / Math.sqrt(getN());
}
 
开发者ID:msteindorfer,项目名称:jmh,代码行数:8,代码来源:AbstractStatistics.java

示例14: OneSampleTTest

import org.apache.commons.math3.distribution.TDistribution; //导入依赖的package包/类
/**
 * Constructs OneSampleTTest with an ArrayList of values.
 * 
 * @param  hAlternative  the inequality for alternative hypothesis
 * @param  testValue     the value for the null hypothesis
 * @param  x             the data sample
 * @param  significance  the significance level
 */
public OneSampleTTest(Hypothesis hAlternative, double testValue,
        ArrayList<Double> x, double significance) {
    tDistribution = new TDistribution((double)(x.size()-1));
    getCriticalRegion(hAlternative, significance);
    double sampleStdDev = Math.sqrt(calcSampleVariance(x));
    calcTestStatistic(hAlternative, calcSampleMean(x),
            testValue, sampleStdDev, x);
    constructStrings(this.hypothesis = hAlternative, testValue,
            calculatedMean, sampleStdDev, x.size(), significance);
    rejectNull = testHypothesis();
}
 
开发者ID:JunkerStudio,项目名称:StatLogic,代码行数:20,代码来源:OneSampleTTest.java

示例15: getResultWithStatistics

import org.apache.commons.math3.distribution.TDistribution; //导入依赖的package包/类
private LeastSquaresRegressionResult getResultWithStatistics(
    double[][] x, double[][] w, double[] y, double[] betas, double[] yModel,
    DoubleMatrix transpose, DoubleMatrix matrix, boolean useIntercept) {
  double yMean = 0.;
  for (double y1 : y) {
    yMean += y1;
  }
  yMean /= y.length;
  double totalSumOfSquares = 0.;
  double errorSumOfSquares = 0.;
  int n = x.length;
  int k = betas.length;
  double[] residuals = new double[n];
  double[] standardErrorsOfBeta = new double[k];
  double[] tStats = new double[k];
  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];
  }
  double regressionSumOfSquares = totalSumOfSquares - errorSumOfSquares;
  double[][] covarianceBetas = convertArray(ALGEBRA.getInverse(ALGEBRA.multiply(transpose, matrix)).toArray());
  double rSquared = regressionSumOfSquares / totalSumOfSquares;
  double adjustedRSquared = 1. - (1 - rSquared) * (n - 1) / (n - k);
  double meanSquareError = errorSumOfSquares / (n - k);
  TDistribution studentT = new TDistribution(n - k);
  for (int i = 0; i < k; i++) {
    standardErrorsOfBeta[i] = Math.sqrt(meanSquareError * covarianceBetas[i][i]);
    tStats[i] = betas[i] / standardErrorsOfBeta[i];
    pValues[i] = 1 - studentT.cumulativeProbability(Math.abs(tStats[i]));
  }
  return new WeightedLeastSquaresRegressionResult(
      betas, residuals, meanSquareError, standardErrorsOfBeta, rSquared, adjustedRSquared, tStats, pValues, useIntercept);
}
 
开发者ID:OpenGamma,项目名称:Strata,代码行数:36,代码来源:WeightedLeastSquaresRegression.java


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