//Calculates the Covariance public double Covarience(RandomVariable other) { double sum = 0; for (var i = 0; i < Values.Count; i++) { sum += Values[i] * other.Values[i]; } return(sum / Values.Count - Average * other.Average); }
//Finds the most corelative variable public RandomVariable FindMostCorelative(List <RandomVariable> variables) { RandomVariable mostCorelative = null; var biggestPCC = -1.0; foreach (var variable in variables) { if (variable == this) { continue; } var pcc = PCC(variable); if (pcc > biggestPCC) { mostCorelative = variable; biggestPCC = pcc; } } return(mostCorelative); }
//Calculates the linear regression public (double, double) LinearRegression(RandomVariable other) { return(Covarience(other) / Varience, other.Average - (Covarience(other) / Varience) * Average); }