Setup
# Load Libriaries
library(tidyverse)
library(knitr)
# Read data
super <- read.csv("2013Coupes.csv")
data <- filter(super,Price < 100000)
Identify Variables
#### Assign the mean to a variable
m <- mean(data$Price)
##### Find the standard deviation
sd <- sd(data$Price)
#### Create dataframe of values below the mean
ltm <- filter(data,data$Price < m)
#### Calculate the size and assign it to a variable
n <- length(data$Price)
#### Calculate p and assign it to a variable
p <- length(ltm$Price)/n
#### Calculate q and assign it to a variable
q <- 1-p
#### calculate Z critical value and assign to variable
zcrit <- qnorm(.975)
#### Return results
df <- data.frame(n,p,q,zcrit)
kable(df)
T Confidence Interval
# Find the standard error (se)
se <- sd / sqrt(n)
alpha <- 0.05
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 95% confident that the population mean car price for the type of cars I selected during week 1 is between $", lower_bound,"and $", upper_bound,".")
## We are 95% confident that the population mean car price for the type of cars I selected during week 1 is between $ 16715.12 and $ 25576.48 .
Proportion confidence interval
ltm_upper <- p+zcrit*(sqrt(p*q/n))
ltm_lower <- p-zcrit*(sqrt(p*q/n))
## Return result in a sentence
cat("We are 95% confident that the population proportion of car prices that are less than $", m, "is between", round(ltm_lower*100,digits=2),"% and", round(ltm_upper*100,digits = 2),"%.")
## We are 95% confident that the population proportion of car prices that are less than $ 21145.8 is between 19.01 % and 80.99 %.