Homework 2
sai Pothula
Author

Sai Padma pothula

Published

May 2, 2023

1:

Code
n1 <- 539
xbar1 <- 19
s1 <- 10

SE1 <- s1/sqrt(n1)
error = qt(0.95, df = n1 - 1)*SE1
LB1 = xbar1 - error
UB1 = xbar1 + error
cat("The 90% confidence interval for the mean wait time for angiography is (", LB1, ",", UB1, ")\n")
The 90% confidence interval for the mean wait time for angiography is ( 18.29029 , 19.70971 )
Code
n2 <- 847
xbar2 <- 18
s2 <- 9
SE2 <- s2/sqrt(n2)
error = qt(0.95, df = n2 - 1)*SE2
LB2 = xbar2 - error
UB2 = xbar2 + error
cat("The 90% confidence interval for the mean wait time for angiography is (", LB2, ",", UB2, ")\n")
The 90% confidence interval for the mean wait time for angiography is ( 17.49078 , 18.50922 )
Code
print(UB1-LB1)
[1] 1.419421
Code
print(UB2-LB2)
[1] 1.018436

2:

Code
n <- 1031
x <- 567
p <- x/n
p
[1] 0.5499515

3:

Code
z <- qnorm(0.95)

#Confidence interval for p
CI <- p + c(-1, 1) * z * sqrt((p*(1-p))/1031)
CI
[1] 0.5244662 0.5754368
Code
sd <- (200 - 30)/4
ME <- 5
n <- ((qnorm(0.95) * sd / ME) ^ 2)
n
[1] 195.4755

4A:

Code
sample_mean <- 410
h_mean <- 500
sample_std <- 90
n <- 9
t_score <- (sample_mean - h_mean) / (sample_std / sqrt(n))
p <- 2 * pt(-abs(t_score), df = n - 1)
p
[1] 0.01707168

B:

Code
p <-  pt((t_score), df = n - 1)
p
[1] 0.008535841

C:

Code
p <-  pt((t_score), df = n - 1, lower.tail=FALSE)
p
[1] 0.9914642

5:

Code
n_jones <- 1000
y_bar_jones <- 519.5
se_jones <- 10.0

t_score_jones <- (y_bar_jones - 500) / se_jones
t_score_jones
[1] 1.95
Code
n_smith <- 1000
y_bar_smith <- 519.7
se_smith <- 10.0

t_score_smith <- (y_bar_smith - 500) / se_smith
t_score_smith
[1] 1.97
Code
p_value <- 2 * pt(abs(t_score_smith), df = n_smith - 1, lower.tail = FALSE)
p_value
[1] 0.04911426
Code
p_value_j <- 2 * pt(abs(t_score_jones), df = n_jones - 1, lower.tail = FALSE)
p_value_j
[1] 0.05145555

6:

Code
grade_levels <- c("6th grade", "7th grade", "8th grade")
healthy_snack <- c(31, 43, 51)
unhealthy_snack <- c(69, 57, 49)
observed <- rbind(healthy_snack, unhealthy_snack)
result <- chisq.test(observed)
result

    Pearson's Chi-squared test

data:  observed
X-squared = 8.3383, df = 2, p-value = 0.01547

7:

Code
area1 <- c(6.2, 9.3, 6.8, 6.1, 6.7, 7.5)
area2 <- c(7.5, 8.2, 8.5, 8.2, 7.0, 9.3)
area3 <- c(5.8, 6.4, 5.6, 7.1, 3.0, 3.5)

perpupil <- data.frame(area1, area2, area3)

summary(perpupil)
     area1           area2           area3      
 Min.   :6.100   Min.   :7.000   Min.   :3.000  
 1st Qu.:6.325   1st Qu.:7.675   1st Qu.:4.025  
 Median :6.750   Median :8.200   Median :5.700  
 Mean   :7.100   Mean   :8.117   Mean   :5.233  
 3rd Qu.:7.325   3rd Qu.:8.425   3rd Qu.:6.250  
 Max.   :9.300   Max.   :9.300   Max.   :7.100  
Code
perpupil2 <- stack(perpupil[,1:3])

model <- aov(values ~ ind, data = perpupil2)

summary(model)
            Df Sum Sq Mean Sq F value  Pr(>F)   
ind          2  25.66  12.832   8.176 0.00397 **
Residuals   15  23.54   1.569                   
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1