or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

array-operations.mdcombinatorics.mddata-manipulation.mddescriptive-statistics.mddistributions.mdindex.mdmachine-learning.mdmath-utilities.mdquantiles.mdregression.mdtesting.md

index.mddocs/

0

# Simple Statistics

1

2

A comprehensive JavaScript implementation of descriptive, regression, and inference statistics designed for data analysis and statistical computing.

3

4

## Package Information

5

6

- **Package Name**: simple-statistics

7

- **Package Type**: npm

8

- **Language**: JavaScript with TypeScript definitions

9

- **Installation**: `npm install simple-statistics`

10

- **Version**: 6.1.1

11

- **Dependencies**: None (zero dependencies)

12

13

## Core Imports

14

15

Import specific functions (recommended):

16

```typescript

17

import { mean, median, standardDeviation, linearRegression } from "simple-statistics";

18

```

19

20

Import entire library:

21

```typescript

22

import * as ss from "simple-statistics";

23

```

24

25

CommonJS:

26

```javascript

27

const { mean, median, standardDeviation, linearRegression } = require("simple-statistics");

28

```

29

30

## Basic Usage

31

32

```typescript

33

import { mean, standardDeviation, linearRegression } from "simple-statistics";

34

35

// Descriptive statistics

36

const data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

37

const average = mean(data); // 5.5

38

const stdDev = standardDeviation(data); // 2.87...

39

40

// Linear regression

41

const xyData = [[1, 1], [2, 2], [3, 1.3], [4, 3.75], [5, 2.25]];

42

const regression = linearRegression(xyData); // {m: 0.425, b: 0.785}

43

```

44

45

## Architecture

46

47

The library provides over 95 statistical functions organized into logical functional areas:

48

49

- **Descriptive Statistics**: Central tendency, variability, and distribution shape measures

50

- **Regression Analysis**: Linear regression and correlation analysis

51

- **Probability Distributions**: Normal, binomial, Poisson, and other distributions

52

- **Statistical Testing**: Hypothesis tests and goodness-of-fit tests

53

- **Machine Learning**: Bayesian and perceptron classifiers

54

- **Data Manipulation**: Sampling, shuffling, and array operations

55

- **Mathematical Utilities**: Root finding, gamma functions, and numerical utilities

56

57

## Capabilities

58

59

### Descriptive Statistics

60

61

Calculate measures of central tendency, spread, and distribution shape.

62

63

```typescript { .api }

64

function mean(values: number[]): number;

65

function median(values: number[]): number;

66

function mode(values: number[]): number;

67

function standardDeviation(values: number[]): number;

68

function variance(values: number[]): number;

69

function sampleVariance(values: number[]): number;

70

function sampleSkewness(values: number[]): number;

71

function sampleKurtosis(values: number[]): number;

72

```

73

74

[Descriptive Statistics](./descriptive-statistics.md)

75

76

### Regression Analysis

77

78

Perform linear regression analysis and correlation calculations.

79

80

```typescript { .api }

81

interface RegressionResult {

82

m: number; // slope

83

b: number; // y-intercept

84

}

85

86

function linearRegression(data: Array<[number, number]>): RegressionResult;

87

function linearRegressionLine(mb: RegressionResult): (x: number) => number;

88

function rSquared(data: Array<[number, number]>, func: (x: number) => number): number;

89

function sampleCorrelation(x: number[], y: number[]): number;

90

function sampleCovariance(x: number[], y: number[]): number;

91

```

92

93

[Regression Analysis](./regression.md)

94

95

### Probability Distributions

96

97

Work with various probability distributions and normal distribution functions.

98

99

```typescript { .api }

100

function bernoulliDistribution(p: number): number[];

101

function binomialDistribution(trials: number, probability: number): number[];

102

function poissonDistribution(lambda: number): number[];

103

function zScore(x: number, mean: number, standardDeviation: number): number;

104

function cumulativeStdNormalProbability(z: number): number;

105

function errorFunction(x: number): number;

106

function inverseErrorFunction(x: number): number;

107

function probit(p: number): number;

108

function standardNormalTable: number[];

109

function chiSquaredDistributionTable: number[];

110

```

111

112

[Probability Distributions](./distributions.md)

113

