SlideShare a Scribd company logo
Rstudioによるデータハンドリング
(データ集計・データ可視化)
のご紹介
2017年11月27日
http://www.truestar.co.jp/
自己紹介
1
学部時代は西洋近代史を学ぶ
好きな歴史上の人物はユリウス・カエサル
2017年3月 筑波大学
ビジネス科学研究科 経営システム科学専攻
(修士課程・夜間)修了
現在,同大学院の博士課程在籍中
現在,truestarにおいて,広告投資と売
上の関係を説明する新しい方法を検討中
truestar
鈴木 貴士
本日の流れ
2
なぜRを使うのか
総務省 家計調査を用いたRによる
データハンドリングのデモ
年明け以降のセミナーの概要
アンケート記入と質疑応答
なぜデータハンドリングが必要か
本日の流れ
3
なぜRを使うのか
総務省 家計調査を用いたRによる
データハンドリングのデモ
年明け以降のセミナーの概要
アンケート記入と質疑応答
なぜデータハンドリングが必要か
Rとは何でしょう?
4
• 統計分析向けプログラミング言語
無料
Rあれこれ
5
Rの本体。これだけでも十分使用可能
Rコマンダー
「R本体」
Rの統合開発環境。Rを使いやすくする
通常はRstudioを用いる
プログラミング無しでRの一部機能を
使えるようにしたソフト
R
6
Rの本体。これだけでも十分使用可能
無料
Rコマンダー
7
プログラミング無しでRの一部機能を使えるようにした
パッケージ
無料
RStudio
8
Rの統合開発環境。Rを使いやすくする
通常はRstudioを用いる
無料
なぜRを使うのか
9
データ分析に使いたいから
なぜRを使うのか
10
• 多様な統計分析をおこなえる
• 集計・作図のプロセスもおこなえる
• プログラムコードを残せるため,再現性がある
• 高機能にも関わらず無料で使うことができる
• 日本語で情報が取得できる
なぜRを使うのか①:多様な統計分析をおこなえる
11
• 日々世界中で新たなパッケージが開発され,Rの機能
は進化し続けている(Rは統計分析のスタンダード)
多種多様な統計分析をおこなうことができる
なぜRを使うのか②:集計・作図のプロセスもおこなえる
12
• データ分析の工程の6~8割はデータの「集計」「可視化」といっ
たデータハンドリングのプロセス
Rは「集計」「可視化」も得意(後ほどデモいたします)
Rを使えば,全工程含めた一気通貫したデータ分析が可能
データ
集計
データ
可視化
統計
分析
• データ分析の流れ
なぜRを使うのか③:再現性・繰り返しに強い
13
• Rはプログラミングコードを残せる
繰り返しに強い
データを入れかえれば,他の分析に流用できる
分析ミスがあった場合に追跡可能
データ
集計
データ
可視化
統計
分析
• 実際のデータ分析は繰り返し
が多数起こるため,上記は
非常に大切
データが間違っていた
データ範囲を変えて再分析
同じ形式のデータが毎月来る
なぜRを使うのか④:高機能にも関わらず無料で使うことができる
14
• 統計分析ソフトで有名なIBM「SPSS」の価格は数十万円
• Rは無料なので,機能追加があっても問題なし
SPSSは更新に費用がかかる
• Rは無料だが,信頼性は問題ない
オープンゆえに,間違いがあったらすぐに修正される
新パッケージの場合は検証が不十分という面も…
学術論文にも多数使用されている
なぜRを使うのか⑤:日本語で情報が入手できる
15
http://cse.naro.affrc.go.jp/takezawa/r-
tips/r.html
• Rは統計分析におけるスタンダードな存在なので,日本語
書籍・ウェブ情報が豊富
なぜRを使うのか:R以外のソフトウェアは?
16
R SPSS Excel
価格 数十万円~ 1万円
操作方法
学習コスト △ ○ ◎
データ前処理・図示化 ◎ △ △
統計分析 ◎ ○ ×~△
プログラミング
無料
マウス操作
• 複雑な分析や繰り返し処理をしないなら「Excel」
• ある程度複雑な分析をおこないたいが,プログラミングは
避けたいなら「SPSS」
• 分析に留まらずシステム開発も含めるなら「python」
本日の流れ
17
なぜRを使うのか
総務省 家計調査を用いたRによる
データハンドリングのデモ
年明け以降のセミナーの概要
アンケート記入と質疑応答
なぜデータハンドリングが必要か
データ分析の流れ
18
データ
集計
データ
可視化
統計
分析
提言
• データ分析の工程の6~8割はデータの「集計」「可視化」と
いったデータハンドリングのプロセス
普通,興味があるのは「提言」と「統計分析」
けれども…
Rで学ぶ○○に書いてあること
19
• Rで学ぶ○○という本はデータハンドリングができることが前提
データ
集計
データ
可視化
統計
分析
提言
統計分析と提言だけに興味がある場合にありがちなプロセス
20
Rによるデータハンドリングを身に着ければ上記は避けられる
Rで「重回帰分析」をしたい!
Rによる「重回帰分析」の
やり方(のみ)を覚える
Rで重回帰分析
データをExcelで加工
結果をExcelへコピペ
○回
繰り返し
疲弊・
ミス
本来あるべきデータ分析の流れ①
21
データ
集計
データ
可視化
統計
分析
提言
• 手元に集まったデータは「整理されていない」「複数ファイルに
分散している」場合が普通なので,データ分析ができる形
式に整える必要がある
本に載っているサンプルデータの場合は初めからデータが整ってお
り,省かれるプロセス
本来あるべきデータ分析の流れ②
22
データ
集計
データ
可視化
統計
分析
提言
• 手元に集まったデータの関係性を把握するには数字を見るだ
けでは分からないので,グラフにして可視化する必要が
• この段階でデータの異常に気づくことが多いので,欠かせない
プロセス
本に載っているサンプルデータの場合は省かれるプロセス
私がデータを触っていた時の実例
23
【コンビニ商材のCM出稿量と売上の関係を分析していた時】
• ある時期からCM出稿量がゼロになっていたが,商品リ
ニューアルによって,商品コードが変わっただけで,Aビー
ルのCM出稿がなくなった訳ではなかった
0
100
200
AビールのCM出稿量
クライアントにデータを貰い直し,データ集計からやり直し
本来あるべきデータ分析の流れ③
24
データ
集計
データ
可視化
統計
分析
提言
• データ集計・可視化をおこない,データについて理解を深め
てから統計分析へ移る
• 本に載っているサンプルデータの場合はデータが正しいことが
前提なので,初めからここから
本来あるべきデータ分析の流れ④
25
データ
集計
データ
可視化
統計
分析
提言
• 統計分析を元に,「提言」をおこなう
Excelでデータハンドリングをおこなって,Rで分析するのは?
26
データ
集計
データ
可視化
統計
分析
提言
• 簡単な処理が数回程度ならExcelでも構わない
それが何十回・何百回となると…?!
• Excelで扱えるデータは100万行まで
Rは100万行以上のデータを扱える
Rで一気通貫したデータ分析をおこないましょう!
Rによるデータハンドリングを身につければ
27
• データ集計・データ可視化をRプログラミングによっておこなう
ことで,正確性が増すと共に生産性が向上
• Rプログラミングスキルが向上するので,新しい統計分析の
実装が早くなる
統計分析は手法ごとに必要なデータ構造や方法が異なる
Rによるデータハンドリングを身につけましょう
本日の流れ
28
なぜRを使うのか
総務省 家計調査を用いたRによる
データハンドリングのデモ
年明け以降のセミナーの概要
アンケート記入と質疑応答
なぜデータハンドリングが必要か
総務省・家計調査データとは?
29
• 皆様に事前に配布したデータをExcelで開いてください
開いた後に,Excel形式で保存し直してください。
• 総務省・家計調査とは?
全国の家計の収入・支出、貯蓄・負債などを毎月調査している
県庁所在地+政令指定都市の物品の年間支出金額が
わかる
総務省・家計調査データとは?
30
都市別
品
目
まずはExcelでデータハンドリングを体験
31
【お題①】
•あなたは「宇都宮市」の観光課の職員です
•「ぎょうざ」を観光に活かしたいと考えています
•そこで,「家計調査」掲載都市の「ぎょうざ」購入金
額をグラフ化し,「宇都宮市」の立ち位置を把握し
てください
Excelでやってみましょう!
グラフのイメージ
32
(円)
Q:「家計調査」掲載都市の「ぎょうざ」購入金額をグラフ化
し,「宇都宮市」の立ち位置を把握してください
0
500
1,000
1,500
2,000
2,500
3,000
45201宮崎市
26100京都市
25201大津市
08201水戸市
21201岐阜市
41201佐賀市
29201奈良市
10201前橋市
11100さいたま市
22100静岡市
32201松江市
46201鹿児島市
27100大阪市
28100神戸市
27140堺市
13100東京都区部
19201甲府市
31201鳥取市
33100岡山市
38201松山市
14130川崎市
全国
15100新潟市
07201福島市
36201徳島市
14100横浜市
04100仙台市
20201長野市
18201福井市
42201長崎市
30201和歌山市
16201富山市
43100熊本市
06201山形市
47201那覇市
34100広島市
12100千葉市
02201青森市
39201高知市
24201津市
40130福岡市
37201高松市
23100名古屋市
14150相模原市
40100北九州市
17201金沢市
03201盛岡市
35203山口市
01100札幌市
44201大分市
05201秋田市
371 ぎょうざ【円】
「ぎょうざ」の購入金額1位の都市は・・・!?
33
•「宇都宮市」はごくわずかに及ばず「浜松市」が1位
0
500
1,000
1,500
2,000
2,500
3,000
3,500
4,000
4,500
5,000
22130浜松市
09201宇都宮市
45201宮崎市
26100京都市
25201大津市
08201水戸市
21201岐阜市
41201佐賀市
29201奈良市
10201前橋市
11100さいたま市
22100静岡市
32201松江市
46201鹿児島市
27100大阪市
28100神戸市
27140堺市
13100東京都区部
19201甲府市
31201鳥取市
33100岡山市
38201松山市
14130川崎市
全国
15100新潟市
07201福島市
36201徳島市
14100横浜市
04100仙台市
20201長野市
18201福井市
42201長崎市
30201和歌山市
16201富山市
43100熊本市
06201山形市
47201那覇市
34100広島市
12100千葉市
02201青森市
39201高知市
24201津市
40130福岡市
37201高松市
23100名古屋市
14150相模原市
40100北九州市
17201金沢市
03201盛岡市
35203山口市
01100札幌市
44201大分市
05201秋田市
371 ぎょうざ【円】
(円)
「ぎょうざ」の購入金額1位の都市は・・・!?
34
•「宇都宮市」はごくわずかに及ばず「浜松市」が1位
0
1,000
2,000
3,000
4,000
5,000
浜松市 宇都宮市 全国
371 ぎょうざ【円】(円) ※ぎょうざの
「購入金額」なので,
外食費は
含んでいません。
まずはExcelでデータハンドリングを体験
35
【お題②】
•「ぎょうざ」を観光に活かしたいと考えていましたが,
購入額1位は「浜松市」でした
•そこで,観光に活かせる品目を探さねばなりません
•各都市の中で「宇都宮市」がトップテンに入る品目
をグラフ化してください
•Excelでやってみましょう!
お疲れ様でした
36
•○分間の時間を取りましたが,いくつできたでしょう
か?
•宇都宮市がベスト10に入る品目は692品目中
121品目あるので,全て終わる時間を計算してくだ
さい
•同じ作業を繰り返すことは非常に大変
•もし,作業後にデータ差し替えなどがあったら?
Rで同じことをやるには
37
•「dplyr」と「ggplot2」というパッケージを使用
•コードを書くのに合計30分使用
R実行
Rでデータ整形およびグラフによる可視化
38
•「dplyr」というパッケージでデータ整形をおこなった後
「ggplot2」というパッケージでグラフによる可視化
できたグラフを見ていきましょう
Rでデータ整形およびグラフによる可視化:「いちご」
39
Rでデータ整形およびグラフによる可視化:「いちご」
40
VBAでプログラムを書けば良いのでは?
41
•Rでデータ集計・可視化をおこなえば,「統計分析」
まで一気通貫して処理をおこなえる
わざわざVBAでデータハンドリングをおこなった後,
Rで統計分析をおこなうのではなく,初めからRで
やった方が効率が良い
例えば,クラスター分析を実行
42
クラスター分析で各都市をグルーピングしたところ,
宇都宮市に最も近いのは前橋市という結果に
100万行を超えるビッグデータもRで処理可能
43
•Excelでは100万行までしか開けないですが,
Rでは100万行を超えるデータも扱えます
•実際に500万行のファイルを開いてみると…
デモを通じてわかったこと
44
• データ集計・データ可視化をRプログラミングによっておこなう
ことで,正確性が増すと共に生産性が向上
• Rプログラミングスキルが向上するので,新しい統計分析の
実装が早くなる
統計分析は手法ごとに必要なデータ構造や方法が異なる
Rによるデータハンドリングを身につけましょう
本日の流れ
45
なぜRを使うのか
総務省 家計調査を用いたRによる
データハンドリングのデモ
年明け以降のセミナーの概要
アンケート記入と質疑応答
なぜデータハンドリングが必要か
年明け以降のセミナーの概要
46
セミナー当日は説明
本日の流れ
47
なぜRを使うのか
総務省 家計調査を用いたRによる
データハンドリングのデモ
年明け以降のセミナーの概要
アンケート記入と質疑応答
なぜデータハンドリングが必要か
質疑応答など
48
アンケートのご協力をお願い申しあげます
本日はありがとうございました

More Related Content

Featured

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
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
Albert 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 Insights
Kurio // 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 2024
Search 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 summary
SpeakerHub
 
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 Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit 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 management
MindGenius
 
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 Work
GetSmarter
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
Alireza Esmikhani
 
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
Project for Public Spaces & National Center for Biking and Walking
 

Featured (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
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
 

なぜRでデータハンドリングが必要なのか

Editor's Notes

  1. 言語ではなく,環境・ツールという話もあるけれど,ここでは言語としておきます
  2. 実際のところ,692品目全てを把握することは少なく,ベスト10とかワースト10を抽出して,という方法になる