Q1

#Stating X1, X2 and Standard deviation

mtrad<-109
mcai<-110
n<-190
SD<-6

df<-n-1
SE<-SD/(sqrt(n))


#Calculate tdf
alpha<-.05
tdf<-qt(p=alpha/2, df, lower.tail=FALSE)

upper<- mcai + (tdf*SE)
lower<- mcai - (tdf*SE)
upper
## [1] 110.8586
lower
## [1] 109.1414

Q2

orig<-5.3
test<-5
n<-5
SD<-1.1 #sd of the sample population, shown usually as s (sd is usually sigma)

df<-n-1
SE<-SD/(sqrt(n))

alpha<-.05
tdf<-qt(p=alpha/2, df, lower.tail=FALSE)

upper<- test + (tdf*SE)
lower<- test - (tdf*SE)
upper
## [1] 6.36583
lower
## [1] 3.63417

Q3

orig<-7.3
test<-7.1
n<-51
SD<-0.49 #sd of the sample population, shown usually as s (sd is usually sigma)
df<-n-1
SE<-SD/(sqrt(n))

alpha<-.01
tdf<-qt(p=.005, df, lower.tail=FALSE)

upper<- test + (tdf*SE)
lower<- test - (tdf*SE)
upper
## [1] 7.283733
lower
## [1] 6.916267
#With a 99% confidence interval, the level of ozone normally found is between 6.916267 and 7.283733 ppm. 
#Because 7.3 is outside of that interval, we can reject the null hypothesis and assume that the data supports the researcher's claim.

Q4

orig<-.36
test<-.29
n<-100
df<-n-1
#we don't have sd, so calculating SE and using Z value
SE<-sqrt((orig*(1-orig))/n)

#Calculating Z

Z<-qnorm(1-.02/2) 

upper<-test+Z*SE
lower<-test-Z*SE
upper 
## [1] 0.4016647
lower
## [1] 0.1783353
#With a 98% confidence interval, the percent of readers that own a laptop is between 17.83353 and 40.16647 percent. 
#Because 36 is equal to or less than the upper bound, we cannot reject the null hypothesis. The data does not support the claim.

Q5

orig<-.31
test<-.95
n<-380
df<-n-1
SE<-sqrt((orig*(1-orig))/n)

#Calculating Z

Z<-qnorm(1-.05/2)

upper<-test+Z*SE
lower<-test-Z*SE
upper
## [1] 0.9965009
lower
## [1] 0.9034991
#With a 98% confidence interval, the percent of uninsured patients is between 90.34991 and 99.65009 percent. 
#Because 31 is equal to or less than the upper bound, we cannot reject the null hypothesis. The data does not support the claim

Q6

Z<-qnorm(1-.01/2)

MOE<-.01 #margin of error
SD<- 1 #assuming standard deviation is 1

n<-((Z*SD)/MOE)^2
round(n,0)
## [1] 66349

Q7

orig<-112
SD1<-24
test<-102
SD2<-15.4387
n<-22 #assuming n1 and n2 are the same
meandiff<-orig - test
SE<-sqrt((SD1^2/n)+(SD2^2/n))
df<-n-1

alpha<-.1
tdf<-qt(p=alpha/2, df, lower.tail=FALSE)

upper<- SD2 + (tdf*SE)
lower<- SD2 - (tdf*SE)
upper
## [1] 25.90784
lower
## [1] 4.969557
#With a 99% confidence interval, the standard deviation is between 4.969557 and 25.90784 
#Because 24 is within that interval, we cannot reject the null hypothesis that SD has not decreased below 24.

Q8

mean.smoke<-87
sd.smoke<-8
mean.non<-84
sd.non<-10
n.smoke<-32
n.non<-31

#Calculating the difference between the means (point estimate), standard error, and degrees(in this case, the smaller population)

meandiff<-mean.smoke - mean.non
SE<-sqrt((sd.smoke^2/n.smoke)+(sd.non^2/n.non))
df<-n.non-1

Tstat<-meandiff/SE
tdf<-qt(p=.05, df, lower.tail=FALSE)

#Calculate p-value with T score and df

pvalue<-2*pt(Tstat, df, lower.tail = FALSE)
pvalue
## [1] 0.1993598
#The pvalue is  0.199 which is greater than 0.1. Therefore, With a 99% confidence interval, 
#We cannot reject the null hypothesis that the pulse rates are the same between smokers and non-smokers.

Q9

n1<-11
x1<-127
s1<-33
n2<-18
x2<-157
s2<-27

meandiff<-x1-x2
SE<-sqrt((s1^2/n1)+(s2^2/n2))
df<-n1-1

Tstat<-meandiff/SE
tdf<-qt(p=.025, df, lower.tail=FALSE)

upper<- meandiff + (tdf*SE)
lower<- meandiff - (tdf*SE)
cat("(",lower,",",upper,")")
## ( -56.31657 , -3.683426 )

Q10

route1<-c(32,27,34,24,31,25,30,23,27,35)
route2<-c(28,28,33,25,26,29,33,27,25,33)

x1<-mean(route1)
n1<-10
s1<-sd(route1)
x2<-mean(route2)
n2<-10
s2<-sd(route2)

#Calculating the difference between the means (point estimate), standard error, and degrees of freedom (in this case, the smaller population)

meandiff<-x1-x2
SE<-sqrt((s1^2/n1)+(s2^2/n2))
df<-n1-1

#Calculate T score and t value based on the degrees of freedom

Tstat<-meandiff/SE
tdf<-qt(p=.01, df, lower.tail=FALSE)


upper<- meandiff + (tdf*SE)
lower<- meandiff - (tdf*SE)
cat("(",lower,",",upper,")")
## ( -4.637066 , 4.837066 )