This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
##1.Test the hypothesis that the mean systolic blood pressure in a certain population equals 140mmHg.The standard deviation has a known value of 20 and a data set of 57 patients is available.94,115,98,129,99,133,125,127,117,119,143,124,90,100,132,92,127,129,135,138,145,148,149,116,96,97,94,136,137,147,148,149,137,107,108,109,120,121,122,123,146,127,129,127,147,129,111,121,131,141,148,149,133,143,127,129,139.
library(DescTools)
## Warning: package 'DescTools' was built under R version 4.3.3
data<-c(94,115,98,129,99,133,125,127,117,119,143,124,90,100,132,92,127,129,135,138,145,148,149,116,96,97,94,136,137,147,148,149,137,107,108,109,120,121,122,123,146,127,129,127,147,129,111,121,131,141,148,149,133,143,127,129,139)
population_mean <- 140
population_stddev <- 20
n <- 57
alpha <- 0.05
sample_mean <- mean(data)
z <- (sample_mean - population_mean) / (population_stddev / sqrt(n))
# Using two-tailed test
z_critical_upper <- qnorm(1 - alpha/2)
z_critical_lower <- -qnorm(1 - alpha/2)
cat("Z-Score:", z)
## Z-Score: -5.483564
## Z-Score: -3.660905
cat("z critical upper:",z_critical_upper)
## z critical upper: 1.959964
## z critical upper: 1.959964
cat("z critical Lower:",z_critical_lower)
## z critical Lower: -1.959964
## z critical Lower: -1.959964
if (z > z_critical_upper || z < z_critical_lower) {
print("Reject the null hypothesis")
} else {
print("Fail to reject the null hypothesis")
}
## [1] "Reject the null hypothesis"
## [1] "Reject the null hypothesis"
z_result <- ZTest(x = data, mu = population_mean, sd_pop = population_stddev, alternative = "two.sided")
z_result
##
## One Sample z-test
##
## data: data
## z = -5.4836, Std. Dev. Population = 20, p-value = 4.168e-08
## alternative hypothesis: true mean is not equal to 140
## 95 percent confidence interval:
## 120.2816 130.6658
## sample estimates:
## mean of x
## 125.4737
# 2...A coin is tossed 100 times and turns up head 43 times Test the claim that this is a fair coin.Use 5% level of significance to test the claim.
n <- 100
x <- 43
p_null <- 0.5
p_hat <- x / n
standard_error <- sqrt((p_null * (1 - p_null)) / n)
z <- (p_hat - p_null) / standard_error
alpha <- 0.05
critical_value <- qnorm(1 - alpha / 2)
cat("Sample Proportion:", p_hat, "\n")
## Sample Proportion: 0.43
## Sample Proportion: 0.43
cat("Z-Score:", z, "\n")
## Z-Score: -1.4
## Z-Score: -1.4
cat("Critical Value:", critical_value, "\n")
## Critical Value: 1.959964
## Critical Value: 1.959964
if (abs(z) > critical_value) {
cat("Reject the null hypothesis: The coin is not fair.\n")
} else {
cat("Fail to reject the null hypothesis: The coin is fair.\n")
}
## Fail to reject the null hypothesis: The coin is fair.
#Q3 A manufacturer of sports equipment has developed a new synthetic fishing line that the company claims has a mean breaking strength of 8 kilograms with a standard deviation of 0.5 kilogram. Test the hypothesis that μ=8 kilograms against the alternative that μ is not equal to 8 kilograms if a random sample of 50 lines is tested and found to have a mean breaking strength of 7.8 kilograms. Use a 0.01 level of significance.
population_mean <- 8
population_stddev <- 0.5
sample_mean <- 7.8
sample_size <- 50
standard_error <- population_stddev / sqrt(sample_size)
z <- (sample_mean - population_mean) / standard_error
alpha <- 0.01
critical_value_left <- qnorm(alpha / 2)
critical_value_right <- qnorm(1 - alpha / 2)
cat("Sample Mean:", sample_mean, "\n")
## Sample Mean: 7.8
## Sample Mean: 7.8
cat("Z-Score:", z, "\n")
## Z-Score: -2.828427
## Z-Score: -2.828427
cat("Critical Values (Left, Right):", critical_value_left, ",", critical_value_right, "\n")
## Critical Values (Left, Right): -2.575829 , 2.575829
## Critical Values (Left, Right): -2.575829 , 2.575829
if (z < critical_value_left || z > critical_value_right) {
cat("Reject the null hypothesis: The mean breaking strength is not equal to 8 kilograms.\n")
} else {
cat("Fail to reject the null hypothesis: The mean breaking strength is equal to 8 kilograms.\n")
}
## Reject the null hypothesis: The mean breaking strength is not equal to 8 kilograms.