using System;
using System.Collections;
using Microsoft.VisualBasic.CompilerServices;

public class Statistics
{
	public static Trendline CalculateLinearRegression2D(ArrayList values)
	{
		int num = 0;
		IEnumerator enumerator = values.GetEnumerator();
		double num4 = default(double);
		double num5 = default(double);
		double num6 = default(double);
		double num7 = default(double);
		double num8 = default(double);
		double num9 = default(double);
		while (enumerator.MoveNext())
		{
			if (!(enumerator.Current is Array))
			{
				continue;
			}
			double num2 = Conversions.ToDouble(NewLateBinding.LateIndexGet(enumerator.Current, new object[1] { 0 }, null));
			double num3 = Conversions.ToDouble(NewLateBinding.LateIndexGet(enumerator.Current, new object[1] { 1 }, null));
			num4 += num2;
			num5 += num3;
			num6 += num2 * num3;
			num7 += num2 * num2;
			num = checked(num + 1);
			if (num == 1)
			{
				num8 = num2;
				num9 = num2;
				continue;
			}
			if (num2 < num8)
			{
				num8 = num2;
			}
			if (num2 > num9)
			{
				num9 = num2;
			}
		}
		Trendline trendline = new Trendline();
		trendline.b = ((double)num * num6 - num4 * num5) / ((double)num * num7 - num4 * num4);
		trendline.a = (num5 - trendline.b * num4) / (double)num;
		trendline.x1 = num8;
		trendline.y1 = trendline.b * trendline.x1 + trendline.a;
		trendline.x2 = num9;
		trendline.y2 = trendline.b * trendline.x2 + trendline.a;
		return trendline;
	}
}
