Simple Linear Regression Calculator, helps to calculate the relationship between two variables by the given equation.
Features
Access the association between two variables in a straight line known as Line of Best fit.
Computes the value of slope, y-intercept and regression equation.
The calculation is based on x and y variables where one variable is dependent and another is independent.
Simple, responsive and easy to integrate.
Preview
Calculate Simple / Linear Regression Line
Downloads
Code
<!-- Script by hscripts.com --> <!-- More scripts @www.hscripts.com --> <html> <head> <title>Linear Regression Calculator | Simple Linear Regression in Javascript </title> <script LANGUAGE="JavaScript"> function chk(){ var sds = document.getElementById('dum'); if(sds == null){alert("You are using a free package.\n You are not allowed to remove the tag.\n"); document.getElementById("maindiv").style.visibility="hidden"; } var sdss = document.getElementById("dumdiv"); if(sdss == null){alert("You are using a free package.\n You are not allowed to remove the tag.\n");} element = document.getElementById('dell'); element.style.display = "none"; } window.onload=chk; function checnum(as) { var dd = as.value; if(dd.lastIndexOf(" ")>=0){dd = dd.replace(" ","");as.value = dd; } if(isNaN(dd)) { dd = dd.substring(0,(dd.length-1)); as.value = dd; } } var x=2; function add() { element = document.getElementById('dell'); element.style.display = "block"; var s = document.getElementById("a").getElementsByTagName("TBODY")[0]; var trow = document.createElement("tr"); var tcol1 = document.createElement("td"); var tcol2 = document.createElement("td"); var d = document.createElement("input"); d.setAttribute("type","text"); d.setAttribute("size","10"); d.setAttribute("id","xvalu"+x); d.setAttribute("onkeyup","checnum(this)"); d.style.backgroundColor= "#ffffff"; d.style.color = "#000000"; var e = document.createElement("input"); e.setAttribute("type","text"); e.setAttribute("size","10"); e.setAttribute("id","yvalu"+x); e.setAttribute("onkeyup","checnum(this)"); e.style.backgroundColor= "#ffffff"; e.style.color = "#000000"; tcol1.appendChild(d); tcol2.appendChild(e); trow.appendChild(tcol1); trow.appendChild(tcol2); s.appendChild(trow); if(x>20){ element = document.getElementById('addd'); element.style.display = "none"; } x++; } function del() { element = document.getElementById('dell'); element.style.display = "block"; if (x<=3) { element = document.getElementById('dell'); element.style.display = "none"; } if(x>2){ var len = x.length; var s = document.getElementById("a").getElementsByTagName("TBODY")[0]; s.removeChild(s.lastChild); x=x-1; } }
function calculate()
{aTemp = document.getElementById("xvalu0").value;
bTemp = document.getElementById("yvalu0").value;
if((aTemp=="")||(bTemp=="")){alert("Enter All Fields");return false;}
else{ var aa = 0;var bb = 0;var cc = 0;var dd = 0;var ee = 0;for(var y=0;y<x; y++){var xxx = document.getElementById("a").getElementsByTagName("TBODY")[0];var a = xxx.getElementsByTagName("input").item(y*2).value;var b = xxx.getElementsByTagName("input").item(1+y*2).value;if((a=="")||(b=="")){alert("Enter All Fields");return false;}else{aa = aa + parseFloat(a);bb = bb + parseFloat(b);cc = cc + (a*b);dd = dd + (a*a); var f = ((x*cc)-(aa*bb));var g = ((x*dd)-(aa*aa));if(g==0){document.getElementById("r1").value = x; document.getElementById("r2").value = "Invalid";
For customization of this script or any script development, mail to support@hscripts.com
Usage
Copy and paste the above code into your HTML page.
Run the file in your browser.
Enter minimum of two values for both the variables to calculate the
linear regression.
Regression equation is calculated by using the function 'calculate()',it will get the values you have entered in the x and y textboxes and gives the output.
If you wish to use the functionality of the script in your web page, copy and paste the code from the <script> tag into head part of HTML page.