# Load Libriaries
library(tidyverse)
library(knitr)
#### Assign the mean to a variable
m <- 34373
##### Find the standard deviation
sd <- 8691.652189
#### Calculate the size and assign it to a variable
n <- 10
#### Calculate p and assign it to a variable
p <- 0.7
#### Calculate q and assign it to a variable
q <- 0.3
#### 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.7 | 0.3 | 34373 | 2.053749 |
# 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 $ 27780.78 and $ 40965.22 .
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 $ 34373 is between 40.24 % and 99.76 %.