Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Try-R-jp
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Takahiro Sumiya
March 01, 2019
Education
150
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Try-R-jp
Takahiro Sumiya
March 01, 2019
More Decks by Takahiro Sumiya
See All by Takahiro Sumiya
DME-20260710
gnutar
0
23
卒論・修論執筆における生成AI 活用とAI 不安:広島大学での実態調査 (3)/CE185
gnutar
0
39
生成AI活用セミナー/GAI-workshop
gnutar
0
210
GAI-FD2025
gnutar
0
140
卒論・修論執筆における生成AI 活用とAI 不安:広島大学での実態調査 (2)/CE180
gnutar
0
97
大学教育現場と著作権/DME-2025-06-04
gnutar
0
100
著作権と授業に関する出前講習会/dme-2025-05-01
gnutar
0
290
Excelグラフはどうしてダサいのか/csd2024-3-sumiya
gnutar
1
400
出前講習会-西海市教育委員会/DME-2025-02-10
gnutar
0
140
Other Decks in Education
See All in Education
Réunion des directrices et directeurs des écoles de la circonscription de Jonzac - 31 août 2026
fmarot
0
140
学生のうちに考えておきたい信頼の話
suisan
1
800
Beyond the Prompt: Programming as a Pathway to Statistical Thinking
minecr
0
390
Visionary Initiative: Materials-Positive Society — Evolving “Things,” empowering a positive society | Science Tokyo
sciencetokyo
PRO
0
270
武藤の処世術を書いてみた
mutomasa
0
120
25-26 CBT Library top items
cbtlibrary
0
290
AIってなぁに?
kenichiota0711
0
840
Visionary Initiative: Future Intelligence — Laying the foundations for the future of science, intelligence, and society | Science Tokyo
sciencetokyo
PRO
0
330
批判的応用言語学ワークショップ(2026-08-12 お茶の⽔⼥⼦⼤学)
terasawat
0
200
Comentario del plano urbano de Madrid hasta 1860 (1ª parte )
juanmartin2026
1
87k
AIでアウトプットできる時代だからこそ、自分の言葉で考えることの大切さ / What's Left to Think, When AI Can Write?
masakiokuda
1
330
sepm-training-sample
levii
0
240
Featured
See All Featured
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
280
AI Search: Where Are We & What Can We Do About It?
aleyda
0
8k
Faster Mobile Websites
deanohume
310
32k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
5
710
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
Embracing the Ebb and Flow
colly
88
5.2k
A Modern Web Designer's Workflow
chriscoyier
699
190k
Crafting Experiences
bethany
1
350
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
Exploring anti-patterns in Rails
aemeredith
4
510
Building an army of robots
kneath
307
46k
Transcript
F3S講習会 統計データ処理ツールを使ってみよう (R入門) 広島大学情報メディア教育研究センター 隅谷孝洋
‣ R is a language and environment for statistic computing
and graphics [Rとは、統計計算と統計グラフのための 言語であり、(実行)環境である。] https://www.r-project.org/about.html
Γ͍ͨ͜ͱ ॲཧखॱ ʢΞϧΰϦζϜʣ 1: int main(int argc,char 2: int i=0;
3: char c; 4: while(i==0){ 5: c=getchar(); ϓϩάϥϜ ࣮ߦʂ (プログラミング)言語 (実行)環境
本日のメニュー 1. Rの準備 2. コマンドの投入と結果の表示 3. Excelのデータの読み込み 4. データの要約 5.
データの視覚的な確認 6. いくつかの統計分析手法を使ってみる
1. Rの準備
Rの準備 ‣ R ✓ R実行環境 ✓ これだけでも利用可 ‣ RStudio ✓
Rの(もっと便利な)実行環境 ✓ 普段はこちらを利用 ʴ
Rのインストール https://www.r-project.org/about.html (日本のミラーサイトを選択) $3"/ͷαΠτ Download R for (Mac)
OS X → R-3.5.1.pkg (最新版) Download R for Windows → Install R for the rst time → Download R 3.5.1 for Windows
RStudio のインストール https://www.rstudio.com (下の方までスクロールして...) RStudio 1.1.463 - Windows
Vista/7/8/10 RStudio 1.1.463 - Mac OS X 10.6+ (64-bit)
RStudioを起動してみる νΣοΫʂ
2. コマンドの投入と結果の表示
まずは、ここに 入れてみましょう
電卓として使う ‣ 式を打ち込んでみよう > 1+1 > 100/3 > 100/3*3 ‣
かっこも使える > (3+5)*7 > 3+5*7 # 結果が違う
Rのコマンドをファイルとして残しておこう ‣ 「プロジェクト」を作ると、一連のファイル をひとまとめにしやすい ✓ 命令(コマンド)を記したファイル ✓ データファイル ✓ 結果のグラフ
‣ File → New Project → New Directory → New Project
Rのコマンドをファイルとして残しておこう ‣ File→New File→R Script ίϚϯυΛ ॻ͍ͯɺ DUMFOUFS
݁Ռ ͪ͜Βʹग़Δ
高級な電卓として使う ‣ ベキ乗 ^ とか > 2^16 ‣ 関数とかも使える >
sin(pi/2) # > exp(1) # > factorial(10) # > choose(5,2) # sin ⇡ 2 10! 5C2 e1
グラフを描いてみよう > plot(c(5,5,4,3,3,4,1,1,1)) > x=c(5,4,3,3,1,4,1,1,1) # 変数に代入 > plot(x) #
スッキリ > plot(x,type="b") # これ、何のデータ? > plot(x,type="b",ylim=c(6,1)) > yr=2010:2018 > plot(yr,x,type="b",ylim=c(6,1))
Rでは、変数(オブジェクト)の中身の基本はベクトル > x # 変数名のみ入れると内容の表示 > x+10 # 数学のベクトルとは違う >
x+c(10,100) # 長さが違うものを足すと? > x[1] # 最初の数値を取り出す > x[c(1,3,5)] # 1,3,5番目を取り出す
一度終了して、再び開いてみよう ‣ コマンドファイルに名前をつけて保存 ‣ RStudio の終了 ‣ フォルダ内のファイルの確認 ‣ プロジェクトファイルをダブルクリックし
て再起動
3. Excelデータの読み込み
Excelのデータは、CSVにして読み込み ‣ Bb9から"carp.xlsx"をダウンロード ‣ Excelで開いて内容を確認 ‣ CSV (UTF-8) で保存 →
carp.csv ‣ Windowsの人は「CSV」で保存
CSVファイルを読み込むと「データフレーム」ができる > read.csv("carp.csv") # 画面に出ちゃう > c=read.csv("carp.csv") # 変数cに保存 >
c # 読めたか確認 ‣ 「データフレーム」は、名前がついたベクト ルの集まり > c$身長 # 「身長」という名前の列 > c$身長[3] # その三番目の値 > mean(c$身長) # 身長の平均
データフレーム(続き) > c$BMI=c$体重/(c$身長/100)^2 # BMI を計算 > c[c$BMI>30,] # BMI
が30より大きい選手 BMI = Weight(kg) Height(m) 2
おまけ1:こんなのもあります Excelのファイルを直接読み込む ‣ install.packages("readxl") ‣ library(readxl) ‣ carp=read_excel("carp.xlsx",1) ‣ dragons=read_excel("carp.xlsx",2)
4. データの要約
summary という関数が便利 ✓ summary(c) ‣ 数値データ ✓ Min(最小値),1st Qu.(第1四分位 点),
Median(中央値), Mean(平 均), 3rd Qu. (第3四分位点), Max(最大値) ‣ カテゴリーデータ ✓ 頻度
グループの要約 > # BMIが26より大きい選手のsummary > summary(c[c$BMI>26,]) > # ポジションごとの身長のsummary >
tapply(c$身長,c$ポジション,summary)
5. データの視覚的な確認
度数分布図、散布図、箱ヒゲ図 > hist(c$身長) ‣ Macの人...化けていますね orz > # ヒラギノ角ゴシックをW3使うように指定 >
par(family = "HiraKakuProN-W3") > hist(c$身長)
気を取り直して、度数分布図、散布図、箱ヒゲ図 > hist(c$身長) # 度数分布図 > barplot(table(c$ポジション)) > plot(c$身長,c$体重) #
散布図 > plot(c) # 散布図行列 > plot(c[,c(4,5,6,9)]) > boxplot(c$身長) # 箱ひげ図 > boxplot(c$身長[c$ポジション=="投手"], c$身長[c$ポジション!="投手"], names=c("投手","それ以外"),ylab="身長")
おまけ2:こんなのもあります 心理学研究用パッケージ > install.packages("psych") > library(psych) > pairs.panels(c[,c(4,5,6,9)])
ググって描いてみよう (1)
ググって描いてみよう (2)
6. いくつかの統計分析手法を使ってみる
線形回帰 > plot(c$体重 ~ c$身長) > result=lm(c$体重 ~ c$身長) >
abline(result) > summary(result)
左利きが多いのか? 世間一般の左利き率が0.1として、二項検定をおこなってみる > summary(c$投) > binom.test(13,13+56,0.1) > cp=c[c$ポジション=="投手",] > summary(cp$投)
> binom.test(11,11+23,0.1)
Rのメリット ‣ 統計計算に特化 ‣ グラフがキレイ ‣ コマンド(=テキスト情報)でやったこと が残るので、再現が簡単 ‣ 新しい手法がどんどん実装される
‣ 無料!オープンソース