Pearson Correlation Calculator
About this app
Calculate the Pearson correlation coefficient between two sets of data.
Pearson Correlation Calculator Pearson Correlation Calculator X Values Y Values Calculate
Related apps
Put this on your site
Source
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Pearson Correlation Calculator</title>
<meta name="description" content="Calculate the Pearson correlation coefficient between two sets of data.">
<meta name="keywords" content="pearson correlation, correlation coefficient, statistics">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<script type="text/javascript">
try {
// App Javascript Goes Here. Place your entire script content inside the try block for error handling.
// This will run when the DOM is ready.
document.addEventListener("DOMContentLoaded", function() {
// Function to calculate Pearson correlation coefficient
function calculateCorrelation() {
// Get the input values
var xValues = $('#xValues').val().split(',').map(Number);
var yValues = $('#yValues').val().split(',').map(Number);
// Check if the input values are valid
if (!xValues || !yValues || xValues.length !== yValues.length) {
$('#result').text('Invalid input values');
return;
}
// Calculate the sum of x values, y values, and product of x and y values
var sumX = 0;
var sumY = 0;
var sumXY = 0;
var sumXSquare = 0;
var sumYSquare = 0;
for (var i = 0; i < xValues.length; i++) {
sumX += xValues[i];
sumY += yValues[i];
sumXY += xValues[i] * yValues[i];
sumXSquare += xValues[i] * xValues[i];
sumYSquare += yValues[i] * yValues[i];
}
// Calculate the Pearson correlation coefficient
var n = xValues.length;
var numerator = (n * sumXY) - (sumX * sumY);
var denominator = Math.sqrt((n * sumXSquare - sumX * sumX) * (n * sumYSquare - sumY * sumY));
var correlationCoefficient = numerator / denominator;
// Display the result
$('#result').text('Correlation Coefficient: ' + correlationCoefficient.toFixed(4));
}
// Attach click event to calculate button
$('#calculateBtn').click(function() {
calculateCorrelation();
});
});
} catch (error) {
// This will throw the error to the parent window.
throw error;
}
</script>
<style>
/* App CSS Goes Here */
body {
background-color: #f8f9fa;
font-family: 'Roboto', sans-serif;
}
h1 {
text-align: center;
margin-top: 20px;
margin-bottom: 30px;
}
.form-group {
margin-bottom: 20px;
}
.btn-primary {
background-color: #007bff;
border-color: #007bff;
}
.btn-primary:hover {
background-color: #0069d9;
border-color: #0062cc;
}
.result {
margin-top: 20px;
text-align: center;
font-weight: bold;
}
</style>
</head>
<body>
<div id="main-container" class="container">
<h1>Pearson Correlation Calculator</h1>
<div class="form-group">
<label for="xValues">X Values</label>
<input type="text" class="form-control" id="xValues" placeholder="Enter comma separated x values">
</div>
<div class="form-group">
<label for="yValues">Y Values</label>
<input type="text" class="form-control" id="yValues" placeholder="Enter comma separated y values">
</div>
<button id="calculateBtn" class="btn btn-primary">Calculate</button>
<div id="result" class="result"></div>
</div>
</body>
</html>
NEW APPS
These are apps made by the community!