library(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
setwd("C:/Users/mezni/OneDrive/Desktop/Heha")
nutrition<- read_csv("NutritionStudy.csv")
## Rows: 315 Columns: 17
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): Smoke, Sex, VitaminUse
## dbl (14): ID, Age, Quetelet, Vitamin, Calories, Fat, Fiber, Alcohol, Cholest...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
fish<- read_csv("FishGills3.csv")
## Rows: 90 Columns: 2
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): Calcium
## dbl (1): GillRate
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Problem 1
observed <- c(R = 244, X = 192)
expected <- c(218, 218)
\(H_0\) : The R and X alleles are equally likely(\(p_R\) = \(p_X\) = 0.5) \(H_a\) : The R and X alleles are not equally likely
chisq_test1 <- chisq.test(observed, p = c(0.5, 0.5))
chisq_test1
##
## Chi-squared test for given probabilities
##
## data: observed
## X-squared = 6.2018, df = 1, p-value = 0.01276
Conclusion: With a p-value of 0.01276, which is less than the typical significance level of 0.05, there is sufficient evidence to reject the null hypothesis. There is evidence that the two alleles are not equally likely.
Problem 2
table_vit <- table(nutrition$VitaminUse, nutrition$Sex)
chisq_test2 <- chisq.test(table_vit)
chisq_test2
##
## Pearson's Chi-squared test
##
## data: table_vit
## X-squared = 11.071, df = 2, p-value = 0.003944
\(H_0\) = Vitamin use and gender are independent \(H_a\) = There is an association between vitamin use and gender
Conclusion: 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 vitamin use and gender.
Problem 3
anova_test <- aov(GillRate ~ Calcium, data = fish)
summary(anova_test)
## 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
\(H_0\) = Mean gill rates are equal across all calcium levels \(H_a\) = At least one mean gill rate is different
conclusion: With a p-value of 0.0121, 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 difference in mean gill rates among the different calcium levels.