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. It is more exploratory in nature.
Quantitative Descriptive Analytics focuses on investigating a phenomenon via statistical, mathematical, and computationaly techniques. It aims to quantify an event with metrics and numbers. It is more explanatory in nature.
In this lab, we will explore both analytics using the data set provided.
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 in Sakai as detailed in previous notes.
For your assignment you may be using different data sets than what is included here. Always read carefully the instructions provided, before executing any included code chunks and/or adding your own code. For clarity, tasks/questions to be completed/answered are highlighted in red color and numbered according to their particular placement in the task section. The red color is only apparent when in Preview mode. Quite often you will need to add your own code chunk.
Execute all code chunks (already included and own added), preview, check integrity, and submit final work (\(html\) file) in Sakai.
Begin by reading in the data from the ‘marketing.csv’ file, and viewing it to make sure it is read in correctly.
mydata = read.csv(file="marketing.csv")
head(mydata)
## 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 let’s calculate the Range, Min, Max, Mean, STDEV, and Variance for each variable. Below is an example of how to compute the items for the variable ‘sales’.
sales = mydata$sales
#Max Sales
max = max(sales)
max
## [1] 20450
#Min Sales
min = min(sales)
min
## [1] 11125
#Range
max-min
## [1] 9325
#Mean
mean(sales)
## [1] 16717.2
#Standard Deviation
sd(sales)
## [1] 2617.052
#Variance
var(sales)
## [1] 6848961
##### 1A) Repeat the above statistics for the variable radio
radio = mydata$radio
maxradio = max(radio)
maxradio
## [1] 89
minradio = min(radio)
minradio
## [1] 65
maxradio-minradio
## [1] 24
mean(radio)
## [1] 76.1
sd(radio)
## [1] 7.354912
var(radio)
## [1] 54.09474
An easy way to calculate many of these statistics is with the summary() function. Below is an example.
summary(sales)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 11125 15175 16658 16717 18874 20450
##### 1B) Repeat the above summary calculation for the variable paper. Some statistics are not calculated with the summary() function, Specify which.
paper = mydata$paper
summary(paper)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 35.00 53.75 62.50 62.30 75.50 89.00
It would seem that standard deviation and variance are not calculated with the summary() function. The range is also missing.
Now, we will produce a basic plot of the ‘sales’ variable . Here we call the plot function and within the plot function we refer the variable we want to plot.
plot(sales)
We can customize the plot by connecting the dots and adding labels to the x- and y- axis.
#xlab labels the x axis, ylab labels the y axis
plot(sales, type="b", xlab = "Case Number", ylab = "Sales in $1,000")
There are further ways to customize plots, such as changing the colors of the lines, adding a heading, or even making them interactive.
Now, lets plot the sales graph, alongside radio, paper, and tv which you will code. Make sure to run the code in the same chunk so they are on the same layout.
#Layout allows us to see all 4 graphs on one screen
layout(matrix(1:4,2,2))
#Example of how to plot the sales variable
plot(sales, type="b", xlab = "Case Number", ylab = "Sales in $1,000")
# Add three other plots here
plot(radio, type ="b", xlab ="Case Number")
plot(paper, type ="b", xlab="Case Number")
tv = mydata$tv
plot(tv, type ="b", xlab="Case Number")
##### 2A) Insert in the above chunk the code for the three other plots for Radio, Paper, and TV. Label the axes properly
When looking at these plots it is hard to see a particular trend. One way to observe any possible trend in the sales data would be to re-order the data from low to high. The 20 months case studies are in no particular chronological time sequence. The 20 case numbers are independent sequentially generated numbers used as tags. Since each case is independent, we can reorder them. Note that as each case is re-ordered corresponding column values are also re-organised to maintain the relationship integrity.
#Re-order sales from low to high, and save re-ordered data in a new set. As sales data is re-reorded associated other column fields follow.
newdata = mydata[order(sales),]
head(newdata)
## case_number sales radio paper tv pos
## 1 1 11125 65 89 250 1.3
## 19 19 12369 65 37 250 2.5
## 20 20 13882 68 80 252 1.4
## 5 5 13965 69 75 255 1.5
## 6 6 14999 70 71 255 2.1
## 11 11 15234 70 66 255 1.5
# Redefine the new variables
newsales = newdata$sales
newradio = newdata$radio
newtv = newdata$tv
newpaper = newdata$paper
##### 2B) Repeat the previous 4 graphs layout exercise using instead the above defined four new variables for sales, radio, tv, and paper
layout(matrix(1:4,2,2))
plot(newsales, type="b", xlab = "Case Number", ylab = "New Sales in $1,000")
plot(newradio, type ="b", xlab ="Case Number")
plot(newpaper, type ="b", xlab="Case Number")
plot(newtv, type ="b", xlab="Case Number")
##### 2C) Explain in clear words what the new plots are revealing in terms of trending relationships
It seems that more people are consuming all forms of media at an increased rate, with the exception of newspaper consumption.
You are given a sales value of $25000. We want to calculate the corresponding z-value or z-score for sales using the mean and standard deviation calculations as shown in task 1. Remember that z-score = (x - mean)/sd.
##### 3A) Calculate the z-value. Based on your result, would you rate a $25000 in sales as poor, average, good, or very good performance? Explain your logic
(25000-mean(newsales))/sd(newsales)
## [1] 3.164935