Fun Share: Linear Regression anyone?

Linear regression is the most common tool used for prediction and forecasting. It is based on sets of data that seem to exhibit some kind of linear relationship - ie. if some independent variable goes up, the dependent variable goes up too, etc. when you plot these sets of data on a scatter plot, you can visually see the clustering that shows this relationship. Linear regression is the process that comes up with a straight line that goes through all these points with the best “fit”. Linear regression is used mainly in prediction and forecasting.

consider this data series of several subjects,of different ages, and the amount of glucose in their blood.
image

if you plot these points on a scatter plot, you can see the trend that suggests that there is a relationship between age and glucose count.

this thunkable app demonstrates how linear regression is used to compute the best fitting line through those points:
lr_chart

here are the blocks for the demo.

the app itself does not do the chart (i used an external tool to do the chart). The app returns the outcome of linear regression -the Slope and Intercept

when you plug these values into this formula

y = Slope * x + Iintercept

you get the equation of a straight line which cuts (ie. intercepts) the y axis at y=Intercept and with an inclination (ie. slope,vertical rise per unit horizontal distance) with the value of slope.

from the data above, the slope of the line varies such that for each unit change in x (age), y (glucose level) goes up by 0.3852 and when the age is zero, the glucose level is 65.1416 - the intercept (i guess it means a newborn baby already has a glucose level of 65.1416 at birth),

this line (represented by the slope and intercept) may be used to predict the estimated glucose level of someone who is 70 years old by solving this equation

y = 0,3852 * 70 + 65.1416
y = 92.1056, around 92

here is the link.
https://x.thunkable.com/copy/9acdc4b01c31d41b68ea855086addf69

3 Likes

Hello… Can i have a new link for your project? I really need a linear regression to my app… Please help

here’s the link
https://x.thunkable.com/copy/0f19cf61672a975ca102c5df3e0b0a15

i should warn you that this app does NOT do the graph. i had to use a separate tool for that.
if/when i find how i did this, i’ll post it.

edit: i found out how i made that chart. i will not make any explanation of it except to say that i used a deprecated graphing tool from google (that is no longer supported) and it was/is hard to learn.
cut-n-paste this in the browser.

https://chart.googleapis.com/chart?
&cht=s
&chs=500x300
&chd=t:43,21,25,42,57,59,0,80|99,65,79,75,87,81,65.14,95.96
&chm=o,0000FF,0,-1,0|o,FF0000,0,0:5:,5|D,000000,1,6:,1,-1
&chxt=x,y