開始使用免費開始

依殼重類別分的年齡類別

在第 2 章中,你已經建立了 agecat:將年齡小於 10.5 歲的鮑魚(編碼為 "< 10.5")與年齡在 10.5 歲以上者(編碼為 "10.5 and older")區分開來。現在也來將鮑魚的殼重分成兩個類別:小於或等於 0.235 公克,以及大於 0.235 公克。

已為你載入含有 agecatabaloneKeep 資料集,以及 dplyr 套件。

本練習屬於課程

給 SAS 使用者的 R

檢視課程

練習說明

  • 使用 ifelse() 函式,將 shellcat 加入 abaloneKeep,依殼重分成高於與低於 0.235g 的 2 類,標記為 "<= 0.235g""> 0.235g"
  • 建立 agecatshellcatchisq.test() 列聯表,命名為 tableageshell。在 tableageshell 上執行 chisq.test()
  • 繪製 agecatshellcat 的馬賽克圖。使用顏色 "light blue""grey"。將標題設為 "Mosaicplot of age by shell categories"

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# 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 = ___)
編輯並執行程式碼