Setup

# Load Libriaries
library(tidyverse)
library(knitr)

Identify Variables

#### Assign the mean to a variable
m <- 37022

##### Find the standard deviation
sd <- 10499.5197

#### Calculate the size and assign it to a variable
n <- 10

#### Calculate p and assign it to a variable
p <- 0.5

#### Calculate q and assign it to a variable
q <- 0.5

#### calculate Z critical value and assign to variable
zcrit <- qnorm(.98)

#### Return results
df <- data.frame(n,p,q,m,zcrit)
kable(df)
n p q m zcrit
10 0.5 0.5 37022 2.053749

T Confidence Interval

# Find the standard error (se)
se <- sd / sqrt(n)
alpha <- 0.04
df <- n - 1
t_score <- qt(alpha/2, df,lower.tail=F)
me <- t_score * se
 
# Calculating lower bound and upper bound
lower_bound <- m - me
upper_bound <- m + me
 
## Return result in a sentence
cat("We are 96% confident that the population mean car price for the type of cars you selected during week 1 is between $", lower_bound,"and $", upper_bound,".")
## We are 96% confident that the population mean car price for the type of cars you selected during week 1 is between $ 29058.6 and $ 44985.4 .

Proportion confidence interval

upper <- p+zcrit*(sqrt(p*q/n))
lower <- p-zcrit*(sqrt(p*q/n))

## Return result in a sentence
cat("We are 96% confident that the population proportion of car prices that are less than $", m, "is between", round(lower*100,digits=2),"% and", round(upper*100,digits = 2),"%.")
## We are 96% confident that the population proportion of car prices that are less than $ 37022 is between 17.53 % and 82.47 %.