Setup
# Load Libriaries
library(tidyverse)
library(knitr)
# Read data
super <- read.csv("2013Coupes.csv")
dat <- filter(super,Price < 100000)
Identify Variables
#### Calculate and assign mean
m <- mean(dat$Price)
#### Assign sample size
n <- 4
#### Calculate new standard deviation and assign
o <- sd(dat$Price)/sqrt(n)
#### Return results
df <- data.frame(m,n,o)
kable(df)
Problem 1: For the next 4 cars that are sampled, what is the
probability that the price will be less than $500 dollars below the
mean?
# Calculate mean-500 and assign
x <- m-500
# Calculate z
z <- (x-m)/o
# Calculate probability where P(X <= J) = P(X < J)
p <- pnorm(z)
## Interpret results
cat("For the next 4 cars that are sampled, there is a ",round(p*100,digits = 2),"% probability that the price will be less than $500 dollars below the mean." )
## For the next 4 cars that are sampled, there is a 43.59 % probability that the price will be less than $500 dollars below the mean.
Problem 2: For the next 4 cars that are sampled, what is the
probability that the price will be higher than $1000 dollars above the
mean?
# Calculate mean+1000 and assign
x <- m+1000
# Calculate z
z <- (x-m)/o
# Calculate probability where P(X => J) = 1-P(X < J)
p <- 1-pnorm(z)
## Interpret results
cat("For the next 4 cars that are sampled, there is a ",round(p*100,digits = 2),"% probability that the price will be higher than $1000 dollars above the mean.")
## For the next 4 cars that are sampled, there is a 37.34 % probability that the price will be higher than $1000 dollars above the mean.
Problem 3: For the next 4 cars that are sampled, what is the
probability that the price will be equal to the mean?
# Calculate z2, using the methodology as described in Example 7.6 problem 5
z2 <- ((m+.5)-m)/o
# Calculate z1, using the methodology as described in Example 7.6 problem 5
z1 <- ((m-.5)-m)/o
# Calculate probability where P(J < X < K) = P(X < K) - P(X < J)
p <- pnorm(z2)-pnorm(z1)
## Interpret results
cat("For the next 4 cars that are sampled, there is a ",round(p*100,digits = 2),"% probability that the price will be equal to the mean.")
## For the next 4 cars that are sampled, there is a 0.01 % probability that the price will be equal to the mean.
Problem 4: For the next 4 cars that are sampled, what is the
probability that the price will be $1500 within the mean?
# Calculate z2
z2 <- ((m+1500)-m)/o
# Calculate z1
z1 <- ((m-1500)-m)/o
# Calculate probability where P(J < X < K) = P(X < K) - P(X < J)
p <- pnorm(z2)-pnorm(z1)
## Interpret results
cat("For the next 4 cars that are sampled, there is a ",round(p*100,digits = 2),"% probability that the price will be $1500 within the mean.")
## For the next 4 cars that are sampled, there is a 37.19 % probability that the price will be $1500 within the mean.
Conclusion
The results are consistent with expectations. In the first problem,
p= 43.59 % < 50 %, which makes sense since we are looking for the
probability of a price slightly less than the middle In the second
problem, p = 37.34%, which is double the distance from the middle as the
first problem. In the third problem, p is effectively 0 which makes
sense since the chance the price will exactly equal the mean to the cent
is very small. The methodology used here does return a 0.01% chance, but
when I ran it using dnorm(), a function intended to return this figure I
get 0%. In problem 4, p=37.19 %, which represents the probability for a
price within a range of values in the middle of the distribution.
Reference
kable(dat)
| Coupe |
2013 |
Jaguar |
XK |
21807 |
16 |
24 |
385 |
8 |
| Coupe |
2013 |
Chevrolet |
Camero |
27795 |
15 |
24 |
426 |
8 |
| Coupe |
2013 |
Ford |
Mustang |
29145 |
15 |
26 |
420 |
8 |
| Coupe |
2013 |
Mercedes |
E550 |
14403 |
17 |
27 |
402 |
8 |
| Coupe |
2013 |
Audi |
S5 |
17209 |
18 |
28 |
333 |
6 |
| Coupe |
2013 |
BMW |
M3 |
25732 |
14 |
20 |
414 |
8 |
| Coupe |
2013 |
Mini |
Coupe 2D |
13674 |
26 |
35 |
208 |
4 |
| Coupe |
2013 |
Dodge |
Challenger |
13774 |
16 |
25 |
375 |
8 |
| Coupe |
2013 |
Cadillac |
CTS-V |
27742 |
12 |
18 |
556 |
8 |
| Coupe |
2013 |
Nissan |
370Z |
20177 |
19 |
26 |
332 |
6 |