cgci <-
function(x, alpha = 0.05, ks = 3.5)
{
#gets T_S,n with a coarse grid
# and the corresponding robust 100 (1-alpha)% CI
n <- length(x)
up <- 1 - alpha/2
med <- median(x)
madd <- mad(x, constant = 1)
d <- sort(x) ##get robust T_S,n CI
lo <- sum(x < (med - ks * madd))
hi <- sum(x > (med + ks * madd))
tp <- max(hi, lo)/n
if(tp == 0)
tp <- 0
if(tp > 0 && tp <= 0.01)
tp <- 0.01
if(tp > 0.01 && tp <= 0.1)
tp <- 0.1
if(tp > 0.1 && tp <= 0.25)
tp <- 0.25
if(tp > 0.25 && tp <= 0.4)
tp <- 0.4
if(tp > 0.4)
tp <- 0.49
tstmn <- mean(x, trim = tp)
#have obtained the two stage trimmed mean
ln <- floor(n * tp)
un <- n - ln
if(ln > 0) {
d[1:ln] <- d[(ln + 1)]
d[(un + 1):n] <- d[un]
}
den <- ((un - ln)/n)^2
swv <- var(d)/den
#got the scaled Winsorized variance
rdf <- un - ln - 1
rval <- qt(up, rdf) * sqrt(swv/n)
tslo <- tstmn - rval
tshi <- tstmn + rval
##got low and high endpoints of robust T_S,n CI
list(int = c(tslo, tshi), tp = tp)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.