install.packages("quantregGrowth")
library(quantregGrowth)
data(growthData) #load data
fit<-gcrq(y~ps(x, lambda=seq(0,100,l=20)), tau=c(0.025,0.975),n.boot=10,
data=growthData)
fit$boot.coef
结果是这样的:
, , 1
[,1] [,2]
[1,] -25.893935 -25.893835
[2,] 2.031909 2.032009
...
, , 2
[,1] [,2]
[1,] -0.09662335 -0.09652335
[2,] 0.51026535 0.51036535
....
, , 10
[,1] [,2]
[1,] 0.3677403 0.3678403
[2,] 0.3677403 1.4858461
....
我想计算Bootstrap置信区间,所以我需要得到所有[,1] [,1]元素之间的平均值,然后平均值在[,1] [,2]之间,然后平均值在[,2]之间[ ,1],最后在[,2] [,2]之间。如何编写循环函数来做到这一点?
答案 0 :(得分:1)
我不确定我是否正确理解了您的问题 无论如何,试试这个:
dms <- dim(fit$boot.coef)
myfun <- function(i,j) mean(fit$boot.coef[i,j,])
outer(1:dms[1], 1:dms[2], FUN=Vectorize(myfun))