11-16-25library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.1 ✔ stringr 1.5.2
## ✔ ggplot2 4.0.0 ✔ tibble 3.3.0
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.1
## ✔ purrr 1.1.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Nutrition_study <- read.csv("C:/Users/nika/Downloads/R/csv/NutritionStudy.csv")
Fish_gills <- read.csv("C:/Users/nika/Downloads/R/csv/FishGills3.csv")
Problem 1
observed_frequencies <- c(244, 192)
expected_frequencies <- c(218, 218)
\(H_0\):\(p_1\) = \(p_2\) = 1/2 \(H_a\): at least on \(p_i\) \(\neq\) 1/2
chisq.test(observed_frequencies)
##
## Chi-squared test for given probabilities
##
## data: observed_frequencies
## X-squared = 6.2018, df = 1, p-value = 0.01276
Based on the p value obtained, we reject the idea that the outcomes are equally likely and conclude that there are differences in the probabilities of X and R classification.
Problem 2
observed_dataset<- table(Nutrition_study$Vitamin, Nutrition_study$Sex)
observed_dataset
##
## Female Male
## 1 109 13
## 2 77 5
## 3 87 24
\(H_0\): There is no association between gender and vitamin use. \(H_a\): There is an association between gender and vitamin use.
chisq.test(observed_dataset)
##
## Pearson's Chi-squared test
##
## data: observed_dataset
## X-squared = 11.071, df = 2, p-value = 0.003944
With a p-value of 0.003944, which is less than the typical significance level of 0.05, there is sufficient evidence to reject the null hypothesis. Therefore, we conclude that there is a significant association between gender and vitamin use.
Problem 3
\(H_0\): \(\mu_A\) = \(\mu_B\) = \(\mu_C\) \(H_a\): not all \(\mu_i\) are equal
anova_result <- aov(GillRate ~ Calcium, data = Fish_gills)
anova_result
## Call:
## aov(formula = GillRate ~ Calcium, data = Fish_gills)
##
## Terms:
## Calcium Residuals
## Sum of Squares 2037.222 19064.333
## Deg. of Freedom 2 87
##
## Residual standard error: 14.80305
## Estimated effects may be unbalanced
summary(anova_result)
## Df Sum Sq Mean Sq F value Pr(>F)
## Calcium 2 2037 1018.6 4.648 0.0121 *
## Residuals 87 19064 219.1
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
The p-value is smaller than the typical significance level of 0.05(0.0121): indicating strong evidence against the null hypothesis. Overall, this test suggests that there are significant differences in mean gill rates across the different calcium levels.