About

Qualitative Descriptive Analytics aims to gather an in-depth understanding of the underlying reasons and motivations for an event or observation. It is typically represented with visuals or charts.

Quantitative Descriptive Analytics focuses on investigating a phenomenon via statistical, mathematical, and computationaly techniques. It aims to quantify an event with metrics and numbers.

In this lab project, you will explore both analytics using the data set provided.

Setup

Remember to always set your working directory to the source file location. Go to ‘Session’, scroll down to ‘Set Working Directory’, and click ‘To Source File Location’. Read carefully the below and follow the instructions to complete the tasks and answer any questions. Submit your work to RPubs as detailed in previous notes.


Task 1: Testing for Outliers(3 points)

First, calculate the mean, standard deviation, maximum, and minimum for the Age column using R.

In R, we must read the file first and extract the column and find the values that are asked for.

#Read File
creditrisk = read.csv(file="creditrisk.csv")
#Name the extracted variable
age = creditrisk$Age
#Calculate the average, standard deviation, maximum and minimum age below. 
meanage = mean(age)
meanage
## [1] 34.39765
spreadage=sd(age)
spreadage
## [1] 11.04513
MaxAge = max(age)
MaxAge
## [1] 73
MinAge = min(age)
MinAge
## [1] 18

An outlier is value that “lies outside” most of the other values in a set of data. Next, use the formula from class to find the upper and lower limits for age to decide on outliers.

#Use the common formula to calculate the upper and lower thresholds
UpperOutlier = meanage + 3*spreadage
UpperOutlier
## [1] 67.53302
LowerOutlier = meanage - 3*spreadage
LowerOutlier
## [1] 1.262269

Are there any outliers? How can you check the data to find out if there are potential outliers? Use the chunk below to make a desicion about possible outliers.

# Insert here your work to find if the data contains potential outliers.
 boxplot(age)

Another similar method to find the upper and lower thresholds discussed in introductory statistics courses involves finding the interquartile range. Use the chunk below to first calculate the interquartile range..

#interquantile range
quantile(age) 
##   0%  25%  50%  75% 100% 
##   18   26   32   41   73
lowerq = quantile(age)[2]
upperq = quantile(age)[4]
iqr = upperq - lowerq
iqr
## 75% 
##  15

The threshold is the boundaries that determine if a value is an outlier. If the value falls above the upper threshold or below the lower threshold, it can be identified as a potential outlier.

Below is the upper threshold:

upperthreshold = (iqr * 1.5) + upperq 
upperthreshold
##  75% 
## 63.5

Below is the lower threshold:

lowerthreshold = lowerq - (iqr * 1.5)
lowerthreshold
## 25% 
## 3.5

Are there any outliers? How many?

It can also be useful to visualize the data using a box and whisker plot. Use the boxplot() command to visualize your data.

 boxplot(age)

Can you identify the outliers from the boxplot? If so how many outliers? There are 5 outliers.

Task 2: Quantitative Analysis - Marketing (2 points)

Begin by reading in the data from the ‘marketing.csv’ file, and viewing it to make sure it is read in correctly.

#read the marketing file and view it to make sure it is read correctly
marketing = read.csv(file="marketing.csv") 
head(marketing)
##   case_number sales radio paper  tv pos
## 1           1 11125    65    89 250 1.3
## 2           2 16121    73    55 260 1.6
## 3           3 16440    74    58 270 1.7
## 4           4 16876    75    82 270 1.3
## 5           5 13965    69    75 255 1.5
## 6           6 14999    70    71 255 2.1

Now calculate the Range, Min, Max, Mean, STDEV, and Variance for the variable ‘sales’.

Sales

#Max Sales
sales = marketing$sales
Maxsales = max(sales)
Maxsales
## [1] 20450
#Min Sales
sales = marketing$sales
Minsales = min(sales)
Minsales
## [1] 11125
#Range
sales = marketing$sales
rangesales = range(sales)
rangesales
## [1] 11125 20450
#Mean
sales = marketing$sales
Meansales = mean(sales)
Meansales
## [1] 16717.2
#Standard Deviation
sales = marketing$sales
spreadsales = sd(sales)
spreadsales
## [1] 2617.052
#Variance
sales = marketing$sales
varsales = var(sales)
varsales
## [1] 6848961

An easy way to calculate the statistics of all of these variables is with the summary() function. Run the summary command to visualize the statistics for all variables in the dataset.

# Summary statistics for all variables. 
summary(marketing)
##   case_number        sales           radio           paper      
##  Min.   : 1.00   Min.   :11125   Min.   :65.00   Min.   :35.00  
##  1st Qu.: 5.75   1st Qu.:15175   1st Qu.:70.00   1st Qu.:53.75  
##  Median :10.50   Median :16658   Median :74.50   Median :62.50  
##  Mean   :10.50   Mean   :16717   Mean   :76.10   Mean   :62.30  
##  3rd Qu.:15.25   3rd Qu.:18874   3rd Qu.:81.75   3rd Qu.:75.50  
##  Max.   :20.00   Max.   :20450   Max.   :89.00   Max.   :89.00  
##        tv             pos       
##  Min.   :250.0   Min.   :0.000  
##  1st Qu.:255.0   1st Qu.:1.200  
##  Median :270.0   Median :1.500  
##  Mean   :266.6   Mean   :1.535  
##  3rd Qu.:276.2   3rd Qu.:1.800  
##  Max.   :280.0   Max.   :3.000

You can also use the summary() command to find the statistics for the sales variable.

# Summary statistics for the sales variable
summary(sales)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   11125   15175   16658   16717   18874   20450

There are some statistics not calculated with the summary() function. Specify which. Range, Variance, Standard Deviation. ———-

Task 3: Calculating Z-Value (2 points)

Given a sales value of $25000, calculate the corresponding z-value or z-score.

#  Calculate the z-value and display it
(25000 - 16717)/2617.052
## [1] 3.165012

Based on the z-value, how would you rate a $25000 sales value: poor, average, good, or very good performance? Explain your logic.

I would rate a $25,000 sales value as a very good performance. We know this because the average sales value, or mean, was $16,717, which is exceeded by almost $10,000. A z-value of 3 also suggests good financial positioning, so we are able to assume this is a very good performance because it exceeds the value of good positioning.