Hw 8

In your markdown answer the following problems. Include the following:  Your hypotheses.  P-value  Conclusion

library(readr)
df <- 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.
rf <- 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.

Problem 1: ACTN3 is a gene that encodes alpha-actinin-3, a protein in fast-twitch muscle fibers, important for activities like sprinting and weightlifting. The gene has two main alleles: R (functional) and X (non-functional). The R allele is linked to better performance in strength, speed, and power sports, while the X allele is associated with endurance due to a greater reliance on slow-twitch fibers. However, athletic performance is influenced by various factors, including training, environment, and other genes, making the ACTN3 genotype just one contributing factor. A study examines the ACTN3 genetic alleles R and X, also associated with fast-twitch muscles. Of the 436 people in this sample, 244 were classified as R, and 192 were classified as X. Does the sample provide evidence that the two options are not equally likely? Conduct the test using a chi-square goodness-of-fit test.

observed <- c(244,192)

theoretical_prop <- rep(1/2, 2)

\(H_0\):\(p_1\) = \(p_2\) = 1/2 \(H_a\): at least on \(p_i\) \(\neq\) 1/2

expected_values <- theoretical_prop*sum(observed) 
expected_values
[1] 218 218
chisq.test(observed)

    Chi-squared test for given probabilities

data:  observed
X-squared = 6.2018, df = 1, p-value = 0.01276

Based off the p-value of 0.01275 we REJECT the idea of the outcomes being equally likely.

Problem 2: Who Is More Likely to Take Vitamins: Males or Females? The dataset NutritionStudy contains, among other things, information about vitamin use and the gender of the participants. Is there a significant association between these two variables? Use the variables VitaminUse and Gender to conduct a chi-square analysis and give the results. (Test for Association)

head(rf)
# A tibble: 6 × 17
     ID   Age Smoke Quetelet Vitamin Calories   Fat Fiber Alcohol Cholesterol
  <dbl> <dbl> <chr>    <dbl>   <dbl>    <dbl> <dbl> <dbl>   <dbl>       <dbl>
1     1    64 No        21.5       1    1299.  57     6.3     0         170. 
2     2    76 No        23.9       1    1032.  50.1  15.8     0          75.8
3     3    38 No        20.0       2    2372.  83.6  19.1    14.1       258. 
4     4    40 No        25.1       3    2450.  97.5  26.5     0.5       333. 
5     5    72 No        21.0       1    1952.  82.6  16.2     0         171. 
6     6    40 No        27.5       3    1367.  56     9.6     1.3       155. 
# ℹ 7 more variables: BetaDiet <dbl>, RetinolDiet <dbl>, BetaPlasma <dbl>,
#   RetinolPlasma <dbl>, Sex <chr>, VitaminUse <chr>, PriorSmoke <dbl>
summary(rf)
       ID             Age           Smoke              Quetelet    
 Min.   :  1.0   Min.   :19.00   Length:315         Min.   :16.33  
 1st Qu.: 79.5   1st Qu.:39.00   Class :character   1st Qu.:21.80  
 Median :158.0   Median :48.00   Mode  :character   Median :24.74  
 Mean   :158.0   Mean   :50.15                      Mean   :26.16  
 3rd Qu.:236.5   3rd Qu.:62.50                      3rd Qu.:28.85  
 Max.   :315.0   Max.   :83.00                      Max.   :50.40  
    Vitamin         Calories           Fat             Fiber      
 Min.   :1.000   Min.   : 445.2   Min.   : 14.40   Min.   : 3.10  
 1st Qu.:1.000   1st Qu.:1338.0   1st Qu.: 53.95   1st Qu.: 9.15  
 Median :2.000   Median :1666.8   Median : 72.90   Median :12.10  
 Mean   :1.965   Mean   :1796.7   Mean   : 77.03   Mean   :12.79  
 3rd Qu.:3.000   3rd Qu.:2100.4   3rd Qu.: 95.25   3rd Qu.:15.60  
 Max.   :3.000   Max.   :6662.2   Max.   :235.90   Max.   :36.80  
    Alcohol         Cholesterol       BetaDiet     RetinolDiet    
 Min.   :  0.000   Min.   : 37.7   Min.   : 214   Min.   :  30.0  
 1st Qu.:  0.000   1st Qu.:155.0   1st Qu.:1116   1st Qu.: 480.0  
 Median :  0.300   Median :206.3   Median :1802   Median : 707.0  
 Mean   :  3.279   Mean   :242.5   Mean   :2186   Mean   : 832.7  
 3rd Qu.:  3.200   3rd Qu.:308.9   3rd Qu.:2836   3rd Qu.:1037.0  
 Max.   :203.000   Max.   :900.7   Max.   :9642   Max.   :6901.0  
   BetaPlasma     RetinolPlasma        Sex             VitaminUse       
 Min.   :   0.0   Min.   : 179.0   Length:315         Length:315        
 1st Qu.:  90.0   1st Qu.: 466.0   Class :character   Class :character  
 Median : 140.0   Median : 566.0   Mode  :character   Mode  :character  
 Mean   : 189.9   Mean   : 602.8                                        
 3rd Qu.: 230.0   3rd Qu.: 716.0                                        
 Max.   :1415.0   Max.   :1727.0                                        
   PriorSmoke   
 Min.   :1.000  
 1st Qu.:1.000  
 Median :2.000  
 Mean   :1.638  
 3rd Qu.:2.000  
 Max.   :3.000  

\(H_0\) : Gender is not associated with vitamin use \(H_a\) : Gender is associated with vitamin use

observed_dataset<- table(rf$Sex, rf$VitaminUse)
observed_dataset
        
          No Occasional Regular
  Female  87         77     109
  Male    24          5      13
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 there is statistical significance that gender affects vitamin use.

Problem 3: Most fish use gills for respiration in water, and researchers can observe how fast a fish’s gill cover beats to study ventilation, much like we might observe a person’s breathing rate. Professor Brad Baldwin is interested in how water chemistry might affect gill beat rates. In one experiment, he randomly assigned fish to tanks with different calcium levels. One tank was low in calcium (0.71 mg/L), the second tank had a medium amount (5.24 mg/L), and the third tank had water with a high calcium level (18.24 mg/L). His research team counted gill rates (beats per minute) for samples of 30 fish in each tank. The results are stored in FishGills3. Perform ANOVA test to see if the mean gill rate differs depending on the calcium level of the water.

head(df)
# A tibble: 6 × 2
  Calcium GillRate
  <chr>      <dbl>
1 Low           55
2 Low           63
3 Low           78
4 Low           85
5 Low           65
6 Low           98

\(H_0\): \(\mu_L\) = \(\mu_M\) = \(\mu_H\)

\(H_a\): not all \(\mu_i\) are equal

anova_result9 <- aov(GillRate ~ Calcium, data = df)

anova_result9
Call:
   aov(formula = GillRate ~ Calcium, data = df)

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_result9)
            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

With the p-value of 0.0121 it suggests that there is a significant differences in mean gill rate measurements among the different calcium levels.