/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.math.stat.inference; import java.util.Collection; import org.apache.commons.math.MathException; import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.distribution.FDistribution; import org.apache.commons.math.distribution.FDistributionImpl; import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.stat.descriptive.summary.Sum; import org.apache.commons.math.stat.descriptive.summary.SumOfSquares; /** * Implements one-way ANOVA statistics defined in the {@link OneWayAnovaImpl} * interface. * *
Uses the * {@link org.apache.commons.math.distribution.FDistribution * commons-math F Distribution implementation} to estimate exact p-values.
* *This implementation is based on a description at * http://faculty.vassar.edu/lowry/ch13pt1.html
** Abbreviations: bg = between groups, * wg = within groups, * ss = sum squared deviations ** * @since 1.2 * @version $Revision: 983921 $ $Date: 2010-08-10 12:46:06 +0200 (mar. 10 août 2010) $ */ public class OneWayAnovaImpl implements OneWayAnova { /** * Default constructor. */ public OneWayAnovaImpl() { } /** * {@inheritDoc}
* This implementation computes the F statistic using the definitional * formula
* F = msbg/mswg* where
* msbg = between group mean square * mswg = within group mean square* are as defined * here */ public double anovaFValue(Collection
* This implementation uses the * {@link org.apache.commons.math.distribution.FDistribution * commons-math F Distribution implementation} to estimate the exact * p-value, using the formula
* p = 1 - cumulativeProbability(F)* where
F
is the F value and cumulativeProbability
* is the commons-math implementation of the F distribution.
*/
public double anovaPValue(Collection* This implementation uses the * {@link org.apache.commons.math.distribution.FDistribution * commons-math F Distribution implementation} to estimate the exact * p-value, using the formula
* p = 1 - cumulativeProbability(F)* where
F
is the F value and cumulativeProbability
* is the commons-math implementation of the F distribution.
* True is returned iff the estimated p-value is less than alpha.
*/ public boolean anovaTest(CollectionCollection
of double[]
* arrays each containing data for one category
* @return computed AnovaStats
* @throws IllegalArgumentException if categoryData does not meet
* preconditions specified in the interface definition
* @throws MathException if an error occurs computing the Anova stats
*/
private AnovaStats anovaStats(Collection