# Initializing the variables
mu_T <- 109 # mean hours for traditional method
mu_C <- 110 # sample mean for CAI method
sigma <- 6 # known standard deviation
n <- 190 # number of students
z <- (mu_C - mu_T) / (sigma / sqrt(n))
p_value <- 2 * (1 - pnorm(abs(z)))
if (p_value < 0.05) {# Assumed alpha 0.05
decision <- "Reject the null hypothesis"
}else{
decision <- "Fail to reject the null hypothesis"
}
cat("Test Statistic (z):", z, "\n")
## Test Statistic (z): 2.297341
cat("P-value:", p_value, "\n")
## P-value: 0.0215993
cat("Decision:", decision, "\n")
## Decision: Reject the null hypothesis
# Initializing the variables
mu_population <- 5.3 # mean ozone level in the population
sample_mean <- 5.0 # sample mean
sample_sd <- 1.1 # sample standard deviation
sample_size <- 5 # number of samples
alpha <- 0.05 # significance level
Null hypothesis: mu = 5.3 ppm Alternative hypothesis: mu < 5.3 ppm
cat("Scenario 1 (One-sided test)\n")
## Scenario 1 (One-sided test)
cat("Test Statistic (z):", (sample_mean - mu_population) / (sample_sd / sqrt(sample_size)), "\n")
## Test Statistic (z): -0.6098367
cat("P-value:", pnorm((sample_mean - mu_population) / (sample_sd / sqrt(sample_size))), "\n")
## P-value: 0.270985
cat("Decision:", ifelse(pnorm((sample_mean - mu_population) / (sample_sd / sqrt(sample_size))) < alpha, "Reject the null hypothesis", "Fail to reject the null hypothesis"), "\n\n")
## Decision: Fail to reject the null hypothesis
Null hypothesis: mu = 5.3 ppm Alternative hypothesis: mu != 5.3 ppm
cat("Scenario 2 (Two-sided test)\n")
## Scenario 2 (Two-sided test)
cat("Test Statistic (z):", (sample_mean - mu_population) / (sample_sd / sqrt(sample_size)), "\n")
## Test Statistic (z): -0.6098367
cat("P-value:", 2 * (1 - pnorm(abs((sample_mean - mu_population) / (sample_sd / sqrt(sample_size))))), "\n")
## P-value: 0.54197
cat("Decision:", ifelse(2 * (1 - pnorm(abs((sample_mean - mu_population) / (sample_sd / sqrt(sample_size))))) < alpha, "Reject the null hypothesis", "Fail to reject the null hypothesis"), "\n")
## Decision: Fail to reject the null hypothesis
# Initializing the variables
mu_population <- 7.3 # population mean ozone level
sample_mean <- 7.1 # sample mean
sample_variance <- 0.49 # sample variance
sample_size <- 51 # number of samples
alpha <- 0.01 # significance level
Calculate the standard error
standard_error <- sqrt(sample_variance / sample_size)
Calculate the t-value
t_value <- (sample_mean - mu_population) / standard_error
# Calculate degrees of freedom
df <- sample_size - 1
# Find critical t-values for a two-tailed test
critical_t_values <- qt(c(alpha / 2, 1 - alpha / 2), df)
cat("Test Statistic (t):", t_value, "\n")
## Test Statistic (t): -2.040408
cat("Critical T-values:", critical_t_values, "\n")
## Critical T-values: -2.677793 2.677793
cat("Decision:", ifelse(abs(t_value) > critical_t_values[2] | abs(t_value) < critical_t_values[1], "Reject the null hypothesis", "Fail to reject the null hypothesis"), "\n")
## Decision: Fail to reject the null hypothesis
# Initializing the variables
p_population <- 0.36 # population proportion
p_sample <- 0.29 # sample proportion
n <- 100 # sample size
alpha <- 0.02 # significance level
standard_error <- sqrt((p_population * (1 - p_population)) / n)
# Find critical z-value for a one-tailed test
cat("Test Statistic (z):",(p_sample - p_population) / standard_error, "\n")
## Test Statistic (z): -1.458333
cat("Critical Z-value:", qnorm(alpha, lower.tail = TRUE), "\n")
## Critical Z-value: -2.053749
cat("Decision:", ifelse((p_sample - p_population) / standard_error < qnorm(alpha, lower.tail = TRUE), "Reject the null hypothesis", "Fail to reject the null hypothesis"), "\n")
## Decision: Fail to reject the null hypothesis
# Initializing the variables
p_population <- 0.31 # population proportion
p_sample <- 95 / 380 # sample proportion
n <- 380 # sample size
alpha <- 0.05 # significance level
# Calculate the standard error
standard_error <- sqrt((p_population * (1 - p_population)) / n)
# Display the results
cat("Test Statistic (z):", (p_sample - p_population) / standard_error, "\n")
## Test Statistic (z): -2.528935
cat("Critical Z-value:", qnorm(alpha, lower.tail = TRUE), "\n")
## Critical Z-value: -1.644854
cat("Decision:", ifelse((p_sample - p_population) / standard_error< qnorm(alpha, lower.tail = TRUE), "Reject the null hypothesis", "Fail to reject the null hypothesis"), "\n")
## Decision: Reject the null hypothesis
# Initializing the variables
historical_mean <- 112
historical_sd <- 24
sample_mean <- 102
sample_sd <- 15.4387
sample_size <- 22
alpha <- 0.1
# Display the results
cat("Chi-square Statistic:", ((sample_size - 1) * sample_sd^2) / historical_sd^2, "\n")
## Chi-square Statistic: 8.68997
cat("Critical Chi-square Value:", qchisq(1 - alpha, sample_size - 1), "\n")
## Critical Chi-square Value: 29.61509
cat("Decision:", ifelse(((sample_size - 1) * sample_sd^2) / historical_sd^2 < qchisq(1 - alpha, sample_size - 1), "Reject the null hypothesis", "Fail to reject the null hypothesis"), "\n")
## Decision: Reject the null hypothesis
# Initializing the variables
x1_bar <- 87
x2_bar <- 84
s1 <- 9
s2 <- 10
n1 <- 32
n2 <- 31
alpha <- 0.1
# Calculate the pooled standard error
se_pooled <- sqrt(((n1 - 1) * s1^2 + (n2 - 1) * s2^2) / (n1 + n2 - 2) * (1/n1 + 1/n2))
# Calculate the t-value
t_value <- (x1_bar - x2_bar) / se_pooled
# Two-tailed test, so find critical t-values
critical_t_values <- qt(c(alpha / 2, 1 - alpha / 2),((s1^2 / n1) + (s2^2 / n2))^2 / (((s1^2 / n1)^2 / (n1 - 1)) + ((s2^2 / n2)^2 / (n2 - 1))))
cat("Degrees of Freedom (Satterthwaite):", ((s1^2 / n1) + (s2^2 / n2))^2 / (((s1^2 / n1)^2 / (n1 - 1)) + ((s2^2 / n2)^2 / (n2 - 1))), "\n")
## Degrees of Freedom (Satterthwaite): 59.87528
cat("Degrees of Freedom (Conservative Approximation):", min(n1 - 1, n2 - 1), "\n")
## Degrees of Freedom (Conservative Approximation): 30
cat("Test Statistic (t):", t_value, "\n")
## Test Statistic (t): 1.252439
cat("Critical T-values:", critical_t_values, "\n")
## Critical T-values: -1.670703 1.670703
cat("Decision:", ifelse(t_value < critical_t_values[1] | t_value > critical_t_values[2], "Reject the null hypothesis", "Fail to reject the null hypothesis"), "\n")
## Decision: Fail to reject the null hypothesis
# Initializing the variables
n1 <- 11
xbar1 <- 127
s1 <- 33
n2 <- 18
xbar2 <- 157
s2 <- 27
alpha <- 0.05 # 95% confidence interval
# Calculate degrees of freedom using Satterthwaite formula
df_satterthwaite <- ((s1^2 / n1) + (s2^2 / n2))^2 / (((s1^2 / n1)^2 / (n1 - 1)) + ((s2^2 / n2)^2 / (n2 - 1)))
# Find the critical t-value
t_critical <- qt(1 - alpha / 2, df_satterthwaite)
# Calculate the margin of error
margin_of_error <- t_critical * sqrt(s1^2 / n1 + s2^2 / n2)
# Calculate the confidence interval
confidence_interval_lower <- (xbar1 - xbar2) - margin_of_error
confidence_interval_upper <- (xbar1 - xbar2) + margin_of_error
cat("Degrees of Freedom (Satterthwaite):", df_satterthwaite, "\n")
## Degrees of Freedom (Satterthwaite): 18.0759
cat("Critical t-value:", t_critical, "\n")
## Critical t-value: 2.10029
cat("Margin of Error:", margin_of_error, "\n")
## Margin of Error: 24.80655
cat("95% Confidence Interval:", "[", confidence_interval_lower, ",", confidence_interval_upper, "]\n")
## 95% Confidence Interval: [ -54.80655 , -5.193452 ]
# Initializing the variables
route_I <- c(32, 27, 34, 24, 31, 25, 30, 23, 27, 35)
route_II <- c(28, 28, 33, 25, 26, 29, 33, 27, 25, 33)
# Calculate the differences
differences <- route_I - route_II
# Calculate sample mean and standard deviation of differences
mean_d <- mean(differences)
sd_d <- sd(differences)
# Calculate the standard error
se_d <- sd_d / sqrt(length(differences))
# Find the critical t-value for a two-tailed test
t_critical <- qt(1 - 0.01 / 2, length(differences) - 1)
# Calculate the margin of error
margin_of_error <- t_critical * se_d
# Calculate the confidence interval
confidence_interval_lower <- mean_d - margin_of_error
confidence_interval_upper <- mean_d + margin_of_error
# Display the results
cat("Sample Mean of Differences:", mean_d, "\n")
## Sample Mean of Differences: 0.1
cat("Standard Deviation of Differences:", sd_d, "\n")
## Standard Deviation of Differences: 3.212822
cat("Standard Error of Differences:", se_d, "\n")
## Standard Error of Differences: 1.015983
cat("Critical t-value:", t_critical, "\n")
## Critical t-value: 3.249836
cat("Margin of Error:", margin_of_error, "\n")
## Margin of Error: 3.301779
cat("98% Confidence Interval:", "[", confidence_interval_lower, ",", confidence_interval_upper, "]\n")
## 98% Confidence Interval: [ -3.201779 , 3.401779 ]
# Initializing the variables
n1 <- 391 # sample size for employed persons
x1 <- 195 # number of employed persons who have registered to vote
n2 <- 510 # sample size for unemployed persons
x2 <- 193 # number of unemployed persons who have registered to vote
# Calculate sample proportions
p1 <- x1 / n1
p2 <- x2 / n2
# Calculate the pooled sample proportion
p <- (x1 + x2) / (n1 + n2)
# Calculate the standard error
se <- sqrt(p * (1 - p) * (1/n1 + 1/n2))
# Calculate the test statistic
z <- (p1 - p2) / se
# Find the critical z-value
critical_z <- qnorm(1 - 0.05)
# Display the critical value
cat("Critical Z-value:", critical_z, "\n")
## Critical Z-value: 1.644854
# Display the test statistic
cat("Test Statistic:", z, "\n")
## Test Statistic: 3.614018
# Make a decision
if (z > critical_z) {
cat("Reject the null hypothesis. There is evidence that the percentage of employed workers who have registered to vote exceeds the percentage of unemployed workers who have registered to vote.\n")
} else {
cat("Fail to reject the null hypothesis. There is no significant evidence that the percentage of employed workers who have registered to vote exceeds the percentage of unemployed workers who have registered to vote.\n")}
## Reject the null hypothesis. There is evidence that the percentage of employed workers who have registered to vote exceeds the percentage of unemployed workers who have registered to vote.