-
September 19th, 2000, 04:56 PM
#1
Regression Line Calculation (SLOPE)
In Microsoft Excel there is a SLOPE function. What I need to do is translate the formula of this SLOPE function to work in a Visual C++ Application. Can anyone out there show me how I would write the function or functions that will produce the same output as the Excel SLOPE function! I can provide more information as needed, but would appreciate as detailed information as possible! PLEASE HELP!
Many thanks!
Charlie
Everything is Free Until You Have to Pay for it....
Platform is Windows 2000/XP Professional, Visual C++ 6.0
-
September 19th, 2000, 10:01 PM
#2
Re: Regression Line Calculation (SLOPE)
Linear line regression algorithm is very easy to implement. I never use Excel SLOPE function. I suppose, that parameters are array of x,y points, the slope of a line( steepness of the line) and intercept.
But I'm not sure, how is this algorithm implemented in Excel. Let me detailed information, if you want.
-
September 20th, 2000, 08:25 AM
#3
Re: Regression Line Calculation (SLOPE)
I need the details if you can provide please do so!
Thanks
Everything is Free Until You Have to Pay for it....
Platform is Windows 2000/XP Professional, Visual C++ 6.0
-
September 20th, 2000, 08:42 AM
#4
Re: Regression Line Calculation (SLOPE)
In this WEB site you can find explanation.
http://www.ruf.rice.edu/~lane/hyperstat/A115370.html
I never used Excel, so I need to know, what kind of input data you use.
-
September 20th, 2000, 11:54 AM
#5
Re: Regression Line Calculation (SLOPE)
I don't know what SLOPE does, but to find the
"least squares regression line" , y = Mx + B
for the points (x(i),y(i)) for i = 1,N
you would do the following :
s0 = N+1
s1 = sum_of(x(i)) for i = 1,N
s2 = sum_of(x(i)*x(i)) for i = 1,N
t0 = sum_of(y(i)) for i = 1,N
t1 = sum_of(x(i)*y(i)) for i = 1,N
then
M = ( s0*t1 - s1*t0 ) / (s0*s2 - s1*s1)
B = ( s2*t0 - s1*t1 ) / (s0*s2 - s1*s1)
and the regression line is given by
y = Mx + B
-
September 20th, 2000, 01:49 PM
#6
Re: Regression Line Calculation (SLOPE)
A B Slope
1.05 0.016632 0.015338
1.05 0.016817
1.05 0.016662
3.05 0.047281
3.05 0.047469
3.05 0.047494
5.05 0.079046
5.05 0.078907
5.05 0.078804
10.05 0.155113
10.05 0.154559
10.05 0.154475
If you open Excel and add the data (not the slope value) The in a column off to the right add the slope function and it should look like this
SLOPE(B2:B13,A2:A13)
If you need more info please let me know.
Thanks!
Charlie
Everything is Free Until You Have to Pay for it....
Platform is Windows 2000/XP Professional, Visual C++ 6.0
-
September 21st, 2000, 09:23 AM
#7
Re: Regression Line Calculation (SLOPE)
Thank you, I take a look on this through the weekend. I'm very busy during working week....
Can you send me your email adress? My is in my profile on codeguru.
-
September 21st, 2000, 09:51 AM
#8
Re: Regression Line Calculation (SLOPE)
Everything is Free Until You Have to Pay for it....
Platform is Windows 2000/XP Professional, Visual C++ 6.0
-
September 21st, 2000, 01:58 PM
#9
Re: Regression Line Calculation (SLOPE)
f.y.i. the algorithm that I gave you calculated the same slope that
you provided in your sample data set.
Here is a code snippet to do the calculation :
// values needed prior to code snippet
//
// int n = number of (x,y) points
// double x[ i ] for i = 0 to n-1 ... the x points
// double y[ i ] for i = 0 to n-1 ... the y points
//
double s0 = 0;
double s1 = 0;
double s2 = 0;
double t0 = 0;
double t1 = 0;
for (int i=0; i<n; i++)
{
s0++;
s1 = s1 + x[ i ];
s2 = s2 + x[ i ]*x[ i ];
t0 = t0 + y[ i ];
t1 = t1 + x[ i ]*y[ i ];
}
double M = ( s0*t1 - s1*t0 ) / (s0*s2 - s1*s1) ; // slope
double B = ( s2*t0 - s1*t1 ) / (s0*s2 - s1*s1) ; // y-intercept
-
September 21st, 2000, 02:40 PM
#10
Re: Regression Line Calculation (SLOPE)
SORRY! I didn't understand your original message, but this is exactly what I was looking for! So I will give it a try and I appreciate your extra effort in providing the information in a more understandable format!
Thanks!
Charlie
Everything is Free Until You Have to Pay for it....
Platform is Windows 2000/XP Professional, Visual C++ 6.0
-
April 25th, 2013, 04:00 AM
#11
Re: Regression Line Calculation (SLOPE)
Originally Posted by Philip Nicoletti
f.y.i. the algorithm that I gave you calculated the same slope that
you provided in your sample data set.
Here is a code snippet to do the calculation :
// values needed prior to code snippet
//
// int n = number of (x,y) points
// double x[ i ] for i = 0 to n-1 ... the x points
// double y[ i ] for i = 0 to n-1 ... the y points
//
double s0 = 0;
double s1 = 0;
double s2 = 0;
double t0 = 0;
double t1 = 0;
for (int i=0; i<n; i++)
{
s0++;
s1 = s1 + x[ i ];
s2 = s2 + x[ i ]*x[ i ];
t0 = t0 + y[ i ];
t1 = t1 + x[ i ]*y[ i ];
}
double M = ( s0*t1 - s1*t0 ) / (s0*s2 - s1*s1) ; // slope
double B = ( s2*t0 - s1*t1 ) / (s0*s2 - s1*s1) ; // y-intercept
Hi thanks for this code,but can you help me to get the regression..y=mx+b? what is the value of x? is it the iteration of data or the total absorbance? or conc? Please email me at jotyme@rocketmail.com. Thanks bro.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|