114

### Statistical Testing

115

116

Perform hypothesis tests and goodness-of-fit analysis.

117

118

```typescript { .api }

119

function tTest(sample: number[], expectedValue: number): number;

120

function tTestTwoSample(sampleX: number[], sampleY: number[], difference?: number): number | null;

121

function chiSquaredGoodnessOfFit(data: number[], distributionType: Function, significance: number): boolean;

122

function permutationTest(sampleX: number[], sampleY: number[], testType?: string, k?: number): number;

123

```

124

125

[Statistical Testing](./testing.md)

126

127

### Machine Learning

128

129

Classification algorithms for supervised learning tasks.

130

131

```typescript { .api }

132

class BayesianClassifier {

133

totalCount: number;

134

data: Record<string, any>;

135

136

train(item: Record<string, any>, category: string): void;

137

score(item: Record<string, any>): Record<string, number>;

138

}

139

140

class PerceptronModel {

141

weights: number[];

142

bias: number;

143

144

predict(features: number[]): number;

145

train(features: number[], label: number): PerceptronModel;

146

}

147

148

function ckmeans<T>(data: T[], nClusters: number): T[][];

149

function kernelDensityEstimation(X: number[], kernel?: string | Function, bandwidthMethod?: string | number): (x: number) => number;

150

```

151

152

[Machine Learning](./machine-learning.md)

153

154

### Quantiles and Ranges

155

156

Calculate percentiles, quartiles, and range statistics.

157

158

```typescript { .api }

159

function quantile(values: number[], p: number): number;

160

function quantile(values: number[], p: number[]): number[];

161

function quantileRank(values: number[], value: number): number;

162

function interquartileRange(values: number[]): number;

163

function medianAbsoluteDeviation(values: number[]): number;

164

```

165

166

[Quantiles and Ranges](./quantiles.md)

167

168

### Data Manipulation

169

170

Sampling, shuffling, and array manipulation utilities.

171

172

```typescript { .api }

173

function sample<T>(population: T[], n: number, randomSource?: () => number): T[];

174

function sampleWithReplacement<T>(population: T[], n: number, randomSource?: () => number): T[];

175

function shuffle<T>(array: T[], randomSource?: () => number): T[];

176

function shuffleInPlace<T>(array: T[], randomSource?: () => number): T[];

177

function chunk<T>(array: T[], chunkSize: number): T[][];

178

function uniqueCountSorted(values: number[]): Array<{value: number, count: number}>;

179

function sumNthPowerDeviations(values: number[], n: number): number;

180

function equalIntervalBreaks(values: number[], nClasses: number): number[];

181

```

182

183

[Data Manipulation](./data-manipulation.md)

184

185

### Combinatorics

186

187

Functions for combinations and permutations.

188

189

```typescript { .api }

190

function combinations<T>(x: T[], k: number): T[][];

191

function combinationsReplacement<T>(x: T[], k: number): T[][];

192

function permutationsHeap<T>(x: T[]): T[][];

193

```

194

195

[Combinatorics](./combinatorics.md)

196

197

### Mathematical Utilities

198

199

Root finding, special functions, and numerical utilities.

200

201

```typescript { .api }

202

function bisect(func: (x: any) => number, start: number, end: number, maxIterations: number, errorTolerance: number): number;

203

function factorial(n: number): number;

204

function gamma(n: number): number;

205

function gammaln(n: number): number;

206

function sign(x: number): number;

207

function numericSort(array: number[]): number[];

208

function quickselect<T>(array: T[], k: number, compare?: (a: T, b: T) => number): T;

209

210

const epsilon: number;

211

```

212

213

[Mathematical Utilities](./math-utilities.md)

214

215

### Array Operations

216

217

Basic array operations for finding extremes and products.

218

219

```typescript { .api }

220

function min(values: number[]): number;

221

function max(values: number[]): number;

222

function extent(values: number[]): [number, number];

223

function minSorted(values: number[]): number;

224

function maxSorted(values: number[]): number;

225

function extentSorted(values: number[]): [number, number];

226

function sum(values: number[]): number;

227

function sumSimple(values: number[]): number;

228

function product(values: number[]): number;

229

```

230

231

[Array Operations](./array-operations.md)