English

# Linear Regression Calculator

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

To Calculate Regression:
 X Value Y Value Add Remove

Code

<!-- Script by hscripts.com -->
<!-- More scripts @www.hscripts.com -->
<html>
<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";
}
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;
{
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.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;

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";

document.getElementById("r3").value = "Invalid";

document.getElementById("r4").value = "Invalid";}else{

var ff = f/g;var gg = (bb-(ff*aa))/x;

var ff1 = Math.round(ff*100000)/100000;

var gg1 = Math.round(gg*100000)/100000;

if(ff < 0)var hh = Math.round(gg1*1000)/1000 + "" + Math.round(ff1*1000)/1000 + "x";
else

var hh = Math.round(gg1*1000)/1000 + "+" + Math.round(ff1*1000)/1000 + "x";

}}}document.getElementById("r1").value = x;document.getElementById("r2").value = ff1;document.getElementById("r3").value = gg1;document.getElementById("r4").value = hh;}
}
function rst()
{
var text=x;for(var rr=1;rr<text;rr++){if(x>1){var len = x.length;var s = document.getElementById("a").getElementsByTagName("TBODY")[0];s.removeChild(s.lastChild);x=x-1;}}
}
</script>
<style>
h2 {border-bottom: 1px solid #ebebeb;color: #474747;font-size: 1.6em;font-weight: normal;line-height: 130%;
}
.frms
{
margin:0 auto;
font-family:Tahoma, Geneva, sans-serif;
color:#333;
font-size:.9em;
line-height:1.2em;
}
{
width:99%;
background:#fff;
border:#ddd 1px solid;
margin-top:5px;
margin-bottom:15px;
height:35px;
}
.frms input:hover,textarea:hover,select:hover
{
}
.frms input:focus,textarea:focus,select:focus
{
-webkit-box-shadow: inset 7px 4px 7px -7px rgba(0,0,0,0.42);
-moz-box-shadow: inset 7px 4px 7px -7px rgba(0,0,0,0.42);
box-shadow: inset 7px 4px 7px -7px rgba(0,0,0,0.42);
border:#9d9983 1px solid;
}
.frms input[type="submit"],input[type="reset"],input[type="button"]
{
font-weight:bold;
color:#fff;
cursor:pointer;
margin:10px 0;
border:none;
}
.frms input[type="submit"]
{
background:#75ab22;
border-bottom:#629826 3px solid;
}
.frms input[type="reset"]
{
background:#ee765d;
border-bottom:#d95e44 3px solid;
}
input[type="button"],button,.blue_button
{
background:#468cd2;
border-bottom:#3277bc 3px solid;
}
.frms label
{
font-size:1.2em;
}
.resp_code
{
margin:5px 10px 10px 300px;
font:normal 1em/1.3em Tahoma, Geneva, sans-serif;
color:#333;
background:#f8f8f8;
border:#ddd 1px solid;
overflow:auto;width:50%;
}
@media screen and (max-width: 480px)
{
.resp_code
{width:auto !important;margin:0px !important;
}
}
</style>
<div class='resp_code' id='maindiv'><div align='center'><h2>Calculate Simple / Linear Regression Line</h2></div>
<form name=first class='frms noborders'>
<table width=100%><caption><b>To Calculate Regression:</b></caption><tr><td></td></tr><tr><td><table id=a width=100%><tbody><tr><td>X Value</td> <td>Y Value </td> </tr><tr><td><input id=xvalu0 onkeyup=checnum(this) type=text size=10></td> <td> <input id=yvalu0 onkeyup=checnum(this) type=text size=10></td></tr>
<tr><td><input id=xvalu1 onkeyup=checnum(this) type=text size=10></td> <td> <input id=yvalu1 onkeyup=checnum(this) type=text size=10></td></tr>
<div align=center><input type=button value=Calculate onclick=calculate()>
<input type='reset' value=Reset><span
</div> </body>
</html>

• Release Date - 16-04-2015
• 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.