Quartiles and Summary
Quartiles
A quartile is a type of quantile. The first quartile (Q1), is defined as the middle number between the smallest number and the median of the data set, the second quartile (Q2) – the median of the given data set while the third quartile (Q3), is the middle number between the median and the largest value of the data set.
Example:
# R program to illustrate
# Descriptive Analysis
# Import the data using read.csv()
myData = read.csv("CardioGoodFitness.csv", stringsAsFactors = F)
# Calculating Quartiles
quartiles = quantile(myData$Age)
print(quartiles)
Output:
0% 25% 50% 75% 100%
18 24 26 33 50
Interquartile Range
The interquartile range (IQR), also called as midspread or middle 50%, or technically H-spread is the difference between the third quartile (Q3) and the first quartile (Q1). It covers the center of the distribution and contains 50% of the observations.
IQR = Q3 – Q1
# R program to illustrate
# Descriptive Analysis
# Import the data using read.csv()
myData = read.csv("CardioGoodFitness.csv", stringsAsFactors = F)
# Calculating IQR
IQR = IQR(myData$Age)
print(IQR)
Output:
[1] 9The function summary() can be used to display several statistic summaries of either one variable or an entire data frame.
Summary of a single variable:
Example:
# R program to illustrate
# Descriptive Analysis
# Import the data using read.csv()
myData = read.csv("CardioGoodFitness.csv",
stringsAsFactors = F)
# Calculating summary
summary = summary(myData$Age)
print(summary)
Output:
Min. 1st Qu. Median Mean 3rd Qu. Max.
18.00 24.00 26.00 28.79 33.00 50.00
Example:
# R program to illustrate
# Descriptive Analysis
# Import the data using read.csv()
myData = read.csv("CardioGoodFitness.csv",
stringsAsFactors = F)
# Calculating summary
summary = summary(myData)
print(summary)
Output:
Product Age Gender Education
Length:180 Min. :18.00 Length:180 Min. :12.00
Class :character 1st Qu.:24.00 Class :character 1st Qu.:14.00
Mode :character Median :26.00 Mode :character Median :16.00
Mean :28.79 Mean :15.57
3rd Qu.:33.00 3rd Qu.:16.00
Max. :50.00 Max. :21.00
MaritalStatus Usage Fitness Income
Length:180 Min. :2.000 Min. :1.000 Min. : 29562
Class :character 1st Qu.:3.000 1st Qu.:3.000 1st Qu.: 44059
Mode :character Median :3.000 Median :3.000 Median : 50597
Mean :3.456 Mean :3.311 Mean : 53720
3rd Qu.:4.000 3rd Qu.:4.000 3rd Qu.: 58668
Max. :7.000 Max. :5.000 Max. :104581
Miles
Min. : 21.0
1st Qu.: 66.0
Median : 94.0
Mean :103.2
3rd Qu.:114.8
Max. :360.0
Comments
Post a Comment