本文主要是介绍计算数组的斜率,偏移,R2,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
模拟Excel中的R2的计算。
public bool fnCheckRear_R2(List<double[]> lRear, int iMinRear, int iMaxRear, ref double dR2)
{
bool bResult = true;
int n = 0;
double r = 0.0;
double meanA = 0;
double meanB = 0;
double varA = 0;
double varB = 0;
List<double> Xdatas = new List<double>();
List<double> Ydatas = new List<double>();
int iCount = 0;
if (lRear.Count > 0)
{
for (int i = 0; i < lRear.Count; i++)
{
double X = lRear[i][0];
if (X >= iMinRear && X < iMaxRear)
{
iCount++;
double currentA = lRear[i][0];
double currentB = lRear[i][1];
double deltaA = currentA - meanA;
double scaleDeltaA = deltaA / ++n;
double deltaB = currentB - meanB;
double scaleDeltaB = deltaB / n;
meanA += scaleDeltaA;
meanB += scaleDeltaB;
varA += scaleDeltaA * deltaA * (n - 1);
varB += scaleDeltaB * deltaB * (n - 1);
r += (deltaA * deltaB * (n - 1)) / n;
}
}
dR2 = (r / Math.Sqrt(varA * varB)) * (r / Math.Sqrt(varA * varB));
}
else
{
bResult = false;
}
return bResult;
}
这篇关于计算数组的斜率,偏移,R2的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!