Docsity

How to find outliers by using C++ programming language., Study Guides, Projects, Research of Statistics

Toggle sidebar
bg1
Outliers by Using 5 Number Summary of Data
Opu Raihan
Department of Computer Science & Engineering (CSE)
Bangladesh University of Business and Technology, Dhaka, Bangladesh
Abstract:
Outliers are data values that differ greatly from the majority of a set of data. These values fall
outside of an overall trend that is present in the data. A careful examination of a set of data to look for
outliers causes some difficulty. Although it is easy to see, possibly by use of a stem plot, that some
values differ from the rest of the data, how much different does the value have to be to be considered
an outlier? We will look at a specific measurement that will give us an objective standard of what
constitutes an outlier.
The interquartile range is what we can use to determine if an extreme value is indeed an outlier. The
interquartile range is based upon part of the five-number summary of a data set, namely the first
quartile and the third quartile. The calculation of the interquartile range involves a single arithmetic
operation. All that we have to do to find the interquartile range is to subtract the first quartile from
the third quartile. The resulting difference tells us how spread out the middle half of our data is.
Multiplying the interquartile range (IQR) by 1.5 will give us a way to determine whether a certain
value is an outlier. If we subtract 1.5 x IQR from the first quartile, any data values that are less than
this number are considered outliers. Similarly, if we add 1.5 x IQR to the third quartile, any data
values that are greater than this number are considered outliers.
We always need to be on the lookout for outliers. Sometimes they are caused by an error. Other times
outliers indicate the presence of a previously unknown phenomenon. Another reason that we need to
be diligent about checking for outliers is because of all the descriptive statistics that are sensitive to
outliers. The mean, standard deviation and correlation coefficient for paired data are just a few of
these types of statistics.
Keywords:
Outliers, Even, Odd, Lower limit, Upper limit, Calculate, C++, Value, Observation, IQR etc.
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download How to find outliers by using C++ programming language. and more Study Guides, Projects, Research Statistics in PDF only on Docsity!

Outliers by Using 5 Number Summary of Data

Opu Raihan

Department of Computer Science & Engineering (CSE) Bangladesh University of Business and Technology, Dhaka, Bangladesh

Abstract:

O utliers are data values that differ greatly from the majority of a set of data. These values fall

outside of an overall trend that is present in the data. A careful examination of a set of data to look for outliers causes some difficulty. Although it is easy to see, possibly by use of a stem plot, that some values differ from the rest of the data, how much different does the value have to be to be considered an outlier? We will look at a specific measurement that will give us an objective standard of what constitutes an outlier. The interquartile range is what we can use to determine if an extreme value is indeed an outlier. The interquartile range is based upon part of the five-number summary of a data set, namely the first quartile and the third quartile. The calculation of the interquartile range involves a single arithmetic operation. All that we have to do to find the interquartile range is to subtract the first quartile from the third quartile. The resulting difference tells us how spread out the middle half of our data is. Multiplying the interquartile range (IQR) by 1.5 will give us a way to determine whether a certain value is an outlier. If we subtract 1.5 x IQR from the first quartile, any data values that are less than this number are considered outliers. Similarly, if we add 1.5 x IQR to the third quartile, any data values that are greater than this number are considered outliers. We always need to be on the lookout for outliers. Sometimes they are caused by an error. Other times outliers indicate the presence of a previously unknown phenomenon. Another reason that we need to be diligent about checking for outliers is because of all the descriptive statistics that are sensitive to outliers. The mean, standard deviation and correlation coefficient for paired data are just a few of these types of statistics.

Keywords:

Outliers, Even, Odd, Lower limit, Upper limit, Calculate, C++, Value, Observation, IQR etc.

1. Introduction:

❖ Outlier: In statistics, an outlier is a data point that differs significantly from other

observations. An outlier may be due to variability in the measurement or it may indicate experimental error; the latter are sometimes excluded from the data set. An outlier can cause serious problems in statistical analyses. Outliers, being the most extreme observations. We can use the IQR method of identifying outliers. This is the method that Minitab Express uses to identify outliers by default.

❖ Programming in C++: C++ is a general-purpose programming language created

by “Bjarne Stroustrup” as an extension of the C programming language, or "C with Classes". The language has expanded significantly over time, and modern C++ now has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation. C++ first appeared in 1985. C++ was designed with an orientation toward system programming and embedded, resource- constrained software and large systems, with performance, efficiency, and flexibility of use as its design highlights. C++ is standardized by the International Organization for Standardization (ISO), with the latest standard version ratified and published by ISO in December 2020 as ISO/IEC 14882:2020 (informally known as C++20).

❖ About our work: In this paper work we have described about ‘Outlier’. What is

