Problem 1

# Observed counts

observed <- c(244, 192)

    # Chi-Square goodness-of-fit test
chisq.test(observed, p= c(0.5,0.5))
## 
##  Chi-squared test for given probabilities
## 
## data:  observed
## X-squared = 6.2018, df = 1, p-value = 0.01276
# P-Value
chisq.test(observed, p = c(0.5, 0.5))$p.value
## [1] 0.01276179

Conclusion: Assuming a standard significance level of Alpha = 0.05, we reject the null hypothesis because the p-value (0.013) is less than 0.05, P=0.013 < 0.05. Therefore, we reject the null hypothesis. There is sufficient statistical evidence to conclude that the functional R allele and non-functional X allele are not equally likely to occur within this population.The chi-square goodness-of-fit test yields a test statistic of X^2 ~ 6.20 and a p-value of 0.013, which indicates that the R and X alleles are not distributed with equal probabilities in the studied population.

Problem 2

NutritionStudy <- read.csv("NutritionStudy.csv")

# Create a contingency table
vit_gender <- table(NutritionStudy$VitaminUse, NutritionStudy$Sex)

# view the table
vit_gender
##             
##              Female Male
##   No             87   24
##   Occasional     77    5
##   Regular       109   13
# Chi-square test of association
chi_test <- chisq.test(vit_gender)

# Display results
chi_test
## 
##  Pearson's Chi-squared test
## 
## data:  vit_gender
## X-squared = 11.071, df = 2, p-value = 0.003944
# Extract p-value
chi_test$p.value
## [1] 0.003944277
# Display expected counts
chi_test$expected
##             
##                 Female     Male
##   No          96.20000 14.80000
##   Occasional  71.06667 10.93333
##   Regular    105.73333 16.26667
# show percentages within each gender
round(prop.table(vit_gender, margin =2) * 100, 2)
##             
##              Female  Male
##   No          31.87 57.14
##   Occasional  28.21 11.90
##   Regular     39.93 30.95
# Test statistics
chi_test$parameter
## df 
##  2
# Degree of freedom
chi_test$parameter
## df 
##  2
#p-value
chi_test$p.value
## [1] 0.003944277

Conclusion: Since the p-value (0.0039) is much lower than the standard significance level of alpha = 0.05, we reject the null hypothesis. There is strong empirical evidence to conclude that a statistically significant association exists between gender and vitamin use in this population, with females demonstrating a higher likelihood of taking vitamins overall.

Problem 3

#Read the data 
fish <- read.csv ("FishGills3.csv")

# view the first few rows
head(fish)
##   Calcium GillRate
## 1     Low       55
## 2     Low       63
## 3     Low       78
## 4     Low       85
## 5     Low       65
## 6     Low       98
# Convert Calcium to a factor
fish$Calcium <- as.factor(fish$Calcium)

# Summary statistics by group
aggregate(GillRate ~ Calcium, data = fish, FUN = function(x) c(mean = mean(x), sd = sd(x), n = length(x)))
##   Calcium GillRate.mean GillRate.sd GillRate.n
## 1    High      58.16667    13.77675   30.00000
## 2     Low      68.50000    16.23481   30.00000
## 3  Medium      58.66667    14.28366   30.00000
# One-way ANOVA
gill_aov <- aov(GillRate ~ Calcium, data = fish) 

# Check Assumption

# 1. Normality of residuals
shapiro.test(residuals(gill_aov))
## 
##  Shapiro-Wilk normality test
## 
## data:  residuals(gill_aov)
## W = 0.96502, p-value = 0.01593
# Q-Q Plot
qqnorm(residuals(gill_aov))
qqline(residuals(gill_aov))

# Homegeneity of vaiences 
bartlett.test(GillRate ~ Calcium, data = fish)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  GillRate by Calcium
## Bartlett's K-squared = 0.87077, df = 2, p-value = 0.647
TukeyHSD(gill_aov)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = GillRate ~ Calcium, data = fish)
## 
## $Calcium
##                  diff        lwr        upr     p adj
## Low-High    10.333333   1.219540 19.4471264 0.0222533
## Medium-High  0.500000  -8.613793  9.6137931 0.9906108
## Medium-Low  -9.833333 -18.947126 -0.7195402 0.0313247
# Boxplot for visualization
boxplot(GillRate ~ Calcium,data = fish,
col = c("lightblue", "lightgreen", "lightpink"),
main = "Gill Rate by Calcium Level", xlab = "Calcium Level",
ylab = "Gill Rate (beats/min)")

#Conclusion: Reject Ho. There is significant evidence that the mean fish gill rate varies with calcium level in the water.