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 computational techniques. It aims to quantify an event with metrics and numbers.
In this project, we will explore quantitative analytics using the babies data set provided. This data is collected to understand different factors effecting baby weights at birth. Below are the explanations of the variables:
Bwt: Baby weights in ounces Gestation: Length of pregnancy in days Height: Mother’s height in inches Smoke: =1 if mother is smoker, = 0 Nonsmoker Age: Mother’s age in years Weight: Mother’s pregnancy weight Parity: = 0 if the baby is first born, =1 otherwise babies: number of babies before this birth
Read this worksheet carefully and follow the instructions to complete the tasks and answer any questions. Submit your work as an HTML or PDF or Word document to Sakai. If you are submitting as a team project only one submission from one of the team members will be sufficient but in this case you need to input the names of the team members in the above Title section.
babies_old data set will be used to check if it contains any missing data. First read the babies_old file and make sure you correctly read the file with the above mentioned variables.
#Read babies_old file and check the variables
library(readr)
babies_old <-read_csv("downloads/babies_old.csv")
## Rows: 1174 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (8): Count, bwt, gestation, parity, height, weight, smoke, age
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
View(babies_old)
dim(babies_old)
## [1] 1174 8
head(babies_old)
## # A tibble: 6 × 8
## Count bwt gestation parity height weight smoke age
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1 120 284 0 62 100 0 27
## 2 2 113 282 0 64 NA 0 33
## 3 3 128 279 0 64 115 1 28
## 4 4 108 282 0 67 125 1 23
## 5 5 136 286 0 62 93 0 25
## 6 6 138 244 0 62 178 0 33
#Check your file for missing data
which(is.na.data.frame(babies_old))
## [1] 5872 5883 5923 5961 6106 6336 6419 6585 6741 6943 7025
which(is.na(babies_old$bwt))
## integer(0)
which(is.na(babies_old$gestation))
## integer(0)
which(is.na(babies_old$parity))
## integer(0)
which(is.na(babies_old$height))
## integer(0)
which(is.na(babies_old$weight))
## [1] 2 13 53 91 236 466 549 715 871 1073 1155
which(is.na(babies_old$smoke))
## integer(0)
which(is.na(babies_old$age))
## integer(0)
#implement omission strategy and check if all the observations with NA's were omitted.
omissionbabies <- na.omit(babies_old)
dim(omissionbabies)
## [1] 1163 8
#Implement imputation strategy
weightmean = mean(babies_old$weight, na.rm = TRUE)
weightmean
## [1] 128.4996
First, read the babies.csv file and calculate the mean, standard deviation, maximum, and minimum for the bwt column using R.
#Read babies file
library(readr)
babies <-read_csv("downloads/babies.csv")
## Rows: 1174 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (8): Count, bwt, gestation, parity, height, weight, smoke, age
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
View(babies)
dim(babies)
## [1] 1174 8
head(babies)
## # A tibble: 6 × 8
## Count bwt gestation parity height weight smoke age
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1 120 284 0 62 100 0 27
## 2 2 113 282 0 64 135 0 33
## 3 3 128 279 0 64 115 1 28
## 4 4 108 282 0 67 125 1 23
## 5 5 136 286 0 62 93 0 25
## 6 6 138 244 0 62 178 0 33
#Calculate and display the average, standard deviation, maximum and minimum babies weight.
maxweight = max(babies$bwt)
minweight = min(babies$bwt)
meanweight = mean(babies$bwt)
standarddevweight = sd(babies$bwt)
maxweight
## [1] 176
minweight
## [1] 55
meanweight
## [1] 119.4625
standarddevweight
## [1] 18.32867
Use the formula from class to detect any outliers. An outlier is value that “lies outside” most of the other values in a set of data.
#calculate the upper and lower thresholds
UpperOutlier = (mean(babies$bwt)) + 3*(sd(babies$bwt))
UpperOutlier
## [1] 174.4485
LowerOutlier = (mean(babies$bwt))-3*(sd(babies$bwt))
LowerOutlier
## [1] 64.47651
Do you think there are possible outliers? Why?
If you decided that you have possible outliers can you identify the observations with possible outliers?
#Observations with possible outliers at the upper end
UpperBound = quantile (babies$bwt, 0.975)
UpperBound
## 97.5%
## 155
#observations with possible outliers at the lower end
LowerBound = quantile (babies$bwt, 0.025)
LowerBound
## 2.5%
## 81
What is the number of outliers at the lower end and upper end of the data?
Another similar method to find the upper and lower thresholds discussed in class involves finding the interquartile range. Find the interquantile range using the following chunk.
#Find the inter quantile range
quantile(babies_old$bwt)
## 0% 25% 50% 75% 100%
## 55 108 120 131 176
lowerq = quantile(babies_old$bwt)[2]
upperq = quantile(babies_old$bwt)[4]
iqr= upperq - lowerq
iqr
## 75%
## 23
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 is a possible outlier.
#calculate the upper threshold
upperthreshold = upperq + (iqr*1.5)
upperthreshold
## 75%
## 165.5
#calculate the lower threshold
lowerthreshold = lowerq - (iqr*1.5)
lowerthreshold
## 25%
## 73.5
Do you think there are possible outliers and why?
If you think there are possible outliers can you identify them? If so how many?
Yes, 21 Outliers
It can also be useful to visualize the data using a box plot.
boxplot(babies$bwt)
Can you identify the outliers from the boxplot? If so how many? yes, 21
Given a birth weight of 182, calculate the corresponding z-value or z-score.
# Calculate the z-value and display it
weight = babies$bwt
(182-mean(babies_old$bwt))/sd(babies_old$bwt)
## [1] 3.412003
Based on the z-value, how would you evaluate the weight of this baby. Explain your logic.
How can you describe the relationship between baby weights and other variables?
#correlation between baby weight and other variables
smoke=cor(babies$bwt,babies$smoke)
smoke
## [1] -0.2467995
age=cor(babies$bwt,babies$age)
age
## [1] 0.02698291
weight=cor(babies$bwt,babies$weight)
weight
## [1] 0.1559233
height=cor(babies$bwt,babies$height)
height
## [1] 0.2037042
parity=cor(babies$bwt,babies$parity)
parity
## [1] -0.04390817
gestation=cor(babies$bwt,babies$gestation)
gestation
## [1] 0.4075428
count=cor(babies$bwt,babies$Count)
count
## [1] -0.06449913
Your comments on these relationships: