Setup

# Load Libriaries
library(tidyverse)
library(knitr)

# Read data
super <- read.csv("2013Coupes.csv")
dat <- filter(super,Price < 100000)

Identify Variables

#### Assign the mean to a variable
m <- mean(dat$Price)

#### Create dataframe of values below the mean
ltm <- filter(dat,dat$Price < m)

#### Calculate the size and assign it to a variable
s <- length(dat$Price)

#### Calculate p and assign it to a variable
p <- length(ltm$Price)/s

#### Calculate q and assign it to a variable
q <- 1-p

#### Return results
df <- data.frame(s,p,q)
kable(df)
s p q
10 0.5 0.5

Problem 1: If you were to find another random sample of 10 cars based on the same data, what is the probability that exactly 4 of them will fall below the average? .

# Note: dbinom(x,size,prob) returns P(X=x)

## Calculate probability as decimal
p1 <- dbinom(4,s,p)

## Interpret results
cat("There is a",round(p1*100,digits = 2),"% probability that exactly 5 cars will fall below average.")
## There is a 20.51 % probability that exactly 5 cars will fall below average.

Problem 2: If you were to find another random sample of 10 cars based on the same data, what is the probability that fewer than 5 of them will fall below the average?

# Note: pbinom(x,size,prob) returns P(X <= x)
# Note: P(X < x) = P(X <= x -1)

## Calculate probability as decimal
p2 <- pbinom(5-1,s,p)

## Interpret results
cat("There is a",round(p2*100,digits = 2),"% probability that fewer than 5 of the cars will fall below average.")
## There is a 37.7 % probability that fewer than 5 of the cars will fall below average.

Problem 3: If you were to find another random sample of 10 cars based on the same data, what is the probability that more than 6 of them will fall below the average?

# Note: pbinom(x,size,prob) returns P(X <= x)
# Note: P(X > x) = 1- P(X <= x)

## Calculate probability as decimal
p3 <- 1 - pbinom(6,s,p)

## Interpret results
cat("There is a",round(p3*100,digits = 2),"% probability more than 6 of the cars will fall below average.")
## There is a 17.19 % probability more than 6 of the cars will fall below average.

Problem 4: If you were to find another random sample of 10 cars based on the same data, what is the probability that at least 4 of them will fall below the average?

# Note: pbinom(x,size,prob) returns P(X <= x)
# Note: P(X => x) = 1 - P(X <= x-1)

## Calculate probability as decimal
p4 <- 1 - pbinom(4-1,s,p)

cat("There is a",round(p4*100,digits = 2),"% probability that at least 4 of the cars will fall below average.")
## There is a 82.81 % probability that at least 4 of the cars will fall below average.

Reference

kable(dat)
Vehicle.Type Year Make Model Price MPG..city. MPG..highway. Horsepower Cylinders
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