Hi everyone!
I understand the basics of calculating the linear regression slope and intercept but I'm trying to remove unnecessary steps because my x-axis is always a series of n whole numbers.
The only shortcut I found so far was that to get the mean of all numbers on the x-axis all I have to do is (N - 1)/2 instead of actually calculating their average by adding them up and dividing by N. So the mean of the first 5 whole numbers is 2 with (5 - 1) / 2 = 2 instead of (0 + 1 + 2 + 3 + 4) / 5 = 2. This saves me some time but I'm sure there is more that I can do to simplify the entire equation but I really don't know how.
What I do is:
1. get the average of all N whole numbers on X axis, now with (N-1)/2
2. calculate the difference between each whole number on X axis and the X axis mean of (N-1)/2
3. square those differences and add them up
4. get the average of all numbers on the Y axis
5. calculate the difference between each Y axis value and the Y axis mean
6. multiply each difference from step 2 with its corresponding difference from step 5 and add them up
Then I get the slope by dividing the result of step 6 by the result of step 3
Then I get the intercept by multiplying the slope by the average from step 1 and subtracting that result from the average from step 4
This all works, but it seems like I'm wasting time with step 2 and 3
1. I don't know how to simplify step 2 and 3 with a formula that accounts for the fact that my x-axis is only a series of N whole numbers (0, 1, 2, 3, ... N)
2. I suppose that if I simplify step 2 and 3 that I would have to change the way step 6 is calculated but again, I have no idea how to do that.
-----------------------------------------
So if anyone can help, it would really be appreciated! Sorry if this is a long question but I already spent days on this and I can't seem to make any progress.
Thanks in advance!
I understand the basics of calculating the linear regression slope and intercept but I'm trying to remove unnecessary steps because my x-axis is always a series of n whole numbers.
The only shortcut I found so far was that to get the mean of all numbers on the x-axis all I have to do is (N - 1)/2 instead of actually calculating their average by adding them up and dividing by N. So the mean of the first 5 whole numbers is 2 with (5 - 1) / 2 = 2 instead of (0 + 1 + 2 + 3 + 4) / 5 = 2. This saves me some time but I'm sure there is more that I can do to simplify the entire equation but I really don't know how.
What I do is:
1. get the average of all N whole numbers on X axis, now with (N-1)/2
2. calculate the difference between each whole number on X axis and the X axis mean of (N-1)/2
3. square those differences and add them up
4. get the average of all numbers on the Y axis
5. calculate the difference between each Y axis value and the Y axis mean
6. multiply each difference from step 2 with its corresponding difference from step 5 and add them up
Then I get the slope by dividing the result of step 6 by the result of step 3
Then I get the intercept by multiplying the slope by the average from step 1 and subtracting that result from the average from step 4
This all works, but it seems like I'm wasting time with step 2 and 3
1. I don't know how to simplify step 2 and 3 with a formula that accounts for the fact that my x-axis is only a series of N whole numbers (0, 1, 2, 3, ... N)
2. I suppose that if I simplify step 2 and 3 that I would have to change the way step 6 is calculated but again, I have no idea how to do that.
-----------------------------------------
So if anyone can help, it would really be appreciated! Sorry if this is a long question but I already spent days on this and I can't seem to make any progress.
Thanks in advance!