HiRoshima.R #2 入門者講習資料
Upcoming SlideShare
Loading in...5
×
 

HiRoshima.R #2 入門者講習資料

on

  • 1,130 views

 

Statistics

Views

Total Views
1,130
Views on SlideShare
1,050
Embed Views
80

Actions

Likes
0
Downloads
8
Comments
1

1 Embed 80

http://d.hatena.ne.jp 80

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

HiRoshima.R #2 入門者講習資料 HiRoshima.R #2 入門者講習資料 Presentation Transcript

  • Hi oshima. 2012-02-11 HiRoshima.R #2 @Friday, February 10, 12 1
  • 0.Friday, February 10, 12 2
  • 0. • (SAKAUE, Tatsuya) • : ... • Nagoya.R / HiRoshima.R • ID: sakaue • ...Friday, February 10, 12 4
  • Friday, February 10, 12 5
  • Agenda 1. R 2. 3. 4. 5. RFriday, February 10, 12 7
  • Agenda 1. R 2. 3. 4. 5. RFriday, February 10, 12 8
  • • • Ross Ihaka & Robert Gentleman (R & R) • Ross Ihaka and Robert Gentleman. R: A language for data analysis and graphics. Journal of Computational and Graphical Statistics, 5(3):299-314, 1996. • http://biostat.mc.vanderbilt.edu/twiki/pub/Main/Je reyHorner/JCGSR.pdf •Friday, February 10, 12 9
  • Friday, February 10, 12 10
  • • IBM SPSS Statistics 10 ... • •Friday, February 10, 12 11
  • • • • • •Friday, February 10, 12 12
  • UgeeeeeeeeeFriday, February 10, 12 13
  • Excel SPSS ... • • • Excel •Friday, February 10, 12 14
  • Excel SPSSFriday, February 10, 12 15
  • -Install / Update / Uninstall-Friday, February 10, 12 16
  • 1. http://www.r-project.org/ 2. “download R” 3. JAPAN 4. OSFriday, February 10, 12 17
  • • Windows: : http://cran.md.tsukuba.ac.jp/bin/windows/base/ • Download R 2.14.0 for Windows • Mac OS X: http://cran.md.tsukuba.ac.jp/bin/macosx/ • R-2.14.0.pkg (latest version)Friday, February 10, 12 18
  • Friday, February 10, 12 19
  • Friday, February 10, 12 20
  • Friday, February 10, 12 21
  • Friday, February 10, 12 22
  • Friday, February 10, 12 23
  • Friday, February 10, 12 24
  • 1. http://www.r-project.org/ 2. 3.Friday, February 10, 12 25
  • • • • Windows •Friday, February 10, 12 26
  • • Windows • [ Windows XP] → • [ Windows 7 ] → • Mac OS X • /Applications /Library Frameworks R. framework CleanAppFriday, February 10, 12 27
  • • Windows • START → Program → R → R 2.14.1 • Mac OS X • /Applications R RFriday, February 10, 12 28
  • • Windows Mac OS X 1. q() 2. 3. RFriday, February 10, 12 29
  • ... • help(sth) • seekR (http://seekr.jp/) • R SEEK (http://www.rseek.org/) • RjpWiki (http://www.okada.jp.org/RWiki/) • R-Tips (http://cse.naro.a rc.go.jp/takezawa/r-tips/r.html) •R (http://aoki2.si.gunma-u.ac.jp/R/)Friday, February 10, 12 30
  • • • • help(sth) !!Friday, February 10, 12 31
  • Excel SPSSFriday, February 10, 12 32
  • Agenda 1. R 2. 3. 4. 5. RFriday, February 10, 12 33
  • Agenda 1. R 2. 3. 4. 5. RFriday, February 10, 12 34
  • Friday, February 10, 12 35
  • • [Enter] • > 3+5 [Enter] • > 10-3 [Enter] • > 2*3 [Enter] • > 100/20 [Enter] • > (12 + 34 -56) * 78 / 90 [Enter]Friday, February 10, 12 36
  • • • > 100^1/2 • > 100^(1/2)Friday, February 10, 12 37
  • Friday, February 10, 12 38
  • Friday, February 10, 12 39
  • Friday, February 10, 12 40
  • “I dont know !” by fmgbain http://www.flickr.com/photos/fmgbain/4382010455/Friday, February 10, 12 41
  • Friday, February 10, 12 42
  • sqrt() • > sqrt(2) • > sqrt(144) • > sqrt(104976)Friday, February 10, 12 43
  • ( ) • •q() help(sth) •Friday, February 10, 12 44
  • Friday, February 10, 12 45
  • Friday, February 10, 12 46
  • Friday, February 10, 12 47
  • Friday, February 10, 12 48
  • Friday, February 10, 12 49
  • “I dont know !” by fmgbain http://www.flickr.com/photos/fmgbain/4382010455/Friday, February 10, 12 50
  • Friday, February 10, 12 51
  • “hako” • > hako <- c(1,2,3,4,5) • > hako • c() concatenate/combine •Friday, February 10, 12 52
  • c() “<-” hako <- c(1,2,3,4,5) “<-” ←Friday, February 10, 12 53
  • + ... • [Enter] • [STOP] • [Esc]Friday, February 10, 12 54
  • • • TabFriday, February 10, 12 55
  • hako 1 5 5Friday, February 10, 12 56
  • Friday, February 10, 12 57
  • • > sqrt(hako) • > log(hako)Friday, February 10, 12 58
  • sqrt(1), sqrt(2) ... sqrt(5) log(1), log (2) ... log (5)Friday, February 10, 12 59
  • Friday, February 10, 12 60
  • Friday, February 10, 12 61
  • • summary() • table() • sum() • length()Friday, February 10, 12 62
  • • mean() • max(), min() • median() • sd()Friday, February 10, 12 63
  • •R • • q(), help(), sqrt(), log(), c() •Friday, February 10, 12 64
  • OKFriday, February 10, 12 65
  • Agenda 1. R 2. 3. 4. 5. RFriday, February 10, 12 66
  • Agenda 1. R 2. 3. 4. 5. RFriday, February 10, 12 67
  • Sub topics 1. 2. 3.Friday, February 10, 12 68
  • Friday, February 10, 12 69
  • Friday, February 10, 12 70
  • ... • • • TOEICFriday, February 10, 12 71
  • ... A 180 75 B 170 65 C 165 60 D 175 70 E 190 80Friday, February 10, 12 72
  • RFriday, February 10, 12 73
  • Friday, February 10, 12 74
  • 1 2 3 4 5 6 7 8 9Friday, February 10, 12 75
  • Friday, February 10, 12 76
  • 1 2 3 4 5 6 7 8 9Friday, February 10, 12 77
  • 1 2 3 4 5 6 7 8 9Friday, February 10, 12 78
  • 1 2 3 4 5 6 7 8 9Friday, February 10, 12 79
  • Friday, February 10, 12 80
  • 1 2 3 4 5 6 7 8 9Friday, February 10, 12 81
  • 1 2 3 4 5 6 7 8 9Friday, February 10, 12 82
  • 1 2 3 4 5 6 7 8 9Friday, February 10, 12 83
  • Friday, February 10, 12 84
  • matrix()Friday, February 10, 12 85
  • matrix() • • matrix( , , ) •Friday, February 10, 12 86
  • A 180 75 B 170 65 C 165 60 D 175 70 E 190 80Friday, February 10, 12 87
  • karada <- matrix(c(180, 170, 165, 175, 190, 75, 65, 60, 70, 80), 5, 2) 1. c() 2. matrix() • 5 2 3. karadaFriday, February 10, 12 88
  • > karadaFriday, February 10, 12 89
  • matrix(1:9,nrow=3,ncol=3) 1 4 7 2 5 8 3 6 9Friday, February 10, 12 90
  • matrix(1:9,nrow=3,ncol=3,byrow=TRUE) 1 2 3 4 5 6 7 8 9Friday, February 10, 12 91
  • 1. 2.Friday, February 10, 12 92
  • demo <- matrix(1:30,nrow=5,ncol=6) http://gyazo.com/76c58d5d6c8426a44f160897cda99671.pngFriday, February 10, 12 93
  • 2 → demo[2,] 2 → demo[,2] http://gyazo.com/6726084afd9e1cc4b03df85fe6bc0f29.pngFriday, February 10, 12 94
  • 2 4 → demo[c(2,4),] 2 4 → demo[, c(2,4)]Friday, February 10, 12 95
  • http://gyazo.com/a116c0e2f1284ea7d38bf7024d92f1cc.pngFriday, February 10, 12 96
  • • • •Friday, February 10, 12 97
  • Sub topics 1. 2. 3.Friday, February 10, 12 98
  • • • •Friday, February 10, 12 99
  • B 175 65 B 177 70 B 174 75 A 179 70 O 170 60Friday, February 10, 12 100
  • • Excel WS • •Friday, February 10, 12 101
  • ... • data.frame() (p.240) • (p.243) • (p.243)Friday, February 10, 12 102
  • ...Friday, February 10, 12 103
  • “173.365 - Come on, feel the noise” by Je the Trojan http://www. ickr.com/photos/trojanguy/3046207115/Friday, February 10, 12 104
  • Friday, February 10, 12 105
  • Sub topics 1. 2. 3.Friday, February 10, 12 106
  • Friday, February 10, 12 107
  • ... • Excel • →Friday, February 10, 12 108
  • • ... • •Friday, February 10, 12 109
  • • Windows → • “MyDocuments” • Mac OS X → • Linux up to you...Friday, February 10, 12 110
  • • • getwd() • > getwd() • setwd() • > setwd("/Users/sakaue/Desktop/")Friday, February 10, 12 111
  • • read.csv() • CSV • CSV: Comma Separated ValueFriday, February 10, 12 112
  • 1. demo.csv • XLS/XLSX • CSV UTF-8 2. > test <- read.csv(“demo.csv”) 3. > test [Enter]Friday, February 10, 12 113
  • CSV ...Friday, February 10, 12 114
  • • read.delim() • • delim: delimiterFriday, February 10, 12 115
  • 1. demo.xls 2. > test2 <- read.delim("clipboard") Mac : read.delim(pipe(“pbpaste”)) 3. > test2 [Enter]Friday, February 10, 12 116
  • > table(test2[,1]) • 1 > mean(test2[,2]) • 2 > hist(test2[,2]) • 2Friday, February 10, 12 117
  • • • CSV read.csv() • orFriday, February 10, 12 118
  • CSV Excel “y2.d175 | Lasershow! Relax!” by B Rosen http://www.flickr.com/photos/rosengrant/4751386872/Friday, February 10, 12 119
  • Excel SPSSFriday, February 10, 12 120
  • Agenda 1. R 2. 3. 4. 5. RFriday, February 10, 12 121
  • Agenda 1. R 2. 3. 4. 5. RFriday, February 10, 12 122
  • Friday, February 10, 12 123
  • Friday, February 10, 12 124
  • 1. 2.Friday, February 10, 12 125
  • 2 Excel SPSS ... orzFriday, February 10, 12 126
  • Friday, February 10, 12 127
  • > age <- c(18, 23, 14, 19, 21, 29, 22, 21, 23, 19, 20, 20, 26, 18, 14, 6, 8, 16, 23, 20) > hist(age)Friday, February 10, 12 128
  • Friday, February 10, 12 129
  • > score <- c(60, 50, 72, 43, 50, 55, 43, 50, 85, 40) > words <- c(340, 190, 465, 170, 130, 225,140, 310, 580, 120) > plot(score,words)Friday, February 10, 12 130
  • Friday, February 10, 12 131
  • > high <- c(350, 285, 315, 340, 210, 185, 120, 740, 425, 155) > coll <- c(365, 570, 645, 540, 645, 665, 880, 550, 410, 585) > boxplot(high, coll, names=c("High", "Coll"))Friday, February 10, 12 132
  • 1. 2. 3. twitter, FBFriday, February 10, 12 133
  • Excel “y2.d175 | Lasershow! Relax!” by B Rosen http://www.flickr.com/photos/rosengrant/4751386872/Friday, February 10, 12 134
  • Agenda 1. R 2. 3. 4. 5. RFriday, February 10, 12 135
  • Agenda 1. R 2. 3. 4. 5. RFriday, February 10, 12 136
  • Friday, February 10, 12 137
  • tFriday, February 10, 12 138
  • tFriday, February 10, 12 139
  • • H0 • H1 • H0 (t, χ2, F ) •Friday, February 10, 12 140
  • t • •R t.test()Friday, February 10, 12 141
  • t • > like <- c(6,10,6,10,7,8,7,9,10,4) > dislike <- c(3,5,6,4,4,8,4,5,4,7) > t.test(like,dislike,var.equal=TRUE)Friday, February 10, 12 142
  • t > t.test(like,dislike,var.equal=TRUE) Two Sample t-test data: like and dislike t = 3.3041, df = 18, p-value = 0.003946 alternative hypothesis: true difference in means is not equal to 0 # 95 percent confidence interval: # 0.9831754 4.4168246 sample estimates: mean of x mean of y 7.7 5.0Friday, February 10, 12 143
  • t ... “ t Welch t Welch t ” http://aoki2.si.gunma-u.ac.jp/lecture/Average/bunsan1.htmlFriday, February 10, 12 144
  • Welch !Friday, February 10, 12 145
  • ! ! ― Welch ― • http://oku.edu.mie-u.ac.jp/~okumura/blog/node/2262 • http://aoki2.si.gunma-u.ac.jp/lecture/BF/index.html • Donald W. Zimmerman, ``Some properties of preliminary tests of equality of variances in the two-sample location problem, The Journal of General Psychology, Vol.123, pp. 217-231 (1996) • The unequal variance t-test is an underused alternative to Students t-test and the Mann-Whitney U test -- Ruxton 17 (4): 688 -- Behavioral Ecology • : Mann-Whitney U http://qdai.way- nifty.com/qjes/2005/02/mannwhitneyu.htmlFriday, February 10, 12 146
  • ... > t.test(like,dislike,var.equal=FALSE) Welch Two Sample t-test data: like and dislike t = 3.3041, df = 16.795, p-value = 0.004249 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: 0.9743014 4.4256986 sample estimates: mean of x mean of y 7.7 5.0Friday, February 10, 12 147
  • t t ... • t t ... • Student t t • s^2 s t ... • http://ja.wikipedia.org/wiki/%E3%82%A6%E3%82%A3%E3%83%AA %E3%82%A2%E3%83%A0%E3%83%BB%E3%82%B4%E3%82%BB%E3%83%83%E3%83%88 • http://ja.wikipedia.org/wiki/%E8%87%AA%E7%94%B1%E5%BA%A6 • http://mat.isc.chubu.ac.jp/fpr/fpr1997/0119.html • http://www.pol.geophys.tohoku.ac.jp/~hanawa/ori/ori/054.htmlFriday, February 10, 12 148
  • tFriday, February 10, 12 149
  • Friday, February 10, 12 150
  • • • • A B •Friday, February 10, 12 151
  • : “ ” “however” 109 347 8 493 [ ] , .... [ ] ..., , .... [ ] ..., .Friday, February 10, 12 152
  • > freq <- c(109,347,8) > chisq.test(freq,correct=FALSE) Chi-squared test for given probabilities data: freq X-squared = 391.7371, df = 2, p-value < 2.2e-16 # 2 # http://homepage2.nifty.com/nandemoarchive/toukei_kiso/t_F_chi.htmFriday, February 10, 12 153
  • tFriday, February 10, 12 154
  • Friday, February 10, 12 155
  • •3 • t • ANOVA ANalysis Of VAriance •F FFriday, February 10, 12 156
  • A B C 10 9 6 8 7 4 9 4 3 6 5 9 9 2 2 5 8 6 7 4 2 9 2 4 8 8 3 10 4 9Friday, February 10, 12 157
  • > test <- read.csv("demo.csv", head=T) > anova(lm(Class ~ Score, data=test)) Analysis of Variance Table Response: Class Df Sum Sq Mean Sq F value Pr(>F) Score 1 5.2389 5.2389 9.9376 0.00384 ** Residuals 28 14.7611 0.5272 --- Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1Friday, February 10, 12 158
  • • • t • • ! • ...Friday, February 10, 12 159
  • Friday, February 10, 12 160
  • Friday, February 10, 12 161
  • Friday, February 10, 12 162
  • Friday, February 10, 12 163
  • 2,940 1,785 3,780Friday, February 10, 12 164
  • One more thing...Friday, February 10, 12 165
  • 22 19 R R R R http://www.occn.zaq.ne.jp/cuhxr802/epi_20120126.pdfFriday, February 10, 12 166
  • Excel SPSSFriday, February 10, 12 167
  • twitter: @sakaue e-mail: tsakaue<AT>hiroshima-u.ac.jpFriday, February 10, 12 168