Professional Documents
Culture Documents
Formula :
Frequency (f) = Number of data points in a specific category or with a particular value
In mathematical notation, for a specific category or value 'c', the formula is:
Example in c++ :
#include <iostream>
#include <map>
int main() {
cin >> n;
int dataPoint;
frequencyMap[dataPoint]++;
cout << "Value: " << pair.first << " - Frequency: " << pair.second << std::endl;
}
return 0;
Arithmetic Mean :
The arithmetic mean, often referred to as the average, is a measure of central tendency in statistics. It is
calculated by adding up all the values in a dataset and then dividing the sum by the number of values.
The formula for the arithmetic mean (mean or average) is as follows:
Example in c++ :
#include <iostream>
int main() {
int n;
cin >> n;
if (n <= 0) {
return 1;
double value;
sum += value;
cout << "Arithmetic Mean (Average) is: " << mean << endl;
return 0;
Harmonic Mean :
The harmonic mean is a mathematical average used to calculate the reciprocal of the arithmetic mean
of a set of values. It is often used in situations where rates or ratios are involved. The formula for the
harmonic mean of n values, denoted as H, is:
Formula:
H = n / [(1/x₁) + (1/x₂) + (1/x₃) + ... + (1/xₙ)]
Where:
x₁, x₂, x₃, ..., xₙ are the individual values for which you want to calculate the harmonic mean.
Example in c++ :
#include <iostream>
int main() {
cin >> n;
if (n <= 0) {
return 1;
double x;
cin >> x;
sumReciprocals += 1.0 / x;
cout << "The harmonic mean is: " << harmonicMean << endl;
return
Geometric Mean :
The geometric mean is a measure of central tendency used to find the average of a set of values by
multiplying them together and then taking the nth root, where "n" is the number of values. It is often
used when dealing with quantities that have a multiplicative relationship, such as growth rates or
investment returns
Example in c++ :
#include <iostream>
#include <cmath>
int main() {
cin >> n;
if (n <= 0) {
return 1;
double x;
cin >> x;
product *= x;
}
cout << "The geometric mean is: " << geometricMean << endl;
return 0;
Mode :
The mode is a statistical measure that represents the value(s) in a data set that occur most frequently. In
other words, it is the value(s) that appear with the highest frequency within a dataset. A dataset can
have one mode (unimodal) or multiple modes (multimodal) if there are multiple values that occur with
the same highest frequency.
Example in c++ :
#include <iostream>
#include <map>
#include <vector>
int main() {
cin >> n;
if (n <= 0) {
return 1;
int x;
cin >> x;
valueFrequency[x]++;
int maxFrequency = 0;
modes.clear();
modes.push_back(pair.first);
maxFrequency = pair.second;
modes.push_back(pair.first);
if (modes.size() == 1) {
cout << "The mode is: " << modes[0] << " with a frequency of " << maxFrequency << endl;
} else {
if (i < modes.size() - 1) {
cout << " with a frequency of " << maxFrequency << endl;
return 0;
}
Median :
The median is a measure of central tendency in statistics. It is the middle value of a dataset when the
data is arranged in ascending or descending order. In other words, it is the value that separates the
higher half from the lower half of the data. If the dataset has an even number of values, the median is
the average of the two middle values.
Example in c++ :
#include <iostream>
#include <algorithm>
#include <vector>
int main() {
vector<double> values;
cin >> n;
if (n <= 0) {
return 1;
double x;
cin >> x;
values.push_back(x);
sort(values.begin(), values.end());
double median;
int middle = n / 2;
if (n % 2 == 0) {
// If the number of values is even, take the average of the two middle values
} else {
median = values[middle];
cout << "The median is: " << median << endl;
return 0;
Range :
In statistics, the range of a dataset is a measure of the spread or dispersion of the data. It is defined as
the difference between the maximum (largest) value and the minimum (smallest) value in the dataset.
The range provides a simple way to understand the extent to which the data values vary.
Example in c++ :
#include <iostream>
#include <vector>
#include <algorithm>
int main() {
vector<double> values;
cin >> n;
if (n <= 0) {
return 1;
}
double x;
cin >> x;
values.push_back(x);
sort(values.begin(), values.end());
cout << "The range is: " << range << endl;
return 0;
Variance :
Variance is a statistical measure that quantifies the extent to which data points in a dataset deviate from
the mean (average). It provides a measure of the spread or dispersion of the data. A higher variance
indicates that the data points are more spread out from the mean, while a lower variance suggests that
they are closer to the mean.
Example in c++ :
#include <iostream>
#include <vector>
int main() {
vector<double> values;
cin >> n;
if (n <= 0) {
return 1;
double x;
cin >> x;
values.push_back(x);
mean += x;
if (n > 1) {
mean /= n;
} else {
variance = 0.0;
cout << "The variance is: " << variance << endl;
return 0;
Standard deviation :
The standard deviation is a measure of the amount of variation or dispersion in a set of values. It
quantifies how spread out the values are from the mean (average) of the dataset. A higher standard
deviation indicates that the values are more spread out, while a lower standard deviation indicates that
the values are closer to the mean.
Example in c++ :
#include <iostream>
#include <vector>
#include <cmath>
int main() {
vector<double> values;
cin >> n;
if (n <= 0) {
return 1;
double x;
cin >> x;
values.push_back(x);
mean += x;
if (n > 1) {
mean /= n;
}
variance /= n - 1; // Sample variance
} else {
standardDeviation = 0.0;
cout << "The standard deviation is: " << standardDeviation << endl;
return 0;
Regression :
Regression is a statistical technique used to model and analyze the relationship between a dependent
variable and one or more independent variables. It is commonly used in various fields, including
economics, social sciences, natural sciences, and machine learning. The primary goal of regression
analysis is to understand and quantify the relationships between variables, make predictions, and
identify patterns in the data.
Example in c++ :
#include <iostream>
#include <Eigen/Dense>
int main() {
cin >> n;
if (n <= 1) {
cout << "Regression analysis requires at least two data points." << endl;
return 1;
cout << "Linear Regression Equation: y = " << slope << "x + " << intercept << endl;
return 0;
Skewness :
Skewness is a statistical measure that describes the asymmetry of the probability distribution of a real-
valued random variable about its mean. In simpler terms, it quantifies the degree to which the data in a
dataset is skewed or biased to one side of the mean.
Example in c++ :
#include <iostream>
#include <vector>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics.hpp>
#include <boost/accumulators/statistics/skewness.hpp>
int main() {
vector<double> data;
cin >> n;
if (n <= 2) {
cout << "Skewness analysis requires at least three data points." << endl;
return 1;
double x;
cin >> x;
data.push_back(x);
acc(data[i]);
cout << "Skewness of the data: " << skew << endl;
return 0;