![](/img/trans.png)
[英]Get Confidence Intervals for Phi statistics using Bootstrapping in R
[英]How to get confidence intervals by bootstrapping for quantile regressions by default
在我的統計類中,我們使用Stata,因為我是R用戶,我想在R中做同樣的事情。我得到了正確的結果,但似乎有點尷尬的方式來獲得像置信區間一樣簡單的東西。
這是我的原始解決方案:
library(quantreg)
na = round(runif(100, min=127, max=144))
f <- rq(na~1, tau=.5, data=ds)
s <- summary.rq(f, se="boot", R=1000)
coef(s)[1]
coef(s)[1]+ c(-1,1)*1.96*coef(s)[2]
我還在啟動包中進行了一些實驗,但我沒有讓它工作:
library(boot)
b <- boot(na, function(w, i){
rand_bootstrap_sample = w[i]
f <- rq(rand_bootstrap_sample~1, tau=.5)
return(coef(f))
}, R=100)
boot.ci(b)
給出錯誤:
bca.ci出錯(boot.out,conf,index [1L],L = L,t = to,t0 = t0.o,:估計調整'a'為NA
我的問題:
您的示例不會給我一個錯誤消息(Windows 7/64,R 2.14.2),因此它可能是隨機種子的問題。 因此,如果您使用一些隨機方法發布示例,最好添加一行set.seed; 看例子。
請注意,錯誤消息是指boot.ci的bca類型; 因為這個經常抱怨,通過明確地給出類型來取消選擇它。
我不知道為什么你在bootstrap中使用相當復雜的rq。 如果您真的想要了解rq,請忘記下面的簡單示例,但請提供更多詳細信息。
library(boot)
set.seed(4711)
na = round(runif(100, min=127, max=144))
b <- boot(na, function(w, i) median(w[i]), R=1000)
boot.ci(b,type=c("norm","basic","perc"))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.