LoslegenKostenlos starten

Age categories by shellweight categories

Earlier, in chapter 2, you created agecat for abalones with ages younger than 10.5 years (coded as "< 10.5") versus those 10.5 years and older (coded as "10.5 and older"). Let's also break the abalone shell weights into categories equal to or lower than 0.235 grams versus those that weigh more than 0.235 grams.

The abaloneKeep dataset with agecat has been loaded for you plus the dplyr package.

Diese Übung ist Teil des Kurses

<Kurs>R For SAS Users</Kurs>
Kurs ansehen

Übungsanweisungen

  • Use ifelse() function to add shellcat to abaloneKeep for shell weight split into 2 categories above and below 0.235g, labeled as "<= 0.235g" and "> 0.235g".
  • Create contingency table called tableageshell of chisq.test() for agecat by shellcat. Run chisq.test() on tableageshell.
  • Make a mosaic plot of agecat by shellcat. Use colors "light blue" and "grey". Set title to "Mosaicplot of age by shell categories".

Interaktive praktische Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Add shellcat to abaloneKeep
___ <- ___ %>%
  mutate(shellcat = ifelse(___, ___, ___))

# Run chisq.test of agecat by shellcat
tableageshell <- ___ %>% 
  with(___)

chisq.test(___)

# Make mosaicplot of agecat by shellcat
mosaicplot(___ ~ ___, data = ___,
           color = c(___, ___),
           main = ___)
Code bearbeiten und ausführen