我想估计MRM系数的频率分布以生成95%CI。以下是初始代码:
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 :(得分:1)
您可以使用ecodist::MRM
库中的boot
功能。我不知道lm
。虽然,这里是> 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
帮助页面中的复制粘贴示例,它显示了如何对FrameFormatter[InEvent]
模型进行系数估计的非参数自举,并获得偏差和置信区间
FrameFormatter[OutEvent]
见 Davison,A.C。和Hinkley,D.V。 (1997)Bootstrap方法及其应用。剑桥大学出版社了解上述输出的详情。您应该考虑使用引导程序实现的目标,并考虑使用哪个引导程序。