2016-05-09 5 views
1

次のコードでは、ベクトルV1を取り、V1からランダム化されたrnomalサンプルを10000倍ブートストラップし、結果が10000列の行列を作成します。次に、その行列のヒストグラムを作成します。確率密度と関連するブレークのテーブル/マトリックスを作成する

V1 <- c(0.18, 0.2, 0.24, 0.35, -0.22, -0.17, 0.28, -0.28, -0.14, 0.03, 0.87, -0.2, 0.06, -0.1, -0.72, 0.18, 0.01, 0.31, -0.36, 0.61, -0.16, -0.07, -0.13, 0.01, -0.09, 0.26, -0.14, 0.08, -0.62, -0.2, 0.3, -0.21, -0.11, 0.05, 0.06, -0.28, -0.27, 0.17, 0.42, -0.05, -0.15, 0.05, -0.07, -0.22, -0.34, 0.16, 0.34, 0.1, -0.12, 0.24, 0.45, 0.37, 0.61, 0.9, -0.25, 0.02) 

xxx <- round(sapply(1:10000, function(i) rnorm(length(V1), mean=sample 
             (V1, length(V1), replace=TRUE), sd(V1))),2) 

h <- hist(xxx, plot=T) 

I、すなわち1.0、0.9、0.8、0.7、0.6、0.5、0.4、0.3、0.2、0.1と行列を得る、マトリクス又はテーブル形式でその確率密度関数の印刷物を作成したいです-1,0、-0.3、-0.4、-0.5、-0.6、-0.7、-0.8、-0.9、-1.0、および関連する確率密度を次の列に含む。

私の問題は2つです。まず、私が望む休憩を指定するのが失敗します。第2に、h$breaksh$densityで行列を作ることも失敗します。どんな洞察も高く評価されるだろう。ありがとうございました。

#This works, but I want to specify the breaks 
h <- hist(xxx, plot=T, breaks=20) 

#This gives error "some 'x' not counted; maybe 'breaks' do not span range of 'x'" 
h <- hist(xxx, plot=T, breaks=c(1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1, 0, -0,1 -0.2, -0.3, -0.4, -0.5, -0.6, -0.7, -0.8, -0.9, -1.0)) 

#This gives error number of rows of result is not a multiple of vector length 
ddd<- cbind(h$breaks, h$density) 

答えて

1

最初にタイプエラーがあり、 "。"と "、"を混同しました。

h <- hist(xxx, plot=F, breaks=c(max(xxx),1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1, 0, -0.1, -0.2, -0.3, -0.4, -0.5, -0.6, -0.7, -0.8, -0.9, -1.0,min(xxx))) 

そして最後に、あなたが代わりに休憩の「中音域」を選択します:

ddd<- cbind(h$mids, h$density) 
秒休憩は、このような観測の全範囲に及ぶ必要がありますで

関連する問題