##Data Analysis #2
## 'data.frame': 1036 obs. of 8 variables:
## $ SEX : Factor w/ 3 levels "F","I","M": 2 2 2 2 2 2 2 2 2 2 ...
## $ LENGTH: num 5.57 3.67 10.08 4.09 6.93 ...
## $ DIAM : num 4.09 2.62 7.35 3.15 4.83 ...
## $ HEIGHT: num 1.26 0.84 2.205 0.945 1.785 ...
## $ WHOLE : num 11.5 3.5 79.38 4.69 21.19 ...
## $ SHUCK : num 4.31 1.19 44 2.25 9.88 ...
## $ RINGS : int 6 4 6 3 6 6 5 6 5 6 ...
## $ CLASS : Factor w/ 5 levels "A1","A2","A3",..: 1 1 1 1 1 1 1 1 1 1 ...
#### Section 1: (5 points) ####
(1)(a) Form a histogram and QQ plot using RATIO. Calculate skewness and kurtosis using ‘rockchalk.’ Be aware that with ‘rockchalk’, the kurtosis value has 3.0 subtracted from it which differs from the ‘moments’ package.
## Skewness: 0.6573096
## Adjusted Kurtosis: 0.3296656
(1)(b) Tranform RATIO using log10() to create L_RATIO (Kabacoff Section 8.5.2, p. 199-200). Form a histogram and QQ plot using L_RATIO. Calculate the skewness and kurtosis. Create a boxplot of L_RATIO differentiated by CLASS.
## Skewness of L_RATIO: 0.3528897
## Adjusted Kurtosis of L_RATIO: -0.1956505
(1)(c) Test the homogeneity of variance across classes using bartlett.test() (Kabacoff Section 9.2.2, p. 222).
##
## Bartlett test of homogeneity of variances
##
## data: L_RATIO by CLASS
## Bartlett's K-squared = 33.434, df = 4, p-value = 9.734e-07
Essay Question: Based on steps 1.a, 1.b and 1.c, which variable RATIO or L_RATIO exhibits better conformance to a normal distribution with homogeneous variances across age classes? Why?
Answer: (I think based on the analysis from steps 1.a, 1.b, and 1.c, the variable L_RATIO (log-transformed RATIO) exhibits better conformance to a normal distribution with homogeneous variances across age classes. The histogram and QQ plot for L_RATIO show a more symmetric distribution with reduced skewness and kurtosis values compared to RATIO, indicating that L_RATIO is closer to a normal distribution. Additionally, the Bartlett’s test results show a significant p-value, suggesting that variances across classes may not be fully homogeneous. However, L_RATIO still provides a more normalized and consistent spread across classes than RATIO, making it a better fit for analyses that assume normality and homogeneity of variance.)
#### Section 2 (10 points) ####
(2)(a) Perform an analysis of variance with aov() on L_RATIO using CLASS and SEX as the independent variables (Kabacoff chapter 9, p. 212-229). Assume equal variances. Perform two analyses. First, fit a model with the interaction term CLASS:SEX. Then, fit a model without CLASS:SEX. Use summary() to obtain the analysis of variance tables (Kabacoff chapter 9, p. 227).
## Df Sum Sq Mean Sq F value Pr(>F)
## CLASS 4 0.04946 0.012365 43.070 < 2e-16 ***
## SEX 2 0.01303 0.006514 22.689 2.29e-10 ***
## CLASS:SEX 8 0.00301 0.000377 1.311 0.234
## Residuals 1021 0.29312 0.000287
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Df Sum Sq Mean Sq F value Pr(>F)
## CLASS 4 0.04946 0.012365 42.97 < 2e-16 ***
## SEX 2 0.01303 0.006514 22.63 2.4e-10 ***
## Residuals 1029 0.29613 0.000288
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Essay Question: Compare the two analyses. What does the non-significant interaction term suggest about the relationship between L_RATIO and the factors CLASS and SEX?
Answer: (Ithink the results of the two analyses show that the interaction term, CLASS, is non-significant (p = 0.234). This suggests that there is no meaningful interaction effect between CLASS and SEX on L_RATIO. In other words, the relationship between L_RATIO and CLASS does not significantly differ across levels of SEX, and vice versa. The main effects of CLASS and SEX are highly significant in both models, indicating that each factor independently influences L_RATIO. However, since the interaction term is not significant, it implies that the effects of CLASS and SEX on L_RATIO are additive rather than multiplicative, allowing for a simplified model without the interaction term. This simplified model should provide an adequate description of the data without loss of explanatory power.)
(2)(b) For the model without CLASS:SEX (i.e. an interaction term), obtain multiple comparisons with the TukeyHSD() function. Interpret the results at the 95% confidence level (TukeyHSD() will adjust for unequal sample sizes).
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = L_RATIO ~ CLASS + SEX, data = mydata)
##
## $CLASS
## diff lwr upr p adj
## A2-A1 -0.012483896 -0.017869374 -7.098418e-03 0.0000000
## A3-A1 -0.018096590 -0.023237545 -1.295564e-02 0.0000000
## A4-A1 -0.022313749 -0.027910912 -1.671659e-02 0.0000000
## A5-A1 -0.023702740 -0.029375250 -1.803023e-02 0.0000000
## A3-A2 -0.005612694 -0.009567118 -1.658271e-03 0.0010565
## A4-A2 -0.009829853 -0.014361551 -5.298155e-03 0.0000000
## A5-A2 -0.011218844 -0.015843281 -6.594408e-03 0.0000000
## A4-A3 -0.004217159 -0.008455357 2.104015e-05 0.0518810
## A5-A3 -0.005606150 -0.009943368 -1.268932e-03 0.0039322
## A5-A4 -0.001388991 -0.006258311 3.480329e-03 0.9365474
##
## $SEX
## diff lwr upr p adj
## I-F 0.0067663915 0.003654820 0.009877963 0.0000012
## M-F 0.0006926505 -0.002311380 0.003696681 0.8509975
## M-I -0.0060737409 -0.009070381 -0.003077100 0.0000067
Additional Essay Question: first, interpret the trend in coefficients across age classes. What is this indicating about L_RATIO? Second, do these results suggest male and female abalones can be combined into a single category labeled as ‘adults?’ If not, why not?
Answer: (The TukeyHSD results for CLASS show a consistent decreasing trend in L_RATIO as the age class increases from A1 to A5, with all pairwise comparisons involving A1 showing statistically significant differences. This suggests that L_RATIO tends to decrease with higher age classes, indicating potential biological differences in shell measurements across age groups. For SEX, significant differences are found between females (F) and immatures (I) as well as between immatures (I) and males (M), while the difference between males and females is not significant (p = 0.85). This lack of significant difference between male and female abalones suggests that these two groups might have similar L_RATIO values. However, because immatures differ significantly from both males and females, combining all three into a single category labeled ‘adults’ would overlook the distinct L_RATIO profile of immatures, indicating that this categorization would not be appropriate.)
#### Section 3: (10 points) ####
(3)(a1) Here, we will combine “M” and “F” into a new level, “ADULT”. The code for doing this is given to you. For (3)(a1), all you need to do is execute the code as given.
##
## ADULT I
## 707 329
(3)(a2) Present side-by-side histograms of VOLUME. One should display infant volumes and, the other, adult volumes.
Essay Question: Compare the histograms. How do the distributions differ? Are there going to be any difficulties separating infants from adults based on VOLUME?
Answer: (I think the histograms show that the volume distributions for infants and adults differ significantly. The distribution for adults is more spread out, with a peak around 400-500 and values extending up to 1000, indicating a wider range of volumes among adult abalones. In contrast, the distribution for infants is more concentrated, with a peak around 200 and very few values exceeding 500. This difference suggests that, in general, infants tend to have lower volumes compared to adults. However, there is some overlap between the higher volumes of infants and the lower volumes of adults, which may make it challenging to separate infants from adults solely based on volume. Therefore, while volume can provide some indication, it may not be a fully reliable metric for distinguishing between infants and adults.)
(3)(b) Create a scatterplot of SHUCK versus VOLUME and a scatterplot of their base ten logarithms, labeling the variables as L_SHUCK and L_VOLUME. Please be aware the variables, L_SHUCK and L_VOLUME, present the data as orders of magnitude (i.e. VOLUME = 100 = 10^2 becomes L_VOLUME = 2). Use color to differentiate CLASS in the plots. Repeat using color to differentiate by TYPE.
Additional Essay Question: Compare the two scatterplots. What effect(s) does log-transformation appear to have on the variability present in the plot? What are the implications for linear regression analysis? Where do the various CLASS levels appear in the plots? Where do the levels of TYPE appear in the plots?
Answer: (I feel like the log-transformation of SHUCK and VOLUME reduces the spread of the data, making it more linear and compact. In the original scale, there is a wide range of variability, especially for larger values of VOLUME, where points are more dispersed. After log-transformation, this variability is reduced, leading to a more even distribution of points along a linear trend, which is beneficial for linear regression analysis as it stabilizes variance and meets the assumption of homoscedasticity (constant variance). Regarding CLASS, lower age classes (e.g., A1) are positioned towards the lower end of both VOLUME and SHUCK, while higher classes (e.g., A5) have larger values and are more spread out in the original scale. For TYPE, infants (I) are clustered towards the lower end of both VOLUME and SHUCK, whereas adults (ADULT) are distributed across a broader range, though log-transformation reduces this spread.)