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 SimLabExpected 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 SimLabExpected output: p-value and t-statistic
Step 4 — K-means clustering
Group 2D data into clusters.
X = [randn(50,2); 3+randn(50,2)];
[idx, C] = kmeans(X, 2);
scatter(X(:,1), X(:,2));
title('K-means Clustering')▶ Run in SimLabExpected output: Scatter plot with 2 visible clusters
Related Tutorials
Try SimLab — Free MATLAB® Alternative
466 functions. Runs in your browser. No install.
Open SimLab