Question 1—–“Does computer aided instruction help students learn to drive more quickly”?

# does the new technique perform differently than the traditional method?

#Null = mu = 109 
# Alternatirve = mu =/= 109 

#Two- tailed hypothesis test.

#Syntax: t.test(x, mu, alternative)

#Parameters:
#x: represents numeric vector data

#mu: represents mean against which sample data has to be tested

#alternative: sets the alternative hypothesis

#Wilcox test.

??rnorm
## starting httpd help server ... done
#z = (mean1-mean2)/(sd/sqrt(n))

z <- (109-110)/(6/sqrt(190))

Pvalue <- pnorm(z)

# Defining sample vector
x <- rnorm(190, 109, 6)
y <- rnorm(190, 110, 6)
plot(x)

plot(y)

# Two Sample T-Test
t.test(x, y)
## 
##  Welch Two Sample t-test
## 
## data:  x and y
## t = -2.9107, df = 377.19, p-value = 0.00382
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -2.9503331 -0.5713528
## sample estimates:
## mean of x mean of y 
##  108.3317  110.0925

#—-Questions2—“is the ozone level too low?”

#there is no difference in the ozone. ie) the level of ozone (5.3) is normal.

#there is a difference in the  ozone level. The ozone level is not normal.

#H0 : mu = 5.3
#H1 : mu =/= 5.3 

x <- rnorm(5, 5, 1.1)
y <- rnorm(5.3, 5, 1.1)

t.test(x,y)
## 
##  Welch Two Sample t-test
## 
## data:  x and y
## t = -0.16539, df = 7.0237, p-value = 0.8733
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -1.683784  1.463495
## sample estimates:
## mean of x mean of y 
##  5.321163  5.431307
#question3--------Researcher thinks that the ozone level isnt at a "normal" level.

#H0 = 7.3
#H1 = 7.3

sd <- sqrt(.49)

ozone <- rnorm(51, 7.1, sd)

result = t.test(ozone, mu = 7.3)
result
## 
##  One Sample t-test
## 
## data:  ozone
## t = -3.9401, df = 50, p-value = 0.0002531
## alternative hypothesis: true mean is not equal to 7.3
## 95 percent confidence interval:
##  6.817632 7.143372
## sample estimates:
## mean of x 
##  6.980502
#ozone levels are abnormal, P-value is 0.037

#question4—– “claim is that 36% own a laptop. a random sample found 29/100 owned a laptop. is there evidence to support the claim at the .02 sig level?

#H0: = 36
#H1 =/=36

prop.test(x=29, n=100, p=0.36, alternative="two.sided",conf.level = 0.98, correct = TRUE)
## 
##  1-sample proportions test with continuity correction
## 
## data:  29 out of 100, null probability 0.36
## X-squared = 1.8338, df = 1, p-value = 0.1757
## alternative hypothesis: true p is not equal to 0.36
## 98 percent confidence interval:
##  0.1931609 0.4093915
## sample estimates:
##    p 
## 0.29

#Question———-5————-“the claim is that 31% of patients are uninsured” the director wants to test the claim that it is less than expected

#claim is that 31% of patients are uninsured.

prop.test(x=.25, n=380, p=0.31, alternative="two.sided",conf.level = 0.95, correct = TRUE)
## 
##  1-sample proportions test with continuity correction
## 
## data:  0.25 out of 380, null probability 0.31
## X-squared = 168.56, df = 1, p-value < 2.2e-16
## alternative hypothesis: true p is not equal to 0.31
## 95 percent confidence interval:
##  0.00000000 0.01363292
## sample estimates:
##            p 
## 0.0006578947

#Question—-6—–What is the min sample size needed to to 99% confident that the sample’s variance is within 1% of the population’s variance?

#Critical value for 99% Ci is 2.576

#formula for n is. n = 2.576*(sd/Me)^2

#Answer--133449

#Question 7 ——– Compare means and standard deviation of test scores

#Solve using "Chi-squared"


#H0: = 24
#H1: < 24

#find t critical value
qt(p=.1, df=23, lower.tail=TRUE)
## [1] -1.31946
#if the test statistic is less than this value, the results of the test are statistically significant.

#formula for test statistics is 

#x^2 = (n-1)sd^2/o^2

