Japan.R #2 Introduction to R

  • 4,945 views
Uploaded on

 

More in: Education , Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
4,945
On Slideshare
0
From Embeds
0
Number of Embeds
7

Actions

Shares
Downloads
30
Comments
0
Likes
5

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Japan.R #2 @ 2011-11-26Saturday, November 26, 11 2
  • 2. 0.Saturday, November 26, 11 3
  • 3. (SAKAUE, Tatsuya) • : ... • Nagoya.R / HiRoshima.R • ID: sakaue • ...Saturday, November 26, 11 5
  • 4. Saturday, November 26, 11 6
  • 5. Agenda 1. R 2. 3. 4. 5. RSaturday, November 26, 11 8
  • 6. Agenda 1. R 2. 3. 4. 5. RSaturday, November 26, 11 9
  • 7. • • 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 •Saturday, November 26, 11 10
  • 8. Saturday, November 26, 11 11
  • 9. • IBM SPSS Statistics 10 ... • •Saturday, November 26, 11 12
  • 10. • • • • •Saturday, November 26, 11 13
  • 11. UgeeeeeeeeeSaturday, November 26, 11 14
  • 12. Excel SPSS ... • • • Excel •Saturday, November 26, 11 15
  • 13. Excel SPSSSaturday, November 26, 11 16
  • 14. -Install / Update / Uninstall-Saturday, November 26, 11 17
  • 15. 1. http://www.r-project.org/ 2. “download R” 3. JAPAN 4. OSSaturday, November 26, 11 18
  • 16. • 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)Saturday, November 26, 11 19
  • 17. Saturday, November 26, 11 20
  • 18. Saturday, November 26, 11 21
  • 19. Saturday, November 26, 11 22
  • 20. Saturday, November 26, 11 23
  • 21. Saturday, November 26, 11 24
  • 22. Saturday, November 26, 11 25
  • 23. 1. http://www.r-project.org/ 2. 3.Saturday, November 26, 11 26
  • 24. • • • Windows •Saturday, November 26, 11 27
  • 25. • Windows • [ Windows XP] → • [ Windows 7 ] → • Mac OS X • /Applications /Library Frameworks R. framework CleanAppSaturday, November 26, 11 28
  • 26. • Windows • START → Program → R → R 2.14.0 • Mac OS X • /Applications R RSaturday, November 26, 11 29
  • 27. • Windows Mac OS X 1. q() 2. 3. RSaturday, November 26, 11 30
  • 28. • OK • Win • [ ]→[GUI ] • Font [MS Mincho]Saturday, November 26, 11 31
  • 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/)Saturday, November 26, 11 32
  • 30. • • • help(sth) !!Saturday, November 26, 11 33
  • 31. Excel SPSSSaturday, November 26, 11 34
  • 32. Agenda 1. R 2. 3. 4. 5. RSaturday, November 26, 11 35
  • 33. Agenda 1. R 2. 3. 4. 5. RSaturday, November 26, 11 36
  • 34. Saturday, November 26, 11 37
  • 35. • [Enter] • > 3+5 [Enter] • > 10-3 [Enter] • > 2*3 [Enter] • > 100/20 [Enter] • > (12 + 34 -56) * 78 / 90 [Enter]Saturday, November 26, 11 38
  • 36. • • > 100^1/2 • > 100^(1/2)Saturday, November 26, 11 39
  • 37. Saturday, November 26, 11 40
  • 38. Saturday, November 26, 11 41
  • 39. Saturday, November 26, 11 42
  • 40. “I dont know !” by fmgbain http://www.flickr.com/photos/fmgbain/4382010455/Saturday, November 26, 11 43
  • 41. Saturday, November 26, 11 44
  • 42. sqrt() • > sqrt(2) • > sqrt(144) • > sqrt(104976) •[ ]2 • 2 3 1 • > 2^(1/3)Saturday, November 26, 11 45
  • 43. ( ) • •q() help(sth) •Saturday, November 26, 11 46
  • 44. Saturday, November 26, 11 47
  • 45. Saturday, November 26, 11 48
  • 46. Saturday, November 26, 11 49
  • 47. Saturday, November 26, 11 50
  • 48. Saturday, November 26, 11 51
  • 49. “I dont know !” by fmgbain http://www.flickr.com/photos/fmgbain/4382010455/Saturday, November 26, 11 52
  • 50. Saturday, November 26, 11 53
  • 51. “hako” • > hako <- c(1,2,3,4,5) • > hako • c() concatenate/combine •Saturday, November 26, 11 54
  • 52. c() “<-” hako <- c(1,2,3,4,5) “<-” ←Saturday, November 26, 11 55
  • 53. + ... • [Enter] • [STOP] • [Esc]Saturday, November 26, 11 56
  • 54. • • TabSaturday, November 26, 11 57
  • 55. hako 1 5 5Saturday, November 26, 11 58
  • 56. Saturday, November 26, 11 59
  • 57. • > sqrt(hako) • > log(hako)Saturday, November 26, 11 60
  • 58. sqrt(1), sqrt(2) ... sqrt(5) log(1), log (2) ... log (5)Saturday, November 26, 11 61
  • 59. Saturday, November 26, 11 62
  • 60. Saturday, November 26, 11 63
  • 61. • summary() • table() • sum() • length()Saturday, November 26, 11 64
  • 62. • mean() • max(), min() • median() • sd()Saturday, November 26, 11 65
  • 63. •R • • q(), help(), sqrt(), log(), c() •Saturday, November 26, 11 66
  • 64. OKSaturday, November 26, 11 67
  • 65. Agenda 1. R 2. 3. 4. 5. RSaturday, November 26, 11 68
  • 66. Agenda 1. R 2. 3. 4. 5. RSaturday, November 26, 11 69
  • 67. Sub topics 1. 2. 3.Saturday, November 26, 11 70
  • 68. Saturday, November 26, 11 71
  • 69. Saturday, November 26, 11 72
  • 70. ... • • • TOEICSaturday, November 26, 11 73
  • 71. ... A 180 75 B 170 65 C 165 60 D 175 70 E 190 80Saturday, November 26, 11 74
  • 72. RSaturday, November 26, 11 75
  • 73. Saturday, November 26, 11 76
  • 74. 1 2 3 4 5 6 7 8 9Saturday, November 26, 11 77
  • 75. Saturday, November 26, 11 78
  • 76. 1 2 3 4 5 6 7 8 9Saturday, November 26, 11 79
  • 77. 1 2 3 4 5 6 7 8 9Saturday, November 26, 11 80
  • 78. 1 2 3 4 5 6 7 8 9Saturday, November 26, 11 81
  • 79. Saturday, November 26, 11 82
  • 80. 1 2 3 4 5 6 7 8 9Saturday, November 26, 11 83
  • 81. 1 2 3 4 5 6 7 8 9Saturday, November 26, 11 84
  • 82. 1 2 3 4 5 6 7 8 9Saturday, November 26, 11 85
  • 83. Saturday, November 26, 11 86
  • 84. matrix()Saturday, November 26, 11 87
  • 85. matrix() • • matrix( , , ) •Saturday, November 26, 11 88
  • 86. A 180 75 B 170 65 C 165 60 D 175 70 E 190 80Saturday, November 26, 11 89
  • 87. karada <- matrix(c(180, 170, 165, 175, 190, 75, 65, 60, 70, 80), 5, 2) 1. c() 2. matrix() • 5 2 3. karadaSaturday, November 26, 11 90
  • 88. > karadaSaturday, November 26, 11 91
  • 89. matrix(1:9,nrow=3,ncol=3) 1 4 7 2 5 8 3 6 9Saturday, November 26, 11 92
  • 90. matrix(1:9,nrow=3,ncol=3,byrow=TRUE) 1 2 3 4 5 6 7 8 9Saturday, November 26, 11 93
  • 91. 1. 2.Saturday, November 26, 11 94
  • 92. demo <- matrix(1:30,nrow=5,ncol=6) http://gyazo.com/76c58d5d6c8426a44f160897cda99671.pngSaturday, November 26, 11 95
  • 93. 2 → demo[2,] 2 → demo[,2] http://gyazo.com/6726084afd9e1cc4b03df85fe6bc0f29.pngSaturday, November 26, 11 96
  • 94. 2 4 → demo[c(2,4),] 2 4 → demo[, c(2,4)]Saturday, November 26, 11 97
  • 95. http://gyazo.com/a116c0e2f1284ea7d38bf7024d92f1cc.pngSaturday, November 26, 11 98
  • 96. • • •Saturday, November 26, 11 99
  • 97. Sub topics 1. 2. 3.Saturday, November 26, 11 100
  • 98. • • •Saturday, November 26, 11 101
  • 99. B 175 65 B 177 70 B 174 75 A 179 70 O 170 60Saturday, November 26, 11 102
  • 100. • Excel WS • •Saturday, November 26, 11 103
  • 101. ... • data.frame() (p.240) • (p.243) • (p.243)Saturday, November 26, 11 104
  • 102. ...Saturday, November 26, 11 105
  • 103. “173.365 - Come on, feel the noise” by Je the Trojan http://www. ickr.com/photos/trojanguy/3046207115/Saturday, November 26, 11 106
  • 104. Saturday, November 26, 11 107
  • 105. Sub topics 1. 2. 3.Saturday, November 26, 11 108
  • 106. Saturday, November 26, 11 109
  • 107. ... • Excel • →Saturday, November 26, 11 110
  • 108. • ... • •Saturday, November 26, 11 111
  • 109. • Windows → • “MyDocuments” • Mac OS X → • Linux up to you...Saturday, November 26, 11 112
  • 110. • • getwd() • > getwd() • setwd() • > setwd("/Users/sakaue/Desktop/")Saturday, November 26, 11 113
  • 111. • read.csv() • CSV • CSV: Comma Separated ValueSaturday, November 26, 11 114
  • 112. 1. demo.csv • XLS/XLSX • CSV UTF-8 2. > test <- read.csv(“demo.csv”) 3. > test [Enter]Saturday, November 26, 11 115
  • 113. CSV ...Saturday, November 26, 11 116
  • 114. • read.delim() • • delim: delimiterSaturday, November 26, 11 117
  • 115. 1. demo.xls 2. > test2 <- read.delim("clipboard") Mac : read.delim(pipe(“pbpaste”)) 3. > test2 [Enter]Saturday, November 26, 11 118
  • 116. > table(test2[,1]) • 1 > mean(test2[,2]) • 2 > hist(test2[,2]) • 2Saturday, November 26, 11 119
  • 117. • • CSV read.csv() • orSaturday, November 26, 11 120
  • 118. CSV Excel “y2.d175 | Lasershow! Relax!” by B Rosen http://www.flickr.com/photos/rosengrant/4751386872/Saturday, November 26, 11 121
  • 119. Excel SPSSSaturday, November 26, 11 122
  • 120. Agenda 1. R 2. 3. 4. 5. RSaturday, November 26, 11 123
  • 121. Agenda 1. R 2. 3. 4. 5. RSaturday, November 26, 11 124
  • 122. Saturday, November 26, 11 125
  • 123. Saturday, November 26, 11 126
  • 124. 1. 2.Saturday, November 26, 11 127
  • 125. 2 Excel SPSS ... orzSaturday, November 26, 11 128
  • 126. Saturday, November 26, 11 129
  • 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)Saturday, November 26, 11 130
  • 128. Saturday, November 26, 11 131
  • 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)Saturday, November 26, 11 132
  • 130. Saturday, November 26, 11 133
  • 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"))Saturday, November 26, 11 134
  • 132. 1. 2. 3. twitter, FBSaturday, November 26, 11 135
  • 133. Excel “y2.d175 | Lasershow! Relax!” by B Rosen http://www.flickr.com/photos/rosengrant/4751386872/Saturday, November 26, 11 136
  • 134. Agenda 1. R 2. 3. 4. 5. RSaturday, November 26, 11 137
  • 135. Agenda 1. R 2. 3. 4. 5. RSaturday, November 26, 11 138
  • 136. Saturday, November 26, 11 139
  • 137. tSaturday, November 26, 11 140
  • 138. tSaturday, November 26, 11 141
  • 139. t, χ2, FSaturday, November 26, 11 142
  • 140. t t.test()Saturday, November 26, 11 143
  • 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)Saturday, November 26, 11 144
  • 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.0Saturday, November 26, 11 145
  • 143. t ... “ t Welch t Welch t ” http://aoki2.si.gunma-u.ac.jp/lecture/Average/bunsan1.htmlSaturday, November 26, 11 146
  • 144. Welch !Saturday, November 26, 11 147
  • 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.htmlSaturday, November 26, 11 148
  • 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.0Saturday, November 26, 11 149
  • 147. t t ... •t t ... • Student t t • s^2 s t ... • %E3%82%B4%E3%82%BB%E3%83%83%E3%83%88 http://ja.wikipedia.org/wiki/%E3%82%A6%E3%82%A3%E3%83%AA%E3%82%A2%E3%83%A0%E3%83%BB • 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.htmlSaturday, November 26, 11 150
  • 148. tSaturday, November 26, 11 151
  • 149. Saturday, November 26, 11 152
  • 150. • • • A B •Saturday, November 26, 11 153
  • 151. : “ ” “however” 109 347 8 493 [ ] , .... [ ] ..., , .... [ ] ..., .Saturday, November 26, 11 154
  • 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.htmSaturday, November 26, 11 155
  • 153. tSaturday, November 26, 11 156
  • 154. Saturday, November 26, 11 157
  • 155. •3 •t • ANOVA ANalysis Of VAriance •F FSaturday, November 26, 11 158
  • 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 9Saturday, November 26, 11 159
  • 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 1Saturday, November 26, 11 160
  • 158. Saturday, November 26, 11 161
  • 159. Saturday, November 26, 11 162
  • 160. One more thing...Saturday, November 26, 11 163
  • 161. Hi oshima.Saturday, November 26, 11 164
  • 162. HiRoshima.R • R • 2-3 • • ...Saturday, November 26, 11 165
  • 163. HiRoshima.R • ... • R • Tsukuba.R / Tokyo.R / Osaka.R / Nagoya.R • Internet (computer) literacy • ...Saturday, November 26, 11 166
  • 164. HiRoshima.R •R • HiRoshima.R • !!Saturday, November 26, 11 168
  • 165. 1 22 14% 23% 64%Saturday, November 26, 11 169
  • 166. HiRoshima.R • →Lightning Talks • •Saturday, November 26, 11 171
  • 167. HiRoshima.R • • R R • • • •Saturday, November 26, 11 172
  • 168. HiRoshima.R • + Speaker !! • • • •R •RSaturday, November 26, 11 173
  • 169. HiRoshima.R • • 1 • 2 #1 • 3 Lightning Talks •Saturday, November 26, 11 174
  • 170. •Speaker • • Lightning Talks • R OK • 5 OKSaturday, November 26, 11 176
  • 171. •Feedback • blog / twitter • #HiRoshimaR @sakaue •Saturday, November 26, 11 177
  • 172. Saturday, November 26, 11 178
  • 173. Saturday, November 26, 11 179
  • 174. Saturday, November 26, 11 180
  • 175. 2,940 1,785 3,780Saturday, November 26, 11 181
  • 176. Excel SPSSSaturday, November 26, 11 182
  • 177. twitter: @sakaue e-mail: tsakaue<AT>hiroshima-u.ac.jpSaturday, November 26, 11 183