myp=function(p, alpha){
if(p<alpha){print('REJECT Ho')}else{print('FAIL 2 REJECT')}
}
Ho (mu = 109): Mean number of hours to obtain the driving license with the CAI is equal to the mean number of hours to obtain the driving license with traditional method (109).
Ha (mu != 109): Mean number of hours to obtain the driving license with the CAI is NOT equal to the mean number of hours to obtain the driving license with traditional method (109).
Two sided test (look at alternative hypothesis).
# Define Variables
n <- 190 # Sample population
m <- 109 # Population Mean
xbar <- 110 # Sample mean
sigma <- 6 # Standard deviation of population
se <- sigma/sqrt(n) # Standard deviation of sample (standard error)
alpha <- 0.05 # Level of significance
# P()
z <- (xbar - m)/(se)
p <- round(2*(1 - pnorm(z)),4)
cat("The probability is",round(p,4), ".\n")
## The probability is 0.0216 .
myp(p,alpha)
## [1] "REJECT Ho"
Ho: Mean ppm of ozone is equal to 5.3 ppm.
Ha: Mean ppm of ozone is less than 5.3 ppm.
One-sided test
# Define Variables
n <- 5 # Sample population
m <- 5.3 # Population Mean
xbar <- 5.0 # Sample mean
sigma <- 1.1 # Standard deviation of population
se <- sigma/sqrt(n) # Standard deviation of sample (standard error)
alpha <- 0.05 # Level of significance
# P()
z <- (xbar - m)/(se)
p <- pt(z,df=n-1,lower.tail=TRUE)
cat("The probability is",round(p,4), ".\n")
## The probability is 0.2875 .
myp(p,alpha)
## [1] "FAIL 2 REJECT"
Ho: Mean ppm of ozone is equal to 7.3 ppm.
Ha: Mean ppm of ozone is less than 7.3 ppm.
One-sided test
# Define Variables
n <- 51 # Sample population
m <- 7.3 # Population Mean
xbar <- 7.1 # Sample mean
var <- 0.49 # Variance of population
sigma <- sqrt(var) # Standard deviation of population
se <- sigma/sqrt(n) # Standard deviation of sample (standard error)
alpha <- 0.01 # Level of significance
# P()
z <- (xbar - m)/(se)
p <- pnorm(q=z)
cat("The probability is",round(p,4), ".\n")
## The probability is 0.0207 .
myp(p,alpha)
## [1] "FAIL 2 REJECT"
Ho: Readers who own a laptop is equal to 36%
Ha: Readers who own a laptop is less than 36%
No Standard Deviation = T Distribution
# Define Variables
n <- 100 # Sample population
pop <- 0.36
sam <- 0.29
alpha <- 0.02 # Level of significance
se <- sqrt((pop*(1-pop))/n)
t <- (sam - pop) / sqrt(pop * (1 - pop) / n)
p <- pt(t, df = n - 1, lower.tail = TRUE)
cat("The probability is",round(p,4), ".\n")
## The probability is 0.074 .
myp(p,alpha)
## [1] "FAIL 2 REJECT"
Ho: Uninsured patients is equal to 31%
Ha: Readers who own a laptop is less than 31%
# Define Variables
n <- 380 # Sample population
pop <- 0.31
sam <- 95/n
alpha <- 0.05 # Level of significance
se <- sqrt((pop*(1-pop))/n)
z <- (sam - pop) / se
p <- pnorm(z, lower.tail = TRUE)
cat("The probability is",round(p,4), ".\n")
## The probability is 0.0057 .
myp(p,alpha)
## [1] "REJECT Ho"
Ho: The standard deviation of tests is equal to 24.
Ha: The standard deviation of tests is less than 24.
# Define Variables
m <- 112 # Population mean
sigma <- 24 # Population standard deviation
n <- 22 # Sample size
xbar <- 102 # Sample mean
se <- 15.4387 # Sample standard deviation
alpha <- 0.1 # Level of significance
df <- n - 1 # Degrees of freedom
t <- (n - 1) * se^2 / sigma^2
p <- pt(t, df, lower.tail = TRUE)
cat("The probability is",round(p,4), ".\n")
## The probability is 1 .
myp(p,alpha)
## [1] "FAIL 2 REJECT"
Ho: The pulse rate for smokers and non-smokers is not equal.
Ha: The pulse rate for smokers and non-smokers is equal.
T-Distribution? Donβt know sd of pop and sample is small.
# Define Variables
nsmoke <- 32 # Sample num smokers
msmoke <- 87 # Sample mean smokers
sdsmoke <- 9 # Sample standard deviation smokers
nnon <- 31 # Sample num nonsmokers
mnon <- 84 # Sample mean nonsmokers
sdnon <- 10 # Sample standard deviation nonsmokers
n <- nsmoke + nnon # Total Sample
alpha <- 0.1 # Level of significance
df <- nnon - 1 # Degrees of freedom
mdiff <- msmoke - mnon
varsmoke <- sdsmoke^2
varnon <- sdnon^2
se <- sqrt((varsmoke/nsmoke)+(varnon/nnon))
t <- mdiff/se
p <- 2*pt(t, df, lower.tail = FALSE)
cat("The probability is",round(p,4), ".\n")
## The probability is 0.2208 .
myp(p,alpha)
## [1] "FAIL 2 REJECT"
# Define Variables
n1 <- 11
xbar1 <- 127
sigma1 <- 33
n2 <- 18
xbar2 <- 157
sigma2 <- 27
alpha <- 0.05
var1 <- sigma1^2
var2 <- sigma2^2
df <- min(n1-1,n2-1)
mdiff <- xbar1 - xbar2
se <- sqrt((var1/n1)+(var2/n2))
tstat <- mdiff/se
t <- qt(0.025, df, lower.tail = FALSE)
margin_error <- t * se
l <- mdiff - margin_error
u <- mdiff + margin_error
cat("95% Confidence interval:", round(l, 4), ",", round(u, 4))
## 95% Confidence interval: -56.3166 , -3.6834
# Create data sets for each route
route1 <- c(32, 27, 34, 24, 31, 25, 30, 23, 27, 35)
route2 <- c(28, 28, 33, 25, 26, 29, 33, 27, 25, 33)
# Define Variables
n1 <- 10
xbar1 <- mean(route1)
s1 <- sd(route1)
var1 <- s1^2
n2 <- 10
xbar2 <- mean(route2)
s2 <- sd(route2)
var2 <- s2^2
df <- n1-1
mdiff <- xbar1 - xbar2
se <- sqrt((var1/n1)+(var2/n2))
t <- mdiff/se
tdf <- qt(p=.01, df, lower.tail=FALSE)
u <- mdiff + (tdf*se)
l <- mdiff - (tdf*se)
cat("(Lower: ",l,", Upper:",u,")")
## (Lower: -4.637066 , Upper: 4.837066 )
Ho: The percentage of employed workers registered to vote is less than percentage of unemployed workers registered to vote.
Ha: The percentage of employed workers registered to vote is greater than or equal to the percentage of unemployed workers registered to vote.
# Define variables
n1 <- 391
xbar1 <- 195
s1 <- 1
var1 <- s1^2
n2 <- 510
xbar2 <- 193
s2 <- 1
var2 <- s2^2
df <- min(n1-1,n2-1)
alpha <- 0.05
mdiff <- xbar1 - xbar2
se <- sqrt((var1/n1)+(var2/n2))
t <- mdiff/se
tdf<-qt(p=.025, df, lower.tail=FALSE)
u<- mdiff + (tdf*se)
l<- mdiff - (tdf*se)
cat("(Lower: ",l,", Upper:",u,")")
## (Lower: 1.867844 , Upper: 2.132156 )
p<-2*pt(t, df, lower.tail = FALSE)
cat("The probability is",p, ".\n")
## The probability is 2.234708e-102 .
myp(p,alpha)
## [1] "REJECT Ho"