This program finds the best fit line given some datapoints. Click to make a datapoint, it needs at least 2 datapoints to work.
This project was made using
: creative, graphical, and browser-based programming.
var x =  var y =  var len = x.length var slope = 0 var yInter = 0 when click: x.push(mouse.x) y.push(mouse.y) len += 1 new Circle(mouse.x,mouse.y,5,"black") var sumXY = 0 var sumX = 0 var sumY = 0 var sumX2 = 0 forEach i in range(len): sumXY += x[i] * y[i] sumX += x[i] sumY += y[i] sumX2 += x[i] * x[i] # this equation is the line for linear regression slope = (len*sumXY - sumX*sumY)/(len*sumX2 - sumX*sumX) yInter = (sumY - slope*sumX)/len var myLine = new Custom() myLine.instructions = line(-240, -240*slope+yInter, 240, 240*slope+yInter)