R/trimciv2.R

trimciv2 <-
function(x,tr=.2,alpha=.05,null.value=0,pr=TRUE){
#
#  Compute a 1-alpha confidence interval for the trimmed mean
#  Same as trimci, only a standardized measure of effect size is reported:
# the difference between the trimmed mean and hypothesized value divided by
# the Winsorized standard deviation, rescaled to estimate the standard deviation
# when sampling from a normal distribution. 
#
#  The default amount of trimming is tr=.2
#
library(MASS)
x<-elimna(x)
se<-sqrt(winvar(x,tr))/((1-2*tr)*sqrt(length(x)))
trimci<-vector(mode="numeric",length=2)
df<-length(x)-2*floor(tr*length(x))-1
trimci[1]<-mean(x,tr)-qt(1-alpha/2,df)*se
trimci[2]<-mean(x,tr)+qt(1-alpha/2,df)*se
test<-(mean(x,tr)-null.value)/se
sig<-2*(1-pt(abs(test),df))
if(tr==0)term=1
if(tr>0)term=sqrt(area(dnormvar,qnorm(tr),qnorm(1-tr))+2*(qnorm(tr)^2)*tr)
epow=(mean(x,tr)-null.value)*term/sqrt(winvar(x,tr=tr,na.rm=TRUE))
list(ci=trimci,estimate=mean(x,tr),test.stat=test,se=se,p.value=sig,n=length(x),Effect.Size=epow)
}
musto101/wilcox_R documentation built on May 23, 2019, 10:52 a.m.