Untitled

Anonymous
plain_text
03/04/2026 5:20 AM
6.6 KB
13
Indexable
---
title: "exp 5"
author: "Dharshan"
date: "2026-03-04"
output: word_document
---
Z TEST
#problem 1
```{r}
sample_mean <- 75
population_mean <- 72
sigma <- 10
n <- 100
alpha <- 0.05
z_stat <- (sample_mean - population_mean) / (sigma / sqrt(n))
z_critical <- qnorm(1 - alpha / 2)
z_stat
z_critical
if(abs(z_stat) > z_critical) {
print("Reject the null hypothesis")
} else {
print("Fail to reject the null hypothesis")
}
```
#problem 2
```{r}
sample_mean <- 505
population_mean <- 500
sigma <- 15
n <- 30
alpha <- 0.01
z_stat <- (sample_mean - population_mean) / (sigma / sqrt(n))
z_critical <- qnorm(1 - alpha)
z_stat
z_critical
if(z_stat > z_critical) {
print("Reject the null hypothesis")
} else {
print("Fail to reject the null hypothesis")
}
```
#problem 3
```{r}
p_hat <- 110 / 200
p0 <- 0.60 
n <- 200
alpha <- 0.05
z_stat <- (p_hat - p0) / sqrt((p0 * (1 - p0)) / n)
z_critical <- qnorm(alpha)
z_stat
z_critical
if(z_stat < z_critical) {
print("Reject the null hypothesis")
} else {
print("Fail to reject the null hypothesis")
}
```
#problem 4
```{r}
sample_mean <- 3.2
population_mean <- 3
sigma <- 0.8
n <- 50
alpha <- 0.05
z_stat <- (sample_mean - population_mean) / (sigma / sqrt(n))
z_critical <- qnorm(1 - alpha)
z_stat
z_critical
if(z_stat > z_critical) {
print("Reject the null hypothesis")
} else {
print("Fail to reject the null hypothesis")
}
```
#problem 5
```{r}
p_hat <- 245 / 500 
p0 <- 0.48 
n <- 500
alpha <- 0.05
z_stat <- (p_hat - p0) / sqrt((p0 * (1 - p0)) / n)
z_critical <- qnorm(1 - alpha / 2)
z_stat
z_critical
if(abs(z_stat) > z_critical) {
print("Reject the null hypothesis")
} else {
print("Fail to reject the null hypothesis")
}
```
#problem 6
```{r}
sample_mean <- 177
population_mean <- 175
sigma <- 10
n <- 200
alpha <- 0.01
z_stat <- (sample_mean - population_mean) / (sigma / sqrt(n))
z_critical <- qnorm(1 - alpha)
z_stat
z_critical
if(z_stat > z_critical) {
print("Reject the null hypothesis")
} else {
print("Fail to reject the null hypothesis")
}
```
#problem 7
```{r}
p_hat <- 110 / 150
p0 <- 0.70 
n <- 150
alpha <- 0.05
z_stat <- (p_hat - p0) / sqrt((p0 * (1 - p0)) / n)
z_critical <- qnorm(1 - alpha)
z_stat
z_critical
if(z_stat > z_critical) {
print("Reject the null hypothesis")
} else {
print("Fail to reject the null hypothesis")
}
```
T TEST
#problem 8
```{r}
sample_mean <- 85
population_mean <- 80
s <- 10
n <- 25
alpha <- 0.05
t_stat <- (sample_mean - population_mean) / (s / sqrt(n))
df <- n - 1
t_critical <- qt(1 - alpha / 2, df)
t_stat
t_critical
if(abs(t_stat) > t_critical) {
print("Reject the null hypothesis")
} else {
print("Fail to reject the null hypothesis")
}
```
#problem 9
```{r}
sample_mean <- 500.5
population_mean <- 500
s <- 2.5
n <- 30
alpha <- 0.01
t_stat <- (sample_mean - population_mean) / (s / sqrt(n))
df <- n - 1
t_critical <- qt(1 - alpha, df)
t_stat
t_critical
if(t_stat > t_critical) {
print("Reject the null hypothesis")
} else {
print("Fail to reject the null hypothesis")
}
```
#problem 10
```{r}
mean1 <- 120
mean2 <- 118
s1 <- 15
s2 <- 14
n1 <- 40
n2 <- 35
alpha <- 0.05
pooled_variance <- (((n1 - 1) * s1^2) + ((n2 - 1) * s2^2)) / (n1 + n2 - 2)
t_stat <- (mean1 - mean2) / sqrt(pooled_variance * (1 / n1 + 1 / n2))
df <- n1 + n2 - 2
t_critical <- qt(1 - alpha / 2, df)
t_stat
t_critical
if(abs(t_stat) > t_critical) {
print("Reject the null hypothesis")
} else {
print("Fail to reject the null hypothesis")
}
```
#problem 11
```{r}
mean1 <- 78
mean2 <- 82
s1 <- 10
s2 <- 12
n1 <- 50
n2 <- 45
alpha <- 0.05
t_stat <- (mean1 - mean2) / sqrt((s1^2 / n1) + (s2^2 / n2))
df <- ((s1^2 / n1 + s2^2 / n2)^2) / (((s1^2 / n1)^2 / (n1 - 1)) + ((s2^2 /
n2)^2 / (n2 - 1)))
t_critical <- qt(1 - alpha / 2, df)
t_stat
t_critical
if(abs(t_stat) > t_critical) {
print("Reject the null hypothesis")
} else {
print("Fail to reject the null hypothesis")
}
```
#problem 12
```{r}
differences <- c(-1.5, 0.2, -2.1, -0.9, -1.7, 0.3, -0.5, -1.0, -1.2, -0.8)
alpha <- 0.05
t_test <- t.test(differences, mu = 0, alternative = "two.sided", conf.level
= 1 - alpha)
t_test
if(t_test$p.value < alpha) {
print("Reject the null hypothesis")
} else {
print("Fail to reject the null hypothesis")
}
```
#problem 13
```{r}
differences <- c(5, 3, 4, 6, 7, 8, 5, 4, 3, 6, 7, 4, 5, 8, 6)
alpha <- 0.01
t_test <- t.test(differences, mu = 0, alternative = "greater", conf.level =
1 - alpha)
t_test
if(t_test$p.value < alpha) {
print("Reject the null hypothesis")
} else {
print("Fail to reject the null hypothesis")
}
```
#problem 14
```{r}
sample_mean <- 45
population_mean <- 50
s <- 7
n <- 20
alpha <- 0.05
t_stat <- (sample_mean - population_mean) / (s / sqrt(n))
df <- n - 1
t_critical <- qt(alpha, df)
t_stat
t_critical
if(t_stat < t_critical) {
print("Reject the null hypothesis")
} else {
print("Fail to reject the null hypothesis")
}
```
Editor is loading...
Leave a Comment