require(mgcv)
lb <- c(4.1,1.2,1e-3,-1) ## weights
df <- c(2,1,1,1) ## degrees of freedom
nc <- c(1,1.5,4,1) ## non-centrality parameter
q <- c(1,6,20) ## quantiles to evaluate
psum.chisq(q,lb,df,nc)
## same by simulation...
psc.sim <- function(q,lb,df=lb*0+1,nc=df*0,ns=10000) {
r <- length(lb);p <- q
X <- rowSums(rep(lb,each=ns) *
matrix(rchisq(r*ns,rep(df,each=ns),rep(nc,each=ns)),ns,r))
apply(matrix(q),1,function(q) mean(X>q))
} ## psc.sim
psum.chisq(q,lb,df,nc)
psc.sim(q,lb,df,nc,100000)
Run the code above in your browser using DataLab