全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
8101 3
2014-10-07
如题,本人初学R语言,想请问一下

在R中,如何用bootstrap 方法求 随机向量的均值,方差,协方差,协方差矩阵

多谢!!!!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2014-10-7 23:42:38
可能你的问题不是R,而是没有理解BOOTSTRAP求均值吧
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-12-29 20:16:31

·  n <- 1000 #样本数据集数量

·  B <- 1000 # boot.samples

·  alpha <- 0.05 #置信概率

·  df <- 6

·  true.mu <- 0 # 真是均值

·  true.sd <- 1 # 真实标准差


·  # 模拟数据生成

·  x <- rnorm(n,mean = true.mu, sd= true.sd)


·  sample.mean.x <- mean(x) #样本均值

·  sample.sd.x <- sd(x) #样本标准差

·  sample.se.x <-sample.sd.x/sqrt(n) #样本标准误

·  sample.conf.x <- sample.mean.x+ c(-1,1)*qnorm(alpha/2,lower.tail=F)*sample.se.x #样本95%置信区间


·  # 为自助法预留缓存向量

·  boot.x <-vector(mode="numeric",length=B)

·  boot.mean <-vector(mode="numeric",length=B)

·  boot.sd <-vector(mode="numeric",length=B)

·  boot.t <-vector(mode="numeric",length=B)


·  for(i in 1:B)

·  {

·    boot.x <- sample(x,size=n, replace=T)

·    boot.mean <-mean(boot.x)

·    boot.sd <-sd(boot.x)

·    boot.t <-(sample.mean.x-boot.mean)/(boot.sd/sqrt(n))

·  }


·  # bootstrap 统计量

·  boot.mean.x <- mean(boot.mean)

·  boot.sd.x <- mean(boot.sd)

·  boot.se.x <- boot.sd.x/sqrt(B)

·  boot.t.quantile <-quantile(boot.t,probs = c(alpha/2,1-alpha/2))

·  boot.mean.quantile <-quantile(boot.mean,probs = c(alpha/2,1-alpha/2))


·  boot.conf.x <- boot.mean.x +c(-1,1)*qt(alpha/2,df=B-1,lower.tail=F)*boot.se.x

·  boot.conf.x2 <- boot.mean.x +boot.t.quantile*boot.se.x


·  true.conf.x <- 2*sample.mean.x- c(boot.mean.quantile[2],boot.mean.quantile[1])


·  #boot.mean.x

·  #boot.sd.x

·  #boot.se.x

·  #boot.conf.x

·  #boot.conf.x2


·  #true.conf.x


·  #sample.mean.x

·  #sample.sd.x

·  #sample.se.x

·  #sample.conf.x
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-2-17 11:01:41
DM小菜鸟 发表于 2014-12-29 20:16
·  n
非常感谢!!!!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群