Open In App

How to find the Standard deviation in Statistics?

Last Updated : 05 Sep, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Statistics is the study of data gathering, organization, interpretation, analysis, and presentation in mathematics. The primary goal of statistics is to plan the obtained data in terms of experimental designs and statistical surveys. Statistics is regarded as a mathematical science that deals with numerical data. In brief, statistics is a critical process that assists in making data-driven decisions. An example of statistical analysis is determining the percentage of a town’s population who watched a movie out of the entire population. The small group of persons picked from the population is referred to as the sample here.

What is Standard Deviation?

Standard deviation is a metric that represents the amount to which various values of a statistical series tend to fluctuate or disperse from its mean or median. It describes how the values are distributed over the data sample and is a measure of the data points’ deviation from the mean. The square root of the variance of a sample, statistical population, random variable, data collection, or probability distribution is its standard deviation.

Standard Deviation Formula

The formula for sample standard deviation(s) is as follows:

s=\frac{\sqrt{\sum({x_i-\bar{x}})^2}}{N}

where,

xi = data values in the set

 xÌ„ = mean of the data

N = number of data values

Example: Find the standard deviation for the data: 42, 38, 35, 26, 45, 52, 48.

Solution:

We have, N = 7.

Mean (x̄) = (42+38+35+26+45+52+48)/7 = 40.85

Standard deviation = \frac{\sqrt{\sum({x_i-\bar{x}})^2}}{N}

\frac{\sqrt{(40.85-42)^2+(40.85-38)^2+(40.85-35)^2+(40.85-26)^2+(40.85-45)^2+(40.85-52)^2+(40.85-48)^2}}{7}

= 8.07

Sample Problems

Question 1. Find the standard deviation for the data: 41, 28, 69, 36, 47.

Solution:

We have, N = 5.

Mean (x̄) = (41+28+69+36+47)/5 = 44.2

Standard deviation = \frac{\sqrt{\sum({x_i-\bar{x}})^2}}{N}

\frac{\sqrt{(44.2-41)^2+(44.2-28)^2+(44.2-69)^2+(44.2-36)^2+(44.2-47)^2}}{5}

= 13.87

Question 2. Find the standard deviation for the data: 3, 2, 7, 1, 4.

Solution:

We have, N = 5.

Mean (x̄) = (3+2+7+1+4)/5 = 3.4

Standard deviation = \frac{\sqrt{\sum({x_i-\bar{x}})^2}}{N}

\frac{\sqrt{(3.4-3)^2+(3.4-2)^2+(3.4-7)^2+(3.4-1)^2+(3.4-4)^2}}{5}

= 2.059

Question 3. Find the standard deviation for the data: 2, 4, 6, 8, 10.

Solution:

We have, N = 5.

Mean (x̄) = (2+4+6+8+10)/5 = 6

Standard deviation = \frac{\sqrt{\sum({x_i-\bar{x}})^2}}{N}

\frac{\sqrt{(6-2)^2+(6-4)^2+(6-6)^2+(6-8)^2+(6-10)^2}}{5}

= 2.82

Question 4. Find the standard deviation for the data: 1, 3, 5, 7, 9.

Solution:

We have, N = 5.

Mean (x̄) = (1+3+5+7+9)/5 = 5

Standard deviation = \frac{\sqrt{\sum({x_i-\bar{x}})^2}}{N}

\frac{\sqrt{(5-1)^2+(5-3)^2+(5-5)^2+(5-7)^2+(5-9)^2}}{5}

= 2.82

Question 5. Find the standard deviation for the data: 18, 32, 9, 20, 15.

Solution:

We have, N = 5.

Mean (x̄) = (18+32+9+20+15)/5 = 18.8

Standard deviation = \frac{\sqrt{\sum({x_i-\bar{x}})^2}}{N}

\frac{\sqrt{(18.8-18)^2+(18.8-32)^2+(18.8-9)^2+(18.8-20)^2+(18.8-15)^2}}{5}

= 7.57

Question 6. Find the standard deviation for the data: 16, 21, -3, 12, 20.

Solution:

We have, N = 5.

Mean (x̄) = (16+21-3+12+20)/5 = 13.2

Standard deviation = \frac{\sqrt{\sum({x_i-\bar{x}})^2}}{N}

\frac{\sqrt{(13.2-16)^2+(13.2-21)^2+(13.2+3)^2+(13.2-12)^2+(13.2-20)^2}}{5}

= 8.70

C++

#include <bits/stdc++.h>
using namespace std;
 
double standardDeviation(vector<int>& v, int n)
{
    // Find the mean of all the values
    int mean = accumulate(v.begin(), v.end(), 0);
    float meanAvg = (float)mean / n;
 
    double sd = 0;
 
    // Now, subtract the meanAvg from every element of v[i]
    // and get its absolute value. Square the absolute value
    // and add it to sd (standard deviation).
 
    for (int i = 0; i < n; i++) {
        sd += pow(abs(meanAvg - v[i]), 2);
    }
 
    // Atlast, till this point sd contains sum of the
    // squares of (abs(meanAvg-v[i]))
    sd /= (n);
 
    // divide the sd by N, to get the variance.
    // square root of sd gives standard Deviation.
    return sqrt(sd);
}
 
// Main method
int main()
{
    int n;
    cin >> n;
    vector<int> arr(n);
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    cout << standardDeviation(arr, n) << endl;
}

                    

Output
-nan


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads