public static RealType VariancePooled <RealType>( IAlgebraReal <RealType> algebra, IList <RealType> sample_0, IList <RealType> sample_1) { RealType mean_0 = Mean(algebra, sample_0); RealType mean_1 = Mean(algebra, sample_1); RealType variance = algebra.AddIdentity; for (int index = 0; index < sample_0.Count; index++) { variance = algebra.Add(variance, algebra.Sqr(algebra.Subtract(sample_0[index], mean_0))); } for (int index = 0; index < sample_1.Count; index++) { variance = algebra.Add(variance, algebra.Sqr(algebra.Subtract(sample_1[index], mean_1))); } return(algebra.Divide(variance, algebra.ToDomain((float)(sample_0.Count + sample_1.Count - 2)))); }
public static RealType VariancePooled <RealType>( IAlgebraReal <RealType> algebra, IList <IList <RealType> > samples) { RealType variance = algebra.AddIdentity; RealType degrees_of_freedom = algebra.AddIdentity; foreach (IList <RealType> sample in samples) { RealType mean_0 = Mean(algebra, sample); for (int index = 0; index < sample.Count; index++) { variance = algebra.Add(variance, algebra.Sqr(algebra.Subtract(sample[index], mean_0))); } degrees_of_freedom = algebra.Add(degrees_of_freedom, algebra.ToDomain((float)(sample.Count - 1))); } return(algebra.Divide(variance, degrees_of_freedom)); }