Need help simplifying my linear regression formula

jeepack

New member
Joined
May 4, 2022
Messages
4
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.
I don't understand what this means. Can you show an example?
Are you doing multiple or single linear regression?
Are you using these formulas? Where [imath]b_1[/imath] is your slope and [imath]b_0[/imath] is your intercept.
Screen Shot 2022-05-05 at 12.05.58 PM.png
 
Single. I'm not familiar with how to read these equations so I'm having a hard time being more clear. But I can say that the X axis is basically 0, 1, 2, 3, 4, 5, 6, etc ... for N whole numbers. So:

if N = 3, then X axis is 0, 1, 2.
if N = 5, then X axis is 0, 1, 2, 3, 4
etc

Maybe I found something that might help, https://otexts.com/fpp2/regression-intro.html talks about Time Series Regression Models... I think that's what I need. I'm not sure I'll be able to figure it out but I'll keep trying :)

Let me know if you have any suggestions that I could read understand this a little bit better. Thanks
 
Screen Shot 2022-05-05 at 6.17.15 PM.png
It's the exact same. Provide a small sample data, maybe with 3-5 data points (x,y). Show me how you calculate the slope and intercept with the small dataset. I can point out where your mistake is.
 
Tomorow I should be working on this again. Someone gave me a simplified equation that I can test in my code. If I can't get it to work, I'll post an example. Thanks
 
View attachment 32603
It's the exact same. Provide a small sample data, maybe with 3-5 data points (x,y). Show me how you calculate the slope and intercept with the small dataset. I can point out where your mistake is.
I finally did it, I got a formula from someone and then I adapted it and simplified it further. Your advice made it much easier. I started writing down examples with 3 data points so I was able to run through the equations by hand many times quickly and that helped me see where my errors were. I hadn't thought of that before so thanks!
 
Top