outlier, how does it work, importance of outlier. We have also described here how to find outliers by using 5 number summary. We used IQR method. We worked here with some random sample of 20 student’s data. How many textbooks they have. We have calculated here minimum, Q1, Q2, Q3 and maximum. Then we have calculated IQR by using Q3 and Q1. After that we calculated ‘Lower limit’ and ‘Upper limit’. After finishing all the calculation, we got outliers. We also made an algorithm, flowchart and built a program by using C++ programming language. The program was runes well and we have added the output of the program.

❖ Organization of paper: In point number 2, we described how to find outliers by

using 5 number summary. In point number 3, we have built a program for finding outliers. In point number 3, we have also added point 3.1 for Algorithm, 3.2 for Flowchart and 3.3 for Programming Structure. In point number 4 we have discussed about results. In point number 5 we have given Conclusion.

3 ( 20 + 1 ) 4

th value of the observation

3 ∗ 21 4

th value of the observation

63 4

th value of the observation = 15.75th^ value of the observation ≈ 16th^ value of the observation [approximately] Q3 = 12

  1. Maximum = 25 To find outliers first find IQR (Inter Quartile Range), IQR = Q3-Q1 = 12-8 = 4 Outliers means value higher than (Q3+1.5IQR) or lower than (Q1-1.5IQR) Now, Lower limit = Q1-1.5IQR = 8-1.54 = 8-6 = 2 Upper limit = Q3+1.5IQR = 12+1.54 = 12+6 = 18 Any observations less than 2 books or greater than 18 books are outliers. There are 4 outliers: 0, 0, 20,

3. Outliers by Using Programming Language: 3.1 Algorithm:

  1. Start
  2. Get array size, n
  3. Sort smallest to largest
  4. Check total array size, n ‘Even’ or ‘Odd’
  5. If even check half of the numbers even or odd. i. If even {Q1=(a[n1/2] +a[(n1/2)-1])/2.0, Q3= (a[n1+(n1/2)] +a[n1+(n1/2)-1])/2.0} ii. If odd {Q1 = a[n1/2], Q3 = a[n1+(n1/2)]}
  6. If odd get n1= n/2+1. Check n1 even or odd i. If even {Q1 = (a[n1/2] +a[(n1/2)-1])/2.0, Q3 = (a[n1-1+(n1/2)] +a[n1+(n1/2)-2])/2.0} ii. If odd {Q1 = a[n1/2], Q3 = a[n1-1+(n1/2)]}
  7. Calculate IQR= Q3-Q
  8. Calculate lower limit= Q1-1.5*IQR
  9. Calculate upper limit= Q3+1.5*IQR
  10. Get outliers from given array with a ‘for’ loop
  11. Stop

3 .2 Flowchart:

Start

Get array size, n

Sort smallest to largest

Check total array

size, n even or odd

Check half of the number even or odd Gets n1= n/2+1. Check n1 even or odd {Q1= (a[n1/2] +a[(n1/2)-1])/2.0, Q3= (a[n1+(n1/2)] +a[n1+(n1/2)-2])/2.0} {Q1= a[n1/2] Q3= a[n1+(n1/2)]} {Q1 = (a[n1/2] +a[(n1/2)-1])/2.0, Q3 = (a[n1-1+(n1/2)] +a[n1+(n1/2)-2])/2.0} {Q1= a[n1/2] Q3= a[n1+(n1/2)]}

Calculate IQR= (Q3-Q1)

Calculate lower limit= (Q1-1.5*IQR)

Calculate upper limit= (Q3+1.5*IQR)

Get outliers from given array with a for loop

Stop

If even If odd

If even If odd If even If odd

int n1 = n/2+1;

if(n1%2==0)

q1 = (a[n1/2]+a[(n1/2)-1])/2.0;

q3 = (a[n1-1+(n1/2)]+a[n1+(n1/2)-2])/2.0;

else

q1 = a[n1/2];

q3 = a[n1-1+(n1/2)];

return q3-q1;

// Driver Function

int main()

int a[] = { 0, 0, 2, 5, 8, 8, 8, 9, 9, 10, 10, 10, 11, 12, 12, 12, 14, 15, 20, 25 };

int n = sizeof(a)/sizeof(a[0]);

double iqr = IQR(a,n);

double lower_limit,upper_limit;

lower_limit = q1-1.5*iqr;

upper_limit = q3+1.5*iqr;

cout <<"\nFirst Quartile(Q1)\t=\t"<< q1 << endl <<"Third Quartile(Q3)\t=\t"<< q3 <<

endl <<"IQR\t\t\t=\t"<< iqr << endl << "Lower Limit\t\t=\t"<< lower_limit << endl

<<"Upper Limit\t\t=\t"<< upper_limit << endl;

cout << "Outliers\t\t= \t";

int flag = 0;

for(int i=0; i<n; i++)

if(a[i]<lower_limit || a[i]>upper_limit)

cout << a[i] << "\t";

flag = 1;

if(flag == 0)

cout << "No Outliers Found";

cout << endl;

return 0;

4. Results and Discussions: Outliers by using 5 number summary Answer Q1 = 8 Q3 = 12