220 likes | 341 Views
量的表現 Quantitation. 分布 Distribution. 1峰性分布. 2峰性分布. 2次元分布. 有限範囲の2次元分布. 1 次元分布 1-dimensional dist. 1 峰性分布 Unimodal dist. 平均・分散 Mean/Variance モーメント Moments モーメントの計算 How to calculate moments 値、値の増加率、増加率の増加率 Value, Increasing rate, Increasing rate of increasing rate
E N D
分布 Distribution • 1峰性分布
1次元分布 1-dimensional dist.1峰性分布 Unimodal dist. • 平均・分散 Mean/Variance • モーメント Moments • モーメントの計算 • How to calculate moments • 値、値の増加率、増加率の増加率 • Value, Increasing rate, Increasing rate of increasing rate • 微分・積分 Diffenrential/Integration • 確率分布・累積確率分布 Probability distribution/Cumulative probability distribution R2-1.R
1峰性分布を作るMake unimodal distribution • N<-100 • x<-rnorm(N) • hist(x) • plot(sort(x)) • x<-rnorm(N,mean=1,sd=1) • hist(x) • plot(sort(x))
1次元2峰性分布Two-dimensional di-modal dist. • N1<-100;N2<-50 • m1<-0;m2<-10;sd1<-1;sd2<-2 • x1<-rnorm(N1,mean=m1,sd=sd1) • x2<-rnorm(N2,mean=m2,sd=sd2) • x<-c(x1,x2) • hist(x) • plot(sort(x))
2次元1峰性分布Two-dimensional unimodal dist. • N<-1000 • x1<-rnorm(N) • x2<-rnorm(N) • plot(x1,x2)
2次元1峰性分布Two-dimensional unimodal dist. • 軸ごとに平均をかえてみる Change mean of x1 and x2 • 軸ごとに分散をかえてみる Change var/sd of x1 and x2 • N<-1000 • x1<-rnorm(N,mean=0,sd=1) • x2<-rnorm(N,mean=10,sd=4) • xlim<-ylim<-c(min(x1,x2),max(x1,x2)) • plot(x1,x2,xlim=xlim,ylim=ylim)
多次元1峰性分布Poly-dimensional unimodal dist. • N<-500 • m1<-0;m2<-10;m3<-30; • sd1<-1;sd2<-4;sd3<-10 • x1<-rnorm(N,mean=m1,sd=sd1) • x2<-rnorm(N,mean=m2,sd=sd2) • x3<-rnorm(N,mean=m3,sd=sd3) • plot(as.data.frame(cbind(x1,x2,x3))) • library(rgl) • plot3d(x1,x2,x3) • 軸の値に注意 Note values on axes displayed
多次元多峰性分布Poly-dimensional polymodal dist. • N<-1000 • m1<-0;m2<-10;m3<-30; • sd1<-1;sd2<-4;sd3<-10 • x1<-rnorm(N,mean=m1,sd=sd1) • x2<-rnorm(N,mean=m2,sd=sd2) • x3<-rnorm(N,mean=m3,sd=sd3) • N<-2000 • m1<-20;m2<-20;m3<-20; • sd1<-1;sd2<-1;sd3<-1 • y1<-rnorm(N,mean=m1,sd=sd1) • y2<-rnorm(N,mean=m2,sd=sd2) • y3<-rnorm(N,mean=m3,sd=sd3) • N<-500 • m1<-10;m2<-50;m3<-20; • sd1<-5;sd2<-4;sd3<-1 • z1<-rnorm(N,mean=m1,sd=sd1) • z2<-rnorm(N,mean=m2,sd=sd2) • z3<-rnorm(N,mean=m3,sd=sd3) • w1<-c(x1,y1,z1) • w2<-c(x2,y2,z2) • w3<-c(x3,y3,z3) • library(rgl) • plot3d(w1,w2,w3)
データプロットを眺める最適視点を探すFind “best” spot to look at the data plot
#偏った集団構成(100人規模の亜集団4つと10人規模の亜集団を20個)で#偏った集団構成(100人規模の亜集団4つと10人規模の亜集団を20個)で • #100項目のデータを作成 • Nm<-100 #項目数 • # 亜集団別の人数発生(100人くらいの4亜集団と20人くらいの10亜集団) • Ns<-c(rpois(4,100),rpois(20,10)) • Npop<-length(Ns) #亜集団数 • M<-NULL #全データを納める行列 • #亜集団別に平均を振ってシミュレーション • for(j in 1:Npop){ • tmpM<-matrix(rep(0,Nm*Ns[j]),ncol=Nm) • for(i in 1:Nm){ # 項目ごとのループ • af<-rnorm(1) # 項目の亜群期待値 • tmpM[,i]<-rnorm(Ns[j],af) # 亜集団別のデータ • } • #全データ行列に格納 • M<-rbind(M,tmpM) • } R7-5.R # データを標準化 wholemean<-mean(M) M<-M-wholemean # 全平均が0になるように mu<-apply(M,2,mean) # 列平均 M<-t(t(M)-mu) # 列平均が0になるように
# 固有値分解前後をimage()プロット image(1:sum(Ns),1:Nm,M,xlab="サンプル(大集団→小集団)",ylab="項目") # 固有値分解 svdout<-svd(M) M2<-svdout$u%*%diag(svdout$d) # 分解後データ行列 par(mfcol=c(1,2)) # 固有値分解前後をimage()プロット image(1:sum(Ns),1:Nm,M,xlab="サンプル(大集団→小集団)",ylab="項目") image(1:sum(Ns),1:Nm,M2,xlab="サンプル(大集団→小集団)", ylab="PCA後eigen項目")
データを読む“Read” data • 記述する・説明する Description, Explanation • 少ない変数で説明する Describe with a few variables • 残りは「ランダム」と考える The rest is “at random”
分散分析 ANOVA SSw=SSb+SSi • SSbが大きければ、「群の違いが大きい」 • When SSb is larger, “difference among groups is larger” • サンプル数が異なるとき • When No. samples is different • サンプル数について一般化 • Generalization for No. samples • 自由度 degrees of freedom
固有値分解・主成分分析Eigenvalue decomposition・Principal Component Analysis (PCA) R7-5.R • 正規直交基底 Orthonormal base • どうして「直交」 Why orthogonal? • 分散が基底成分の分散に分解できるから Because variance is decomposed into component variances of directions