我不确定@Metrics 的答案是否会为调查加权 quantreg 调用提供正确的标准误差。这是您尝试执行的操作的示例。您肯定遇到了错误,因为此时qr
嵌套在withReplicates
函数中的函数无法tau
一次处理多个参数(即使该qr
函数本身可能)。一次只打一个电话,也许是这样:)
library(survey)
library(quantreg)
# load some fake data
data(scd)
repweights <-
cbind(c(4,0,3,0,4,0), c(3,0,0,4,0,3),c(0,3,4,0,0,2),c(0,1,0,4,3,0))
# tack on the fake replicate weights
x <- cbind( scd , repweights )
# tack on some fake main weights
x[,9] <- c( 3 , 2 , 3 , 4 , 1 , 4 )
# name your weight columns
names( x )[ 5:9 ] <- c( paste0( 'rep' , 1:4 ) , "wgt" )
# create a replicate-weighted survey design object
scdrep <-
svrepdesign(
data = x ,
type = "BRR" ,
repweights = "rep" ,
weights = ~wgt ,
combined.weights = TRUE
)
# loop through each desired value of `tau`
for ( i in seq( 0.1 , 0.9 , by = 0.1 ) ){
print( i )
# follow the call described here:
# http://www.isr.umich.edu/src/smp/asda/Additional%20R%20Examples%20bootstrapping%20with%20quantile%20regression.pdf
print(
withReplicates(
scdrep ,
quote(
coef(
rq( arrests ~ alive , tau = i , weights = .weights )
)
)
)
)
}