sd2 <-- 15.4387^2

varsquared <- 24^2

xsquared <- (22-1)*sd2

criticalvalue <- xsquared/varsquared

criticalvalue
## [1] -8.68997
#We can reject H0 because the critical value lies in the critical region of "<-1.31964"

#there is evidence that the standard deviation of test scores has decreased.

#Question 8 —–Smokers and non-smokers, non-paired test. Medical researcher wants to compare the pulse rates of smokers and non-smokers, he blieves that he pulse rate for smokers and non-smokers is diffferernt and wants to test this claim at the .1 level. The researcher checks 32 smokers and finds that they have a mean pulse of 87**, and 31 non-smokers have a mean pulse of 84. The Sd of the pulse is 9 for smokers and 10 for non-smokers. Let my be the true mean puslse rate for smokers and mu2 bew the true mean pulse rate for non-smokers

#solve using ttest-non-paired 


#H0: there is no significant difference in pulse rates
#H1: there is a significant difference in pulse rates

#critical value for a sig level of .1 is zc=1.64


#Sample means. 

x1 <- 87
x2 <- 84

#population Sd 

sd1 <- 9
sd2 <-10

#sample sizes

n1 <- 32
n2 <- 31



# find z-scores 
z <- (87-84)/(9/sqrt(32))

Pvalue <- pnorm(z)
Pvalue
## [1] 0.9703268
# Defining sample vector
x <- rnorm(190, 109, 6)
y <- rnorm(190, 110, 6)


t.test(x,y)
## 
##  Welch Two Sample t-test
## 
## data:  x and y
## t = -1.6894, df = 371.83, p-value = 0.09199
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -2.1966712  0.1664417
## sample estimates:
## mean of x mean of y 
##  108.4301  109.4452
#H0: mu1 = mu2
#H1: mu1 =/= mu2

#sig level is .1

#the null hypotheis is not rejected, because the z scores are below the level of significance.
#there is not sufficient evidence to support the claim that the mean pulse rate for smokers and nonsmokers is different.

#—question9 —— Use the given data to calculate the true difference between the populaiton means. Assume that the population variances are not equial and that the two populations are normally distrubted.

n <- 11
xbar <- 127
s1 <- 33 


n2 <- 18
xbar2 <- 157 
s2 <- 27

# use this data for find the 95% CI for the true difference between the population means.


# Paired sample t-test
 
# Taking two numeric vectors
One <- rnorm(11, mean = 127, sd = 33)
Two <- rnorm(18, mean = 157, sd = 27)
 
# Using t.tset()
result = t.test(One, Two,
                var.equal = TRUE)
 
# Print the result
print(result)
## 
##  Two Sample t-test
## 
## data:  One and Two
## t = -2.1544, df = 27, p-value = 0.0403
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -38.6204041  -0.9414897
## sample estimates:
## mean of x mean of y 
##  130.7768  150.5578
#difference in true population mean
difference <- 153.5438-119.0464
difference
## [1] 34.4974

#Question 10 —- Two men commute to work and conduct an experiment– Paired confidence interval

# Paired sample t-test
 
set.seed(0)
 
# Taking two numeric vectors
shopOne <- rnorm(50, mean = 140, sd = 4.5)
shopTwo <- rnorm(50, mean = 150, sd = 4)
 
# Using t.tset()
result = t.test(shopOne, shopTwo,
                var.equal = TRUE)
 
# Print the result
print(result)
## 
##  Two Sample t-test
## 
## data:  shopOne and shopTwo
## t = -13.158, df = 98, p-value < 2.2e-16
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -11.482807  -8.473061
## sample estimates:
## mean of x mean of y 
##  140.1077  150.0856

#—Qesution 11——– Unemployment and voting

#Below are the null and alternative Hypothesis,
#Null Hypothesis, H0: p1 = p2
#Alternate Hypothesis, Ha: p1 > p2

p1cap <-  195/433 
p2cap <-  193/555 


pcap <- (195+193)/(391+510)


#Test statistic
#z = (p1cap - p2cap)/sqrt(pcap * (1-pcap) * (1/N1 + 1/N2))




#This is right tailed test, for α = 0.01
#Critical value of z is 2.33.
#Hence reject H0 if z > 2.33