C # finding slope linear regression slope

Source: Internet
Author: User

public class Myslope
{
Public list<double> Values {get; set;}

Public double Sloperesult {get; set;}

}
//------------------------------------------------------------------------------------------------------------- ------------------
#region Calculation slope
<summary>
Calculates Slope ()
</summary>
<param name= "Input" >input y_signal</param>
<param name= "period" >number of periods</param>
<returns>object containing Operation Results</returns>
public static Myslope Slope (ienumerable<double> input_y, int period)
{//var returnvalues = new list<double> ();
list<double> input_x = new list<double> ();
for (int i = 1; I <= period; i++)
{
Input_x.add (i);

}

var copyinputvalues_x = Input_x.tolist ();
var copyinputvalues_y = Input_y.tolist ();
List<double> arr_xy=new list<double> ();
List<double> arr_xx=new list<double> ();
list<double> arr_x = new list<double> ();
list<double> arr_y = new list<double> ();
arr_x = copyinputvalues_x;
for (int j=copyinputvalues_y.count-period;j<copyinputvalues_y.count;j++)
{

Arr_x.add (Copyinputvalues_x[j]);
Arr_y.add (Copyinputvalues_y[j]);

}
Double X_arr_dataav = arr_x.take (period). Average ();
Double Y_arr_dataav = arr_y.take (period). Average ();
for (int i=0;i<arr_x.count;i++)
{
Arr_x[i] = arr_x[i]-X_arr_dataav;
Arr_y[i] = arr_y[i]-Y_arr_dataav;
Arr_xx. ADD (arr_x[i] * arr_x[i]);
Arr_xy. ADD (arr_y[i] * arr_x[i]);
}
Double sumxx = arr_xx. Sum ();
Double Sumxy = Arr_xy. Sum ();


var result = new Myslope ()
{
Sloperesult = Sumxy/sumxx,
Values = Returnvalues,
};
return result;
}
#endregion

}

C # finding slope linear regression slope

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.