2017-02-08 23 views
3

MRM係数の頻度分布を推定して95%CIを生成したいと考えています。以下は初期コードです距離行列の重回帰係数(MRM)のブートストラップ係数

library(ecodist) 
dat=data.frame(matrix(rnorm(3*25),ncol=3)) 
names(dat)<-c('Pred','Var1','Var2') 
mod<-MRM(dist(Pred) ~ dist(Var1) + dist (Var2), data=dat, nperm=100) 
slopes<-mod$coef 

どのように係数値をブートストラップできますか?

+0

例の再現可能なデータを入力してください。 –

+0

変更を加えましたが、これは大丈夫です。どうもありがとう。 – Sreekar

答えて

0

bootライブラリのboot機能を使用できます。私はecodist::MRMを知らない。しかし、ここを参照してくださいデイヴィソン

> library(boot) 
> nuke <- nuclear[, c(1, 2, 5, 7, 8, 10, 11)] 
> nuke.lm <- lm(log(cost) ~ date+log(cap)+ne+ct+log(cum.n)+pt, data = nuke) 
> 
> nuke.fun <- function(dat, inds, i.pred, fit.pred, x.pred) 
+ { 
+ lm.b <- lm(log(cost) ~ date+log(cap)+ne+ct+log(cum.n)+pt, 
+    data = dat[inds, ]) 
+ coef(lm.b) 
+ } 
> 
> set.seed(45282964) 
> nuke.boot <- boot(nuke, nuke.fun, R = 999) 
> nuke.boot 

ORDINARY NONPARAMETRIC BOOTSTRAP 


Call: 
boot(data = nuke, statistic = nuke.fun, R = 999) 


Bootstrap Statistics : 
     original  bias std. error 
t1* -13.26031434 -0.482810992 4.93147203 
t2* 0.21241460 0.006775883 0.06480161 
t3* 0.72340795 0.001842262 0.14160523 
t4* 0.24902491 -0.004979272 0.08857604 
t5* 0.14039305 0.009209543 0.07253596 
t6* -0.08757642 0.002417516 0.05489876 
t7* -0.22610341 0.006136044 0.12140501 
> 
> boot.ci(nuke.boot, index = 2) # pick the covariate index you want 
BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS 
Based on 999 bootstrap replicates 

CALL : 
boot.ci(boot.out = nuke.boot, index = 2) 

Intervals : 
Level  Normal    Basic   
95% (0.0786, 0.3326) (0.0518, 0.3215) 

Level  Percentile   BCa   
95% (0.1033, 0.3730) (0.0982, 0.3688) 
Calculations and Intervals on Original Scale 
Warning message: 
In boot.ci(nuke.boot, index = 2) : 
    bootstrap variances needed for studentized intervals 

lmモデルの係数の推定のノンパラメトリックブートストラップを行い、バイアスと信頼区間を取得する方法を示しているbootのヘルプページからに近いコピー&ペーストの一例です、ACおよびHinkley、DV (1997)ブートストラップ法とその応用。上記の出力の詳細については、Cambridge University Pressを参照してください。ブートストラップで何を達成したいのかを考え、使用するブートストラップ手順を検討する必要があります。

関連する問題