Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Tokoy.R #99 パーマーステーションのペンギンたち #1
bob3bob3
June 03, 2022
Science
1
760
Tokoy.R #99 パーマーステーションのペンギンたち #1
Rのpalmerpenguinsパッケージの紹介。
bob3bob3
June 03, 2022
Tweet
Share
More Decks by bob3bob3
See All by bob3bob3
応用セッション発表のすすめ
bob3bob3
0
470
LT発表のすすめ
bob3bob3
0
270
Rコードのベンチマーク
bob3bob3
0
410
TokyoR#101 パーマーステーションのペンギンたち2 データクリーニング編
bob3bob3
1
390
失われたグラフを求めて
bob3bob3
1
500
Tokyo.Rも100回目なので、 そろそろPythonと仲良くしたい
bob3bob3
0
1.2k
UXリサーチの誕生
bob3bob3
0
380
Tokyo.R RStudioでグラフをちょっときれいに出力する - CairoとAGG -
bob3bob3
0
870
Tokyo.R #98 Rを学ぶのは難しい
bob3bob3
3
2.9k
Other Decks in Science
See All in Science
pccr_ppt
zugalniy
0
150
AI最新論文読み会2022年まとめ
ailaboocu
0
250
GEOLOGI DAN PENGEMBANGAN GEOWISATA DAERAH CILETUH DAN SEKITARNYA, KECAMATAN CIEMAS KABUPATEN SUKABUMI, JAWA BARAT
dasaptaerwin
0
110
プロバスケットボール・B.LEAGUEにおけるインパクトメトリクスと総得点の関係 / Proposal of new impact metrics and its relation with points in B.LEAGUE
konakalab
0
130
Droidcon Berlin - A ride through AOSP's new colors
siddroid
0
400
男子プロテニスのサービス着地点およびランキングポイントに基づく予測得点確率モデルの構築 / Construction of scoring probability model based on service landing location and ranking points in men’s professional tennis matches
konakalab
0
160
NAKAMURA Takahiro
genomethica
0
320
Rで有名絵画を安全に買いたい
saltcooky12
0
110
標本調査法の基礎と実践
arumakan
0
310
SIGNATE ソニーグループ合同データ分析コンペティション(for Recruiting) 3rd Place Solution
yayaya
1
270
Tensor decomposition based unsupervised feature extraction with optimized standard deviation applied to differentially expressed genes, DNA methylation and histone modification
tagtag
0
110
統計的因果推論の理論と実装「潜在的結果変数の枠組み」
s1ok69oo
3
1.6k
Featured
See All Featured
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
349
27k
For a Future-Friendly Web
brad_frost
166
7.7k
Testing 201, or: Great Expectations
jmmastey
25
5.7k
Rails Girls Zürich Keynote
gr2m
87
12k
Ruby is Unlike a Banana
tanoku
93
9.5k
Atom: Resistance is Futile
akmur
256
24k
Mobile First: as difficult as doing things right
swwweet
213
7.8k
VelocityConf: Rendering Performance Case Studies
addyosmani
317
22k
BBQ
matthewcrist
75
8.1k
4 Signs Your Business is Dying
shpigford
171
20k
Building Better People: How to give real-time feedback that sticks.
wjessup
346
17k
Creatively Recalculating Your Daily Design Routine
revolveconf
207
11k
Transcript
パーマーステーションの ペンギンたち #1 Tokyo.R #99 (2022/06/04) @bob3bob3 Artwork by @allison_horst
パーマーステーションのペンギンたち Rには様々なサンプルデータセットが用 意されているのもいいところ。 その中でもpalmerpenguinsパッケージの データセットが練習用、学習用にちょう ど良いので紹介したいというお話。 とりあえず、いますぐ install.packages("palmerpenguins") しましょう! Artwork
by @allison_horst
どう良いの? • ペンギンがかわいい。 • 整形済みのデータと整形前のデータの両方がある。 • 名義尺度と連続尺度の両方の変数が含まれる。 • 名義尺度の変数が複数含まれる。 •
連続尺度の変数も複数含まれる。 • 欠測値(NA)が含まれる。 • 日時の変数が含まれる。 • ペンギンがカワイイ。
palmerpenguinsパッケージ 南極にある米国の越冬基地パーマー基地において Kristen Gorman 博士が行ったペン ギンの生態調査のデータセットです。 引用元 引用元
引用元
引用元
トージャーセン島 引用元 Cynthia Spence (CC BY-NC-ND 4.0) トージャーセン島から眺めるパーマー基地 Cynthia Spence
(CC BY-NC-ND 4.0)
引用元
引用元 IMDb パーマー基地が舞台となる日本映画
どんなデータ? • 2007年、2008年、2009年の3回の調査(越冬隊?)。 • ビスコー諸島、ドリーム島、トージャーセン島の3か所。 • アデリーペンギン、ヒゲペンギン、ジェンツーペンギンの3種のペンギン。 • 嘴の長さ、高さ、翼の長さ、体重、性別、血液検査の結果などが含まれる。 アデリー(Adelie)
ジェンツー(Gentoo) ヒゲ(Chinstrap) Stan Shebs (CC BY-SA 3.0) Andrew Shiva(CC BY-SA 4.0) Stan Shebs (CC BY-SA 3.0)
アデリーペンギン Wikipediaより引用 • くちばしの根元から先端近くまで羽毛でおおわ れているのも特徴で、くちばしが短いように見え るが、口を開けると目の前まで開く。これは南極 の厳しい寒さに適応した結果羽毛が無い部分が 少なくなったと考えられる。
• また、他のペンギンに比べて尾羽が長いが、こ れはヒゲペンギン、ジェンツーペンギンにも共通 する特徴である。ペンギンの分類ではこの3種類 をまとめてアデリーペンギン属(Pygoscelis属)と して扱う。 • Suicaのペンギンのモデル。 Jerzy Strzelecki(CC BY 3.0)
ヒゲペンギン Wikipediaより引用 • 目の後ろから喉を通る黒い帯模様が あるのが特徴である。和名の「ヒゲペ ンギン」は喉を通る帯模様をあごひげ に見立てたものである。また、英名 の"Chinstrap"は帽子やヘルメットの あごひものことで、これもやはり喉を 通る帯模様に由来している。
引用元
ジェンツーペンギン Wikipediaより引用 • 両目をつなぐ白い帯模様が特徴であ る。 • 大きさはペンギン18種類のうち、コウ テイペンギン、キングペンギンに次い で3番目に大きい。また、オスの方がメ スよりわずかに大きい。更に、ペンギ
ンで最も泳ぐのが速いペンギンでもあ る。最高時速は時速35kmにも達す る。 Ben Tubby(CC BY 2.0)
2つのデータセット penguins_raw 生のデータ • 17変数 • studyName: 研究名(越冬隊ごと?) •
Sample Number: 標本番号(連番) • Species: ペンギンの種(学名付き) • Region: 調査した地域 • Island: 調査した島 • Stage: 発育段階 • Individual ID: 個体ID • Clutch Completion: 巣の完成度 • Date Egg: 巣に1個以上の卵が確認された日? • Culmen Length (mm): くちばしの長さ • Culmen Depth (mm): くちばしの高さ • Flipper Length (mm): 翼の長さ • Body Mass (g): 体重 • Sex: 性別 • Delta 15 N (o/oo): 窒素同位体比(δ15N) • Delta 13 C (o/oo): 炭素同位体比(δ13C) • Comments: コメント penguins 使いやすく加工されたデータ • 8変数 • species: ペンギンの種 • island: 調査した島 • bill_length_mm: くちばしの長さ • bill_depth_mm: くちばしの高さ • flipper_length_mm: 翼の長さ • body_mass_g: 体重 • sex: 性別 • year: 調査した年 Artwork by @allison_horst
とりあえず生データを確認 library(palmerpenguins) penguins_raw |> head(10) |> View()
サマリーを確認 library(summarytools) penguins_raw |> dfSummary() |> view() • 欠測値(NA)がある。 •
値がすべて同じ列がある。 • 同じ個体IDが3回出現している。
変数間の関係の概要 penguins_raw |> dplyr::select( #余分な変数を除外 !c( `Sample Number`, Region, Stage,
`Individual ID`, Comments ) ) |> GGally::ggpairs( aes(colour = Species), title = "Palmer Penguins Raw" )
変数間の関係の概要 penguins_raw |> dplyr::select( #余分な変数を除外 !c( `Sample Number`, Region, Stage,
`Individual ID`, Comments ) ) |> GGally::ggpairs( aes(colour = Species), title = "Palmer Penguins Raw" ) Date Egg x studyName と Species x Island が気になる。
研究名ごとの期間 penguins_raw |> group_by(studyName) |> summarise(Start = min(`Date Egg`), End
= max(`Date Egg`)) # studyName Start End # <chr> <date> <date> #1 PAL0708 2007-11-09 2007-12-03 #2 PAL0809 2008-11-02 2008-11-25 #3 PAL0910 2009-11-09 2009-12-01
調査した島と生息するペンギンの種 penguins_raw |> xtabs(~ Species + Island, data = _)
# Island #Species Biscoe Dream Torgersen # Adelie Penguin (Pygoscelis adeliae) 44 56 52 # Chinstrap penguin (Pygoscelis antarctica) 0 68 0 # Gentoo penguin (Pygoscelis papua) 124 0 0
「オスの方がメスよりわずかに大きい」? penguins_raw |> drop_na(Sex) |> ggplot(aes(x = Sex, y =
`Body Mass (g)`)) + geom_violin(aes(colour=Sex, fill = Sex)) + geom_boxplot(width = 0.3) + geom_jitter(width = 0.15, height = 0) + facet_wrap(vars(Species)) + labs( title = "性別と体重", x = "性別", y = "体重 (g)", colour = "性別", fill = "性別" ) + theme(text = element_text(size = 18))
to be continued... 今後の予定: 1. データセットの紹介(今回) 2. データクリーニング ◦ penguins_rawからpenguinsへ
3. 可視化例 4. 分析例 ◦ シンプソンのパラドクス ◦ 次元縮約 ◦ クラスタリング ◦ 判別モデル ◦ などなど いらすとやにはアデリーペン ギンがいなかった…… タイトルの「パーマーステーションのペ ンギンたち」は『ウォーターシップダウ ンのウサギたち』をもじったつもり。