Sample Mean and Covariance Calculator

Sample Mean and Covariance Calculator, is used to calculate the values of two or more variables from the set of data. Its an online probability and statistics tool to calculate the values of X mean, Y mean and Covariance (X,Y).

Features

  • Online calculator allows to find the sample mean, covariance between the two random variables.
  • Calculation is based on the number of input values of the data sets.
  • Responsive and supports all modern browsers.
  • Note : Since it finds the covariance for X and Y, the number of values should be same for both X and Y.

Preview

Online Mean and Covariance Calculator

    ©h

Result:

Downloads

Code
<!-- Script by hscripts.com -->

<!-- More scripts @www.hscripts.com -->

<html>
<head>
<title>Sample Mean and Covariance Calculator Online Code</title>
<script type='text/javascript' >

function add()

{
var q=0;
var x=0;
var x1=0;
var n1=0;
var y=0;
var y1=0;
var n2=0;
var num=document.getElementById("t1").value;
var a=num.split(",");
var num1=document.getElementById("t2").value;
var b=num1.split(",");
a=a.filter(function(n){return n});
b=b.filter(function(n){return n});
var tot=a.length;
var tot1=b.length;
if(tot==0)
alert("Enter the X values");
else if(tot1==0)
alert("Enter the Y values");
else if(tot==tot1)
{
for (var i=0;i<a.length;i++)
{
var d1=a[i];
if(d1[d1.length-1]==",")a[i]=d1.substring(0,(d1.length-1));
n1=(+n1)+(+a[i]);
var m1=n1/tot;
var m2=m1.toFixed(3);
document.getElementById("m").value=m2;
}
for (var i=0;i<b.length;i++)
{
var d1=b[i];
if(d1[d1.length-1]==",")b[i]=d1.substring(0,(d1.length-1));
n2=(+n2)+(+b[i]);
var s=n2/tot;
var s1=s.toFixed(3);
document.getElementById("m1").value=s1;
}
for (var k=0;k<b.length;k++)
{
var x=(+a[k])-(+m1);
var y=(+b[k])-(+s1);
var y1=(+x)*(+y);
q=q+y1;
}
var r1=q/tot;
document.getElementById("n").value=tot;
document.getElementById("res").value=r1;
}
else
{
alert("Number of values should be same for X and Y");
}
}
function res1()
{
document.getElementById("t1").value="";
document.getElementById("t2").value="";document.getElementById("m").value="";
document.getElementById("m1").value="";
document.getElementById("n").value="";
document.getElementById("res").value="";
}
function checnum(as)
{
var dd = as.value;
if(dd[dd.length-1]=="," && dd.length==1)
{as.value= dd.substring(0,(dd.length-1));
}
else if(dd[dd.length-1]==" ")
{as.value= dd.substring(0,(dd.length-1));
}
else
{var rr=dd.split(",");
for(var i=0;i<rr.length;i++)
{ if(isNaN(rr[i]) || rr[i]==" "){
dd=as.value;
dd = dd.substring(0,(dd.length-1));
if(i==0)as.value = dd;
else
as.value = dd;}
}
}
}
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");}
}
window.onload=chk;
</script>
<style>label{float:left;padding:0 0 10px;}
h2 {border-bottom: 1px solid #ebebeb;color: #474747;font-size: 1.2em;font-weight: normal;line-height: 130%;
}.div1{float:left;width:60%;line-height:60px;}textarea
{
width:30%;
min-height:50px;
height:auto;
background:#fff;
border:#ddd 1px solid;
border-radius:.35em;
-moz-border-radius:.35em;
-webkit-border-radius:.35em;
-o-border-radius:.35em;
padding:1% .5%;
margin-top:5px;
margin-bottom:15px;
}
.frms
{
margin:0 auto;
padding:10px;
-moz-border-radius:.3em;
-webkit-border-radius:.3em;
-o-border-radius:.3em;
font-family:Tahoma, Geneva, sans-serif;
color:#333;
font-size:.9em;
line-height:1.2em;
}
.frms label {font-size: 1em;
}
.frms input[type="text"]
{
width:99%;
background:#fff;
border:#ddd 1px solid;
border-radius:.35em;
-moz-border-radius:.35em;
-webkit-border-radius:.35em;
-o-border-radius:.35em;
padding:0 .5%;
margin-top:5px;
margin-bottom:15px;
height:35px;
}
.frms input:hover,textarea:hover,select:hover
{
box-shadow:#dae1e5 0px 0px 5px;
-moz-box-shadow:#dae1e5 0px 0px 5px;
-webkit-box-shadow:#dae1e5 0px 0px 5px;
-o-box-shadow:#dae1e5 0px 0px 5px;
}
.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="button"],input[type="reset"]
{
padding:7px 14px;
font-weight:bold;
color:#fff;
cursor:pointer;
border-radius:.3em;
-moz-border-radius:.2em;
-webkit-border-radius:.2em;
-o-border-radius:.2em;
margin:10px 0;
border:none;
}
input[type="button"]
{
background:#468cd2;
border-bottom:#3277bc 3px solid;
text-shadow:#214d73 1px 1px 0px;
}
.frms input[type="reset"]
{
background:#ee765d;
border-bottom:#d95e44 3px solid;
text-shadow:#8c3736 1px 1px 0px;
}
.resp_code
{
margin:5px 10px 10px 300px;
padding:10px 20px 10px 20px;
font:normal 1em/1.3em Tahoma, Geneva, sans-serif;
color:#333;
background:#f8f8f8;
border:#ddd 1px solid;
border-radius:.25em;
overflow:auto;width:50%;
}
@media screen and (max-width: 480px)
{
.resp_code
{width:auto !important;margin:0px !important;
}
.frms textarea{width:40%;min-height:50px;}.div1{float:left;line-height:20px;font-size:0.9em;}
}
</style></head><body><div class='resp_code'><div align='center'><h2>Online Mean and Covariance Calculator</h2></div><div class="frms" id='maindiv'>
<form name=first><div style='width:100%;padding-top:10px;'><div class='div1' align='left'><label>Enter the X Values (Separated by comma(,))</label></div><div style='width:100%;'><textarea rows=2 id=t1 cols=33 onkeyup=checnum(this) ></textarea></div></div><div style='width:100%;'><div class='div1' align='left'><label>Enter the Y Values (Separated by comma(,))</label></div><div style='width:100%;'><textarea rows=2 id=t2 cols=33 onkeyup=checnum(this) ></textarea></div></div><div align='center'><input type=button value=Calculate onclick=add()>
<input type=reset value=Reset onclick=res1()><span
align='center' style="font-size: 10px;color: #dadada;" id="dumdiv"><a href="https://www.hscripts.com" id="dum" style="font-size: 10px;color: #dadada;text-decoration:none;color: #dadada;">&copy;h</a></span></div>
<div class='result'><p align='center' style="font-size:1.1em;">Result:</p><div>
<div align='left'><label>Mean x:</label></div><input type=text id=m readonly><div align='left'><label>Mean y:</label></div><input type=text id=m1 readonly><div align='left'><label>N:</label></div><input type=text id=n readonly><div align='left'><label>Cov(X,Y):</label></div><input type=text id=res readonly></div></div></form></div></div></body>
</html>
  • Release Date - 09-03-2015
  • Get free version without ©copyright link for just $10/-
  • For customization of this script or any script development, mail to support@hscripts.com

Usage

  • Copy and paste the code into your HTML page to use this sample mean and covariance calculator.
  • Enter the X and Y values separated by comma and click calculate to find the mean and covariance.

License

Related Scripts

Free Javascript Scripts


Ask Questions

Ask Question