<title>Analyze — Correlate · Usage</title>
<description>How to compute pairwise correlations and reliability. Covers two-column vs matrix outputs and Cronbach’s alpha.</description>
<keywords>pearson, sample vs population, spearman, kendall, cronbach alpha, correlation matrix</keywords>

# Correlate — practical usage

## Two columns vs matrix

```js
import { Analyze } from 'als-statistics';
const { Correlate } = Analyze;

// 1) EXACTLY TWO columns → returns a single test instance
const one = new Correlate({ X: [1,2,3], Y: [2,4,9] }).pearson('X', 'Y');
console.log(one.r, one.t, one.df, one.p);

// 2) THREE OR MORE columns → returns a map of pairwise results
const all = new Correlate({ A:[...], B:[...], C:[...] }).pearson();
console.log(Object.keys(all));        // ['A|B','A|C','B|C']
console.log(all['A|B'].r, all['A|B'].p);
```

### Population vs sample (Pearson)

- `pearson()` — uses **population** covariance in the r-formula.
- `pearsonSample()` — uses **sample** covariance.
- Both provide two-sided `p` via the t-distribution with `df = n - 2`.

```js
const p1 = new Correlate(data).pearson();        // population r
const p2 = new Correlate(data).pearsonSample();  // sample r
```

### Spearman & Kendall (ties handled)

```js
const s = new Correlate({ X:[...], Y:[...] }).spearman('X','Y');
const k = new Correlate({ X:[...], Y:[...] }).kendall('X','Y');
console.log(s.r, s.p, k.tau, k.p);
```


> Two-sided helpers: `.spearmanTwoSided()` и `.kendallTwoSided()`.


## Reliability — Cronbach’s alpha

```js
// Option A: import the class directly
import { CronbachAlpha } from 'als-statistics/analyze/correlate/cronbach-alpha.js';

// Option B: via the namespace
import { Analyze } from 'als-statistics';
const { Correlate } = Analyze;
// new Correlate.CronbachAlpha(table)  // same class

const items = { Q1:[...], Q2:[...], Q3:[...] };
const alpha = new CronbachAlpha(items);

console.log(alpha.alpha);          // overall alpha
console.log(alpha.ifItemsDeleted); // { Q1: α_if_deleted, ... }
console.log(alpha.htmlTable);      // ready-to-embed HTML with a small table
```

> Notes:
> - `Correlate` methods **auto-trim** vectors to the shortest length where needed (e.g., Spearman).
> - Pairwise matrices return a plain object of test instances keyed as `'A|B'`.
