2.1 R, ( ), Download R for Windows base. R ( ) R win.exe, 2.,.,.,. R > 3*5 # [1] 15 > c(19,76)+c(11,13)

Similar documents
1 R Windows R 1.1 R The R project web R web Download [CRAN] CRAN Mirrors Japan Download and Install R [Windows 9

R による統計解析入門

k3 ( :07 ) 2 (A) k = 1 (B) k = 7 y x x 1 (k2)?? x y (A) GLM (k

講義のーと : データ解析のための統計モデリング. 第2回

一般化線形 (混合) モデル (2) - ロジスティック回帰と GLMM

講義のーと : データ解析のための統計モデリング. 第3回

講義のーと : データ解析のための統計モデリング. 第5回

「産業上利用することができる発明」の審査の運用指針(案)

PDF Information

(2/24) : 1. R R R

2 Excel =sum( ) =average( ) B15:D20 : $E$26 E26 $ =A26*$E$26 $ $E26 E$26 E$26 $G34 $ E26 F4

untitled

Microsoft Word - 計量研修テキスト_第5版).doc

Use R


DAA09


i I Excel iii Excel Excel Excel

統計研修R分散分析(追加).indd

『引越れんらく帳』説明資料

FAX780TA_chap-first.fm

1 Stata SEM LightStone 4 SEM 4.. Alan C. Acock, Discovering Structural Equation Modeling Using Stata, Revised Edition, Stata Press 3.

森林航測87号

Stata 11 Stata ROC whitepaper mwp anova/oneway 3 mwp-042 kwallis Kruskal Wallis 28 mwp-045 ranksum/median / 31 mwp-047 roctab/roccomp ROC 34 mwp-050 s

( 28 ) ( ) ( ) 0 This note is c 2016, 2017 by Setsuo Taniguchi. It may be used for personal or classroom purposes, but not for commercial purp

Excel97関数編

T rank A max{rank Q[R Q, J] t-rank T [R T, C \ J] J C} 2 ([1, p.138, Theorem 4.2.5]) A = ( ) Q rank A = min{ρ(j) γ(j) J J C} C, (5) ρ(j) = rank Q[R Q,

FdData社会歴史

スライド 1

P P P P P P P P P P P P P

DPCはやわかり表紙_2014_H1-H4.indd

Microsoft Word J.^...O.|Word.i10...j.doc

program_japanese

Rによる計量分析:データ解析と可視化 - 第3回 Rの基礎とデータ操作・管理

PowerPoint プレゼンテーション

13 Student Software TI-Nspire CX CAS TI Web TI-Nspire CX CAS Student Software ( ) 1 Student Software 37 Student Software Nspire Nspire Nspir

Excel基礎講座演習-表紙とはじめにv1.3.doc


R John Fox R R R Console library(rcmdr) Rcmdr R GUI Windows R R SDI *1 R Console R 1 2 Windows XP Windows * 2 R R Console R ˆ R

大学等における社会人の受け入れ状況調査

kubostat2017e p.1 I 2017 (e) GLM logistic regression : : :02 1 N y count data or

32



LGBZ3107-T3A1

kubostat2017c p (c) Poisson regression, a generalized linear model (GLM) : :

4名連記 P1-21

1.中山&内田 P1-9

¥¤¥ó¥¿¡¼¥Í¥Ã¥È·×¬¤È¥Ç¡¼¥¿²òÀÏ Âè2²ó

u u u 1 1

Microsoft Word - 教材ガイド一覧ビデオ.doc

食事編_表1_4_0508

2.2 Sage I 11 factor Sage Sage exit quit 1 sage : exit 2 Exiting Sage ( CPU time 0m0.06s, Wall time 2m8.71 s). 2.2 Sage Python Sage 1. Sage.sage 2. sa

PDF


卒業論文

01

Transcription:

3 ( ) R 3 1 61, 2016/4/7( ), 4/14( ), 4/21( ) 1 1 2 1 2.1 R, ( )................ 2 2.2 ggm............................ 3 2.3,................ 4 2.4...................................... 6 2.5 1 ( ).................... 7 2.6...................................... 8 2.7 2 ( )................. 8 2.8................................ 10 2.9............................... 14 3 14 1,,.,,.,,. 2.,, 2 (p. 10). 1, 6 356, matsui@mist.i.u-tokyo.ac.jp; TA. http://www.sr3.t.u-tokyo.ac.jp/matsui/2016s/2016s jikken3.html 1

2.1 R, ( ), http://cran.md.tsukuba.ac.jp/, Download R for Windows base. R (2014-4-17 ) R-3.1.0-win.exe, 2.,.,.,. R > 3*5 # [1] 15 > c(19,76)+c(11,13) # [1] 30 89 > x <- c(3,1,4,1,5,9) # > 1:4 # [1] 1 2 3 4 > 1:4+1 # (1:4)+1 [1] 2 3 4 5 > f <- function(x,y){ sqrt(x^2+y^2) } # > f(3,4) [1] 5 R,. 1....,. 2. R...,., browser()., R, URL. http://cse.naro.affrc.go.jp/takezawa/r-tips/r.html 2 PC R 2

1. R R web 3 sum, prod, cumsum abs, log, sqrt mean, sd, min, median, max scale combine, c list, matrix, array %*% t rbind, cbind diag cor det or apply solve read.table, write.table plot, pairs EPS dev.copy2eps which pnorm, rnorm ls, rm browser for, while, repeat 2.2 ggm, ggm (Graphical Gaussian Models). 1. R ( Japan (Tsukuba) ). 2. ggm. 3. package ggm successfully unpacked and MD5 sums checked. graph RBGL graph R : graph > source("http://bioconductor.org/bioclite.r") > bioclite("graph") RBGL 3 3

RBGL > source("http://bioconductor.org/bioclite.r") > bioclite("rbgl").,., R 1.,,,. > library(ggm) 2.3,,.,,,.., ggm marks,.. > data(marks) > marks mechanics vectors algebra analysis statistics 1 77 82 67 67 81 2 63 78 80 70 81 3 75 73 71 66 81 4 55 72 63 70 68... ( )... 87 5 26 15 20 20 88 0 40 21 9 14 88 5, 5, 88.,., (X t,i ) 1 t n,1 i p (n = 88, p = 5). X 2,3 = 80. summary (min), 1 (1st Qu.), = 2 (median), (mean), 3 (3rd Qu.), (max)., X i = 1 n 4 n t=1 X t,i

, 25%, 50%, 75%. > summary(marks) mechanics vectors algebra analysis statistics Min. : 0.00 Min. : 9.00 Min. :15.00 Min. : 9.00 Min. : 9.00 1st Qu.:30.00 1st Qu.:42.00 1st Qu.:45.00 1st Qu.:35.75 1st Qu.:31.00 Median :41.50 Median :51.00 Median :50.00 Median :49.00 Median :40.00 Mean :38.97 Mean :50.59 Mean :50.60 Mean :46.68 Mean :42.31 3rd Qu.:49.25 3rd Qu.:60.00 3rd Qu.:57.25 3rd Qu.:57.00 3rd Qu.:51.50 Max. :77.00 Max. :82.00 Max. :80.00 Max. :70.00 Max. :81.00 4. (r i,j ) r i,j = s i,j si,i s j,j, s i,j = 1 n (X t,i n X i )(X t,j X j ) t=1 > cor(marks) mechanics vectors algebra analysis statistics mechanics 1.0000000 0.5526975 0.5462281 0.4096365 0.3894430 vectors 0.5526975 1.0000000 0.6096447 0.4850813 0.4364487 algebra 0.5462281 0.6096447 1.0000000 0.7108059 0.6647357 analysis 0.4096365 0.4850813 0.7108059 1.0000000 0.6071743 statistics 0.3894430 0.4364487 0.6647357 0.6071743 1.0000000 > round(cor(marks),3) # 3 mechanics vectors algebra analysis statistics mechanics 1.000 0.553 0.546 0.410 0.389 vectors 0.553 1.000 0.610 0.485 0.436 algebra 0.546 0.610 1.000 0.711 0.665 analysis 0.410 0.485 0.711 1.000 0.607 statistics 0.389 0.436 0.665 0.607 1.000 i j,,. R,., ( ) 1. marks,, mechanics statistics., 2,., vectors mechanics statistics,. 4,. 5

20 60 10 30 50 70 mechanics 0 20 60 20 60 vectors algebra 20 40 60 80 10 30 50 70 analysis statistics 10 40 70 0 20 60 20 40 60 80 10 40 70 1:. > pairs(marks), 2,.,,,.,, 2. 2.4 G, V E V V., (= G = (V, E)). V = {a, b, c, d}, E = {(a, b), (a, c), (b, d)} ggm., drawgraph adjust TRUE,.. > amat <- UG(~ a*b + a*c + b*d) > amat a b c d a 0 1 1 0 b 1 0 0 1 c 1 0 0 0 d 0 1 0 0 > drawgraph(amat,adjust=false) d a c b 6

2.5 1 ( ),, ( ),,., web (1997),., R = (r i,j ), R 1 = (r i,j )., p i,j = r i,j r i,i r j,j (i j), 1 (i = j) (1), i j. P = (p i,j )., ( ) 1.,.,, ( )., S1 = mechanics, S2 = vectors, S3 = algebra, S4 = analysis, S5 = statistics. 1: ( ) ( ). S1 S2 S3 S4 S5 S3 0.546 0.61 1 S4 0.41 0.485 0.711 1 S5 0.389 0.436 0.665 0.607 1 S1 S2 S3 S4 S5 S2 0.328 S3 0.229 0.282 S4-0.001 0.078 0.432 S5 0.026 0.02 0.357 0.253 2. 2, R, P. I cor2par <- function(r){ X <- solve(r) p <- nrow(r) P <- matrix(0,p,p) dimnames(p) <- dimnames(r) for(i in (1:p)){ for(j in (1:p)){ if(i!= j) P[i,j] <- -X[i,j]/sqrt(X[i,i]*X[j,j]) if(i == j) P[i,j] <- 1 }} P } 7

II cor2par <- function(r){ X <- solve(r) d <- sqrt(diag(x)) P <- -X / (d %*% t(d)) diag(p) <- 1 P } 2.6, 4 8.,,,, 47 4. StatLib http://e-stat.go.jp/ http://lib.stat.cmu.edu/datasets/ web. : "math" "phys" "chem" "eng" "1" 30 40 50 60 "2" 20 0 10 70 "3" 40 60 90 45 "4" 30 60 20 70 "5" 40 50 20 70 "6" 50 70 30 80 mark4.txt R...,, : > X <- read.table("mark4.txt") 3.,. 2.9. ( Word ) 2.7 2 ( ) i j p i,j, 8

i j, i j.. 1 ( ).., i j,, p i,j., i j p i,j = 0., p i,j = 0, i j,.,, analysis mechanics (p 41 = 0.001) 0.,, vectors, algebra, statistics, analysis mechanics.,, 5.,.. 2.. 1,, 10 4.,, 2.., 2. 2 1,,. 2: ( ) ( ) S1 S2 S3 S4 S5 S3 0.546 0.61 1 S4 0.388 0.433 0.711 1 S5 0.363 0.405 0.665 0.607 1 S1 S2 S3 S4 S5 S2 0.331 S3 0.235 0.327 S4 0 0 0.451 S5 0 0 0.364 0.256,. (1997) ( [2]). 2 ( )., a, b, s, a b s (a b s, )., s, a b. 5,.,. 9

2:., a = {vectors}, b = {statistics}, s = {algebra}, 2 2., algebra, vectors statistics (mechanics analysis )., a = {mechanics,vectors}, b = {analysis,statistics}, s = {algebra}, 2., mechanics vectors algebra. 4. a = {mechanics}, b = {statistics}, s = {vectors,analysis} a b s 2.8 2.7 (, 1 2 )., web.,,,., R, n ( n = 88). AIC ( ) G, G M = M(G), P = P (G),.., G, G,,., AIC (Akaike s Information Criterion) ( ), AIC = 2 ( ) 2 ( ) + ( ) 10

., AIC 0 ( web )., ggm fitcongraph. 2, AIC. fitcongraph, AIC > options(digits=3) # 3 > X <- marks # > n <- nrow(x); p <- ncol(x) # > R <- cor(x) # > amat <- matrix(1,p,p)-diag(p); #, # amat <- UG(~a*b*c*d*e). > dimnames(amat) <- dimnames(r) # > amat[4,1] <- amat[1,4] <- 0 # (4,1) > amat[4,2] <- amat[2,4] <- 0 # (4,2) > amat[5,1] <- amat[1,5] <- 0 # (5,1) > amat[5,2] <- amat[2,5] <- 0 # (5,2) > amat # mechanics vectors algebra analysis statistics mechanics 0 1 1 0 0 vectors 1 0 1 0 0 algebra 1 1 0 1 1 analysis 0 0 1 0 1 statistics 0 0 1 1 0 > f <- fitcongraph(amat,r,n) # > f # $Shat # mechanics vectors algebra analysis statistics mechanics 1.000 0.553 0.546 0.388 0.363 vectors 0.553 1.000 0.610 0.433 0.405 algebra 0.546 0.610 1.000 0.711 0.665 analysis 0.388 0.433 0.711 1.000 0.607 statistics 0.363 0.405 0.665 0.607 1.000 $dev # [1] 0.9 $df # [1] 4 $it # [1] 2 > f$dev # [1] 0.9 > aic <- f$dev - 2*f$df # AIC > aic [1] -7.1 11

. 1. G ( ). M = R. AIC 0 AIC. 2. M (R ) P = (p i,j ) ( 2 ). 3. G (i, j), p i,j (i, j), G. 4. G M = M(G) AIC = AIC(G) (fitcongraph fitcongraph M R ). 5. AIC 2. AIC,. 5. 3 G (i, j), p ij (i, j),. G amat., select.ij <- function(p,amat){ p <- nrow(p); minabsp <- Inf for(i in (2:p)){ for(j in (1:(i-1))){ if(amat[i,j] == 1 && abs(p[i,j]) < minabsp){ minabsp <- abs(p[i,j]); i0 <- i; j0 <- j }}} c(i0,j0) },. 1,. M 0, P 0. M 0 S1 S2 S3 S4 S5 S3 0.546 0.61 1 S4 0.41 0.485 0.711 1 S5 0.389 0.436 0.665 0.607 1 P 0 S1 S2 S3 S4 S5 S2 0.328 S3 0.229 0.282 S4-0.001 0.078 0.432 S5 0.026 0.02 0.357 0.253 P 0 AIC 0 AIC 0 = 0. P 0, (4,1) 0.001. (4,1). fitcongraph, AIC, 12

M 1 S1 S2 S3 S4 S5 S3 0.546 0.61 1 S4 0.41 0.485 0.711 1 S5 0.389 0.436 0.665 0.607 1 P 1 S1 S2 S3 S4 S5 S2 0.328 S3 0.229 0.282 S4 0 0.078 0.432 S5 0.025 0.02 0.357 0.253. AIC 1 AIC 0. AIC 1 = 2 P 1, (5,2) 0.02 (P 0 P 1 )., (5,2), M 2 S1 S2 S3 S4 S5 S3 0.546 0.61 1 S4 0.411 0.485 0.711 1 S5 0.389 0.426 0.665 0.607 1 P 2 S1 S2 S3 S4 S5 S2 0.329 S3 0.225 0.289 S4 0 0.082 0.428 S5 0.032 0 0.362 0.254 AIC 2 = 3.96. AIC 2 AIC 1,., P 2 (5, 1) (0.032), M 3 S1 S2 S3 S4 S5 S3 0.546 0.61 1 S4 0.406 0.485 0.711 1 S5 0.368 0.419 0.665 0.607 1 P 3 S1 S2 S3 S4 S5 S2 0.33 S3 0.24 0.286 S4 0 0.085 0.424 S5 0 0 0.372 0.255 AIC 3 = 5.86 P 3 (4, 2) (0.085), M 4 S1 S2 S3 S4 S5 S3 0.546 0.61 1 S4 0.388 0.433 0.711 1 S5 0.363 0.405 0.665 0.607 1 P 4 S1 S2 S3 S4 S5 S2 0.331 S3 0.235 0.327 S4 0 0 0.451 S5 0 0 0.364 0.256 AIC 4 = 7.1 P 4 (3, 1) (0.235), M 5 S1 S2 S3 S4 S5 S3 0.337 0.61 1 S4 0.24 0.433 0.711 1 S5 0.224 0.405 0.665 0.607 1 P 5 S1 S2 S3 S4 S5 S2 0.465 S3 0 0.391 S4 0 0 0.464 S5 0 0 0.374 0.256 AIC 5 = 0.208 13

. AIC 5 > AIC 4, P 4. 2. 6.,,, P 0 P 1,. web.) 2.9 3, 2.3, 2.8. ( ) 3 4 (zip )., PDF, or Word. (2.3 ). (2.3 ). (2.8 ), AIC..... matsui@mist.i.u-tokyo.ac.jp 2016/4/28( ).,. 3,. [1] (2004), The R Book R,. [2] (1997),,. 14