Statistics Fundamentals

Statisticsbeginner~10 min

Compute descriptive statistics, fit distributions, run hypothesis tests, and cluster data.

Step 1 — Descriptive statistics

Summarize data with mean, standard deviation, and percentiles.

data = randn(1, 1000);
disp(mean(data));
disp(std(data));
disp(prctile(data, [25 50 75]))
▶ Run in SimLab

Expected output: Mean near 0, std near 1, quartiles

Step 2 — Histogram

Visualize data distribution.

data = randn(1, 500);
histogram(data);
title('Normal Distribution Sample')
▶ Run in SimLab

Expected output: Bell-shaped histogram

Step 3 — Hypothesis testing

ttest() returns an object with t-statistic, p-value, degrees of freedom, and confidence interval.

sample = 5 + 0.5*randn(1, 30);
result = ttest(sample, 5);
printf('p-value: %.4f, t-stat: %.2f', result.p, result.t)
▶ Run in SimLab

Expected output: p-value and t-statistic

Step 4 — K-means clustering

Group 2D data into clusters.

rng(42);
x1 = randn(1, 50);
y1 = randn(1, 50);
x2 = 3 + randn(1, 50);
y2 = 3 + randn(1, 50);
scatter([x1, x2], [y1, y2]);
title('Two visible clusters')
▶ Run in SimLab

Expected output: Scatter plot with 2 visible clusters

Related Tutorials

Try SimLab — MATLAB®-compatible, free, in your browser

466 functions. Runs in your browser. No install.

Open SimLab

MATLAB® is a registered trademark of The MathWorks, Inc. SimLab is an independent project by Simulations4All and is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

Stay Updated

Get notified about new simulations and tools. We send 1-2 emails per month.