SlideShare ist ein Scribd-Unternehmen logo
1 von 25
再現可能性ベストプラクティス
解析方法とレポート作成方法の
再現可能性
RとRStudioとR Markdownを通して
高橋康介
(中京大学心理学部)
理論的(統計的)な再現可能性
QRPs レビューつきプレレジ
再現可能性=理論的(統計的)な再現可能性 × 実践的な再現可能性
実践的な再現可能性
実験環境の多様性
アドホックなデータ解析
実験環境の統制
再現可能なデータ解析
共立 Wonderful R: RR本の紹介
再現可能性のすゝめ―RStudioによるデータ解析とレポート作成―(仮)
1. なぜ再現可能性?
• たこ焼き屋ジョンの苦悩
2. RStudio入門
3. 再現可能なデータ解析プラクティス
4. Rマークダウンの導入
5. Rマークダウンの応用
• flexdashboard / htmlwidgets / bookdown
6. 再現可能性を高める
• Git / パッケージ環境の再現(packrat)
7. RStudioを使いこなす
Wonderful R 第3弾として5月くらいに刊行予定
データ解析とレポート作成
• 入力
• 実験データ・調査データ・さまざまなログなど
• 出力
• ミーティング用の資料
• プレゼン資料
• 報告書・論文
• 究極の目標は「入力→出力」の変換を再現可能にすること。
→「結果(できたモノ)を残す」のではなく
「手順(やったこと)を残す」
入力
出力
データ解析とレポート作成
• データをエクセルで加工・整形
• 被験者数分のシート!
• グラフはどこ?このグラフ何?
• Rのコンソールで解析
• エクセルからコピペ
• 自分でもなにをやったからこうなったのかわからない
• 結果・グラフをワード・パワポにコピペ
• このグラフでいいのか?
入力
出力
メリット
• 信頼性向上
• どこでもだれでもいつでも同じデータから同じ結果を。
• 間違いの検証
• レポートの中の間違い・怪しい点をあとから追跡可能。
• 作業効率の向上
• 再現可能化=自動化。
• (リバイズ対応)
• 追加解析など、めっちゃ楽。
※どこからどこまでが再現可能なのか常に意識する
使うべきツール
• R:統計解析環境
• RStudio:Rを使いやすくする環境
• Rスクリプト:解析手順を記述したレシピ
• Rマークダウン:Rスクリプト+ドキュメント
• knitr:Rマークダウンの中で働くやつ
RStudioの導入
• 現在ではRのGUI環境のデファクトスタンダードだと思
われる。
• ユーザが多い→情報が多い・開発がアクティブ
• ColdFusionのJJ Allaire(凄腕プログラマ)が率いる。現在では
HadleyやYihuiも参加。
• メリット
• プロジェクトという概念の導入
• 再現可能性に関するさまざまな便利機能を使うことができる
• デメリット
• なし(UIが英語)
プロジェクト
• 必須というわけではないが、絶対に使うべき。
• タスクに関連するファイル類・セッションをプロジェクト
ごとに独立に扱うことができる。「1料理」=「1台所」
• 新しいタスク→新しいプロジェクト
• 実験(研究ではない)ごとにプロジェクト
• 実験1と実験2は別プロジェクト
• 比較分析が必要なときは別途対応
プロジェクトA
• ファイル類
• データ
• 解析スクリプト
• アウトプット
• Rセッション
• 変数
• 関数定義
• パッケージ環境
プロジェクトB
• ファイル類
• データ
• 解析スクリプト
• アウトプット
• Rセッション
• 変数
• 関数定義
• パッケージ環境
プロジェクトC
• ファイル類
• データ
• 解析スクリプト
• アウトプット
• Rセッション
• 変数
• 関数定義
• パッケージ環境
再現可能な解析処理
• 「結果を記録」から「手順を記録」へ。
• RスクリプトまたはRマークダウンの導入
• 手作業+確認+スクリプト化(マークダウン化)
• 目による確認は厳禁
• 頻繁な正当性チェック(≠内容チェック)
• データの行数・欠損値・列名・符号・などなど
再現可能な解析処理:基本的な作
業ルーチン(パターン1)
1. 必要な処理を実行するコマンドをコンソールに
入力して実行する (手作業)。
2. 結果を確認する (目作業)。
3. 欲しい結果が得られるまで、コマンドを修正し
て実行する (コマンド履歴を活用)。
4. 問題なければ、そのコマンドをRスクリプト・R
マークダウンに記録する (コピペなど)。
5. 1に戻る
再現可能な解析処理:基本的な作
業ルーチン(パターン2)
1. 必要な処理を実行するコマンドをRスクリプト・
Rマークダウンに記述する (手作業)。
2. 必要な箇所のコードを実行する (実行補助機能を
活用)。
3. 結果を確認する (目作業)。
4. 欲しい結果が得られるまで、コマンドを修正す
る。
5. 問題なければ、次のコマンドの記述に進む。
データ読み込み
• データソース
• 実験データ・調査データなど。frozen(編集しない)
• PsychoPyならtrial csvが↓の入力データとしてそのまま使える。
• 入力データ
• Rで読み込めるデータ
• 基本は2次元の表形式x複数ファイル
• Matlabの.mなども可(Rで扱える)。
• データソース→入力データ
• 可能な限り自動化(外部ツールなどでもいいので、とにかく自動化)
• 手作業をルーチン化する前に、あらゆる努力を(土下座も含む)。
データ読み込みプラクティス
• RStudioのインポート機能はコード生成に使う(実際には使わない)
• 同じ形式の大量のデータを読み込みたい
余談・研究データとtidy data
• 作成するデータは2次元表形式に。
• 1観測=1行
• 1試行1行(実験)、1サンプル1行(調査)
• Tidy data
大学 文系 理系
A大学 45 55
B大学 65 75
Tidyではないデータ
大学 文理 偏差値
A 文 45
A 理 55
B 文 65
B 理 75
Tidyデータ
http://id.fnshr.info/2017/01/09/tidy-data-intro/
解析:こまめにデータの妥当
性を確認する
• データを目で眺めることは無意味。
• 安心したいということなら止めないけど時間の無駄。
• 内容の確認ではなく形式の正当性チェック
• 行数・型・欠損値・範囲・などなど
• データ要約を駆使する。
• str, head, names, dim: データの構造
• summary, range, table: データの要約
• くわしくはRR本で。
画像保存・結果保存
• 全てファイルに保存すること。「自動化」すること。
• 結果をパワポ・ワードにコピペ、RStudioの手動エクスポート→NG
• 画像保存
• cairo_pdf / jpeg などお好みで。
• Rマークダウンの場合、自動的にファイルに残るが、論文用のグラフな
どは明示的に保存しておくほうがわかりやすい。
• 結果保存
• Rマークダウンの場合:出力しておけばよい。
• 表:knitr::kable
• 統計量:print / broom::tidy
• くわしくはRR本で。
R Markdownの導入
• 従来のレポート
• ドキュメントに解析結果(図・表・統計)をコピペ
• 再現可能型レポート
• ドキュメントと解析コード→自動変換→レポート
R Markdownでどこまでやるか
• レポート中のデータ・ドキュメント比がひとつの目安
• データの割合が大きいほど有効
• ミーティング資料などには圧倒的に便利
• 学会プレゼン・論文はちょっと厳しいかも
• 不可能ではないし、使ったほうが再現性は高い
• 面倒が多い(レイアウト・デザイン・リファレンス)
• DD比が小さい(データが締める割合が小さい)
• やり過ぎると効率を落とすことになるので、柔軟に対応しましょう。
Rマークダウン最速入門
1. Rマークダウンファイル (.Rmd) の新規作成。
2. メタ情報の編集。
3. ドキュメントとコードの編集。
4. レポート生成コマンドの実行。
• 3と4を、先程紹介したルーチンで繰り返す。
実演でやります。
Rマークダウン補足
1. 表はkableまたはDT::datatableで。
2. 外部画像はknitr::include_graphicsが吉。
3. 重要なチャンクオプションを知っておく
1. echo, include など。自分の使い方に合わせて。
表
• 小さい表ならknitr::kableが便利
• 大きめかつHTML対応ならDT::datatable
• 細かいことは気にしない。
再現可能性ベストプラクティス
• 再現可能なデータ解析
• とにかく1実験(調査)=1プロジェクト。
• 目で確認より要約関数。形式の正当性チェックを頻繁に。
• 再現可能なレポート作成
• まずはRマークダウンを作成。
• クリーンな環境でのテストを頻繁に。
• 再現可能性の維持
• 手作業を排除する。データが増えてもコードの修正を不要に。
• 完璧を目指しすぎず、再現可能性を徐々に高める。
理論的(統計的)な再現可能性
QRPs レビューつきプレレジ
再現可能性=理論的(統計的)な再現可能性 × 実践的な再現可能性
実践的な再現可能性
実験環境の多様性
アドホックなデータ解析
実験環境の統制
再現可能なデータ解析
森としての再現可能性
木としての再現可能性

Weitere ähnliche Inhalte

Empfohlen

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellSaba Software
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming LanguageSimplilearn
 

Empfohlen (20)

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
 

再現可能性ベストプラクティス  解析方法とレポート作成方法の再現可能性  RとRStudioとR Markdownを通して