GeneralizedT<-function(means,sds,ns,wts,k0=0,CI=FALSE,conf=0.95,null=0) ## means => a vector of group means ## example.. means <- c(1.12,3.51) ## sds => a vector of corresponding standard deviations ## ns => a vector of sample sizes ## wts => a vector of linear weights to be applied ## k0 => the constant that the linear combination is, by hypothesis, equal to ## default value is 0 ## CI => set this equal to TRUE if you want a confidence interval ## conf => the confidence level, by default 0.95 for a 95% interval ## null => an indicator as to where the null hypothesis region is relative to k0 ## 0 indicates equal to k0, i.e., a 2-sided test ## -1 indicates that the null hypothesis is of the form H0: kappa <= k0 ## 1 indicates that the null hypothesis is of the form H0: kappa >= k0 ## NOTE! Entering null incorrectly will result in the ## p-value being reported incorrectly! { if(CI) k0 <- 0 if(null==0)tails <- 2 else tails <- 1 J<-length(means) df<-sum(ns)-J VarEstimate <- sum((ns-1)*sds^2)/df num<-sum(wts*means)-k0 den<-sqrt(sum(wts^2/ns)*VarEstimate) t<-num/den if(!CI){ if(tails == 2) pval <- 2*pt(-abs(t),df) if(null < 0) pval <- 1 - pt(t,df) if(null > 0) pval <- pt(t,df) return(c(t,df,pval))} else{ tcrit <- qt(1-(1-conf)/2,df) dist <- tcrit*den lower <- num - dist upper <- num + dist return(c(lower,upper))} }