PEARSON function
PRO
The PEARSON
function in Jspreadsheet Formulas Pro is a tool that calculates the relationship between two groups of data. It gives you the Pearson product-moment correlation coefficient, a value that can range between -1 and 1. This number will tell you how closely the two sets of data are related. If the value is close to 1, the data sets have a strong positive correlation; if it's close to -1, they have a strong negative correlation; if it's close to 0, there's no correlation.
Documentation
Returns the Pearson product moment correlation coefficient between two data sets.
Category
Statistical
Syntax
PEARSON(array1, array2)
Parameter | Description |
---|---|
array1 |
The first array or range of values. |
array2 |
The second array or range of values. |
Behavior
The PEARSON
function calculates the Pearson product-moment correlation coefficient for two sets of values. This coefficient indicates the degree of linear relationship between the two sets of data.
- Empty Cells: The
PEARSON
function ignores empty cells. - Text: The
PEARSON
function cannot handle text. If any cell in the range contains text, the function will return an error. - Booleans: Boolean values are treated as integers.
TRUE
is treated as 1 andFALSE
is treated as 0. - Errors: If any cell in the range contains an error, the
PEARSON
function will return an error. - Non-Numeric Values: If the arrays contain non-numeric values, the function will return an error.
- Array sizes: The two arrays must be of the same size, else the function will return an error.
Common Errors
Error | Description |
---|---|
#N/A | Occurs if the two arrays provided are of different lengths. |
#DIV/0! | Occurs if there is only one pair of data point, as the standard deviation of the data points cannot be calculated. |
#VALUE! | Occurs if the provided arguments are non-numeric or if any of the cells in the range contain text. |
#REF! | Occurs if the cell reference is not valid. |
Best practices
- Always ensure that the two arrays provided to the
PEARSON
function are of the same size.- Be sure to handle non-numeric values before using the
PEARSON
function to avoid errors.- Use the
PEARSON
function to compare the linear relationship between two sets of data, not to establish a cause-effect relationship.- Verify that your data does not contain any error values to prevent the
PEARSON
function from returning an error.
Usage
A few examples using the PEARSON function.
PEARSON({1,2,3,4,5}, {2,4,6,8,10})
→ Returns 1
Meaning: Perfect positive linear relationship (as Y doubles X).
PEARSON({1,2,3,4,5}, {10,8,6,4,2})
→ Returns -1
Meaning: Perfect negative linear relationship.
PEARSON({1,2,3,4,5}, {7,7,7,7,7})
→ Returns #DIV/0!
Meaning: Error occurs because the second array has zero variance.
Interactive Spreadsheet Demo
<html>
<script src="https://jspreadsheet.com/v11/jspreadsheet.js"></script>
<script src="https://jsuites.net/v5/jsuites.js"></script>
<link rel="stylesheet" href="https://jsuites.net/v5/jsuites.css" type="text/css" />
<link rel="stylesheet" href="https://jspreadsheet.com/v11/jspreadsheet.css" type="text/css" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Material+Icons" />
<script src="https://cdn.jsdelivr.net/npm/@jspreadsheet/formula-pro/dist/index.min.js"></script>
<div id="spreadsheet"></div>
<script>
// Set your JSS license key (The following key only works for one day)
jspreadsheet.setLicense('YTc3MjJkNTYzYmRhODU5YTdlY2Q2NDk1Yjg5MTBhNTIzNTY2YzQyYTdlZDBkM2U1MmZmYjRmMzdiZDcwNWI0YjgyZmE4ZGVkMDg2MzRiOGIyZTdlNTAwOWZjMGFlNzBmNWJlMjAzMzY2ZTQ2ZGY0MTI3MzA3MzBlYjdmNjJhMGUsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpVM01EY3pORFF4TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2lkMlZpSWl3aWJHOWpZV3hvYjNOMElsMHNJbkJzWVc0aU9pSXpOQ0lzSW5OamIzQmxJanBiSW5ZM0lpd2lkamdpTENKMk9TSXNJbll4TUNJc0luWXhNU0lzSW1Ob1lYSjBjeUlzSW1admNtMXpJaXdpWm05eWJYVnNZU0lzSW5CaGNuTmxjaUlzSW5KbGJtUmxjaUlzSW1OdmJXMWxiblJ6SWl3aWFXMXdiM0owWlhJaUxDSmlZWElpTENKMllXeHBaR0YwYVc5dWN5SXNJbk5sWVhKamFDSXNJbkJ5YVc1MElpd2ljMmhsWlhSeklpd2lZMnhwWlc1MElpd2ljMlZ5ZG1WeUlpd2ljMmhoY0dWeklpd2labTl5YldGMElsMHNJbVJsYlc4aU9uUnlkV1Y5');
// Set the extensions
jspreadsheet.setExtensions({ formula });
// Create a new spreadsheet
jspreadsheet(document.getElementById('spreadsheet'), {
worksheets: [{
data: [
[
"Hours Studied",
"Test Score"
],
[
2,
65
],
[
4,
75
],
[
6,
85
],
[
8,
90
],
[
10,
95
],
[
"Correlation:",
"=PEARSON(A2:A6,B2:B6)"
]
]
}]
});
</script>
</html>
import React, { useRef } from "react";
import { Spreadsheet, Worksheet, jspreadsheet } from "@jspreadsheet/react";
import formula from "@jspreadsheet/formula-pro";
import "jsuites/dist/jsuites.css";
import "jspreadsheet/dist/jspreadsheet.css";
// Set license
jspreadsheet.setLicense('YTc3MjJkNTYzYmRhODU5YTdlY2Q2NDk1Yjg5MTBhNTIzNTY2YzQyYTdlZDBkM2U1MmZmYjRmMzdiZDcwNWI0YjgyZmE4ZGVkMDg2MzRiOGIyZTdlNTAwOWZjMGFlNzBmNWJlMjAzMzY2ZTQ2ZGY0MTI3MzA3MzBlYjdmNjJhMGUsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpVM01EY3pORFF4TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2lkMlZpSWl3aWJHOWpZV3hvYjNOMElsMHNJbkJzWVc0aU9pSXpOQ0lzSW5OamIzQmxJanBiSW5ZM0lpd2lkamdpTENKMk9TSXNJbll4TUNJc0luWXhNU0lzSW1Ob1lYSjBjeUlzSW1admNtMXpJaXdpWm05eWJYVnNZU0lzSW5CaGNuTmxjaUlzSW5KbGJtUmxjaUlzSW1OdmJXMWxiblJ6SWl3aWFXMXdiM0owWlhJaUxDSmlZWElpTENKMllXeHBaR0YwYVc5dWN5SXNJbk5sWVhKamFDSXNJbkJ5YVc1MElpd2ljMmhsWlhSeklpd2lZMnhwWlc1MElpd2ljMlZ5ZG1WeUlpd2ljMmhoY0dWeklpd2labTl5YldGMElsMHNJbVJsYlc4aU9uUnlkV1Y5');
// Set the extensions
jspreadsheet.setExtensions({ formula });
export default function App() {
// Spreadsheet array of worksheets
const spreadsheet = useRef();
// Worksheet data
const data = [
[
"Hours Studied",
"Test Score"
],
[
2,
65
],
[
4,
75
],
[
6,
85
],
[
8,
90
],
[
10,
95
],
[
"Correlation:",
"=PEARSON(A2:A6,B2:B6)"
]
];
// Render component
return (
<Spreadsheet ref={spreadsheet}>
<Worksheet data={data} />
</Spreadsheet>
);
}
<template>
<Spreadsheet ref="spreadsheet">
<Worksheet :data="data" />
</Spreadsheet>
</template>
<script>
import { Spreadsheet, Worksheet, jspreadsheet } from "@jspreadsheet/vue";
import "jsuites/dist/jsuites.css";
import "jspreadsheet/dist/jspreadsheet.css";
import formula from "@jspreadsheet/formula-pro";
// Set license
jspreadsheet.setLicense('YTc3MjJkNTYzYmRhODU5YTdlY2Q2NDk1Yjg5MTBhNTIzNTY2YzQyYTdlZDBkM2U1MmZmYjRmMzdiZDcwNWI0YjgyZmE4ZGVkMDg2MzRiOGIyZTdlNTAwOWZjMGFlNzBmNWJlMjAzMzY2ZTQ2ZGY0MTI3MzA3MzBlYjdmNjJhMGUsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpVM01EY3pORFF4TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2lkMlZpSWl3aWJHOWpZV3hvYjNOMElsMHNJbkJzWVc0aU9pSXpOQ0lzSW5OamIzQmxJanBiSW5ZM0lpd2lkamdpTENKMk9TSXNJbll4TUNJc0luWXhNU0lzSW1Ob1lYSjBjeUlzSW1admNtMXpJaXdpWm05eWJYVnNZU0lzSW5CaGNuTmxjaUlzSW5KbGJtUmxjaUlzSW1OdmJXMWxiblJ6SWl3aWFXMXdiM0owWlhJaUxDSmlZWElpTENKMllXeHBaR0YwYVc5dWN5SXNJbk5sWVhKamFDSXNJbkJ5YVc1MElpd2ljMmhsWlhSeklpd2lZMnhwWlc1MElpd2ljMlZ5ZG1WeUlpd2ljMmhoY0dWeklpd2labTl5YldGMElsMHNJbVJsYlc4aU9uUnlkV1Y5');
// Set the extensions
jspreadsheet.setExtensions({ formula });
export default {
components: {
Spreadsheet,
Worksheet,
},
data() {
// Worksheet data
const data = [
[
"Hours Studied",
"Test Score"
],
[
2,
65
],
[
4,
75
],
[
6,
85
],
[
8,
90
],
[
10,
95
],
[
"Correlation:",
"=PEARSON(A2:A6,B2:B6)"
]
]
return {
data
};
}
}
</script>
import { Component, ViewChild, ElementRef } from "@angular/core";
import jspreadsheet from "jspreadsheet";
import * as formula from "@jspreadsheet/formula-pro";
// Set your JSS license key (The following key only works for one day)
jspreadsheet.setLicense('YTc3MjJkNTYzYmRhODU5YTdlY2Q2NDk1Yjg5MTBhNTIzNTY2YzQyYTdlZDBkM2U1MmZmYjRmMzdiZDcwNWI0YjgyZmE4ZGVkMDg2MzRiOGIyZTdlNTAwOWZjMGFlNzBmNWJlMjAzMzY2ZTQ2ZGY0MTI3MzA3MzBlYjdmNjJhMGUsZXlKamJHbGxiblJKWkNJNklpSXNJbTVoYldVaU9pSktjM0J5WldGa2MyaGxaWFFpTENKa1lYUmxJam94TnpVM01EY3pORFF4TENKa2IyMWhhVzRpT2xzaWFuTndjbVZoWkhOb1pXVjBMbU52YlNJc0ltTnZaR1Z6WVc1a1ltOTRMbWx2SWl3aWFuTm9aV3hzTG01bGRDSXNJbU56WWk1aGNIQWlMQ0p6ZEdGamEySnNhWFI2TG1sdklpd2lkMlZpWTI5dWRHRnBibVZ5TG1sdklpd2lkMlZpSWl3aWJHOWpZV3hvYjNOMElsMHNJbkJzWVc0aU9pSXpOQ0lzSW5OamIzQmxJanBiSW5ZM0lpd2lkamdpTENKMk9TSXNJbll4TUNJc0luWXhNU0lzSW1Ob1lYSjBjeUlzSW1admNtMXpJaXdpWm05eWJYVnNZU0lzSW5CaGNuTmxjaUlzSW5KbGJtUmxjaUlzSW1OdmJXMWxiblJ6SWl3aWFXMXdiM0owWlhJaUxDSmlZWElpTENKMllXeHBaR0YwYVc5dWN5SXNJbk5sWVhKamFDSXNJbkJ5YVc1MElpd2ljMmhsWlhSeklpd2lZMnhwWlc1MElpd2ljMlZ5ZG1WeUlpd2ljMmhoY0dWeklpd2labTl5YldGMElsMHNJbVJsYlc4aU9uUnlkV1Y5');
// Set the extensions
jspreadsheet.setExtensions({ formula });
@Component({
standalone: true,
selector: "app-root",
template: `<div #spreadsheet></div>`
})
export class AppComponent {
@ViewChild("spreadsheet") spreadsheet: ElementRef;
// Worksheets
worksheets: jspreadsheet.worksheetInstance[];
// Create a new data grid
ngAfterViewInit() {
// Create spreadsheet
this.worksheets = jspreadsheet(this.spreadsheet.nativeElement, {
worksheets: [{
data: [
[
"Hours Studied",
"Test Score"
],
[
2,
65
],
[
4,
75
],
[
6,
85
],
[
8,
90
],
[
10,
95
],
[
"Correlation:",
"=PEARSON(A2:A6,B2:B6)"
]
]
}]
});
}
}