From 9637fe6c871b5977fe0b1a73c123ecfd91c52657 Mon Sep 17 00:00:00 2001 From: Joe Fowler Date: Wed, 8 Feb 2017 11:22:22 -0700 Subject: [PATCH] Moved trimcibt() to unmaintained status. --- README.md | 19 --------- UNMAINTAINED.md | 13 +++++++ src/RobustStats.jl | 3 -- src/functions.jl | 64 ------------------------------ src/unmaintained.jl | 95 +++++++++++++++++++++++++++++++++++++++++++++ src/utils.jl | 31 --------------- 6 files changed, 108 insertions(+), 117 deletions(-) diff --git a/README.md b/README.md index 2f06148..0e3f7bd 100644 --- a/README.md +++ b/README.md @@ -268,25 +268,6 @@ Compute a (1-α) confidence interval for a trimmed mean by bootstrap methods. p value: 0.086000 - - -####30. `trimcibt()` -Compute a (1-α) confidence interval for the trimmed mean using a bootstrap percentile t method. The default amount of trimming is tr=.2. side=true, indicates the symmetric two-sided method. side=false yields an equal-tailed confidence interval. NOTE: p.value is reported when side=true only. - - julia> trimcibt(x, nboot=5000, plotit=true) - Bootstrap .95 confidence interval for the trimmed mean - using a bootstrap percentile t method - - Estimate: 1.292180 - Statistic: 3.469611 - Confidence interval: 0.292162 2.292199 - p value: 0.022600 - -![plot](http://imageshack.us/a/img844/1970/34o.png) - - - - #### `pcorb` Compute a .95 confidence interval for Pearson's correlation coefficient. This function uses an adjusted percentile bootstrap method that gives good results when the error term is heteroscedastic. diff --git a/UNMAINTAINED.md b/UNMAINTAINED.md index ba7be6f..fd47031 100644 --- a/UNMAINTAINED.md +++ b/UNMAINTAINED.md @@ -128,3 +128,16 @@ Two examples are shown below to demonstrate the two ways of specifying data: Degrees of freedom: 2.00 8.11 Statistic: 28.990510 p value: 0.000202 + + +#### `trimcibt` +Compute a (1-α) confidence interval for the trimmed mean using a bootstrap percentile t method. The default amount of trimming is tr=.2. side=true, indicates the symmetric two-sided method. side=false yields an equal-tailed confidence interval. NOTE: p.value is reported when side=true only. + + julia> trimcibt(x, nboot=5000) + Bootstrap .95 confidence interval for the trimmed mean + using a bootstrap percentile t method + + Estimate: 1.292180 + Statistic: 3.469611 + Confidence interval: 0.292162 2.292199 + p value: 0.022600 diff --git a/src/RobustStats.jl b/src/RobustStats.jl index 79dbae7..7e038dd 100644 --- a/src/RobustStats.jl +++ b/src/RobustStats.jl @@ -39,9 +39,6 @@ export trimpb, pcorb, yuend, - - trimcibt, - bisquareWM, huberWM, trimean, diff --git a/src/functions.jl b/src/functions.jl index e74262e..a052a4f 100644 --- a/src/functions.jl +++ b/src/functions.jl @@ -685,70 +685,6 @@ end -# Compute a (1-α) confidence interval for the trimmed mean -# using a bootstrap percentile t method. -# -# The default amount of trimming is tr=.2 -# side=T, for true, indicates the symmetric two-sided method -# -# -# Side=F yields an equal-tailed confidence interval -# -# -# NOTE: p.value is reported when side=T only. -# - -function trimcibt{S <: Real}(x::AbstractArray{S}; tr::Real=0.2, alpha::Real=0.05, nboot::Integer=2000, side::Bool=true, - nullvalue::Real=0, seed=2, method::Bool=true) - if isa(seed, Bool) - if seed - srand(2) - end - else - srand(seed) - end - n=length(x) - test=(tmean(x, tr=tr)-nullval)./trimse(x, tr=tr) - randid=rand(1:n, n*nboot) - tempout=trimcibt_loop(x, n, nboot, tr, side, randid, test) - if side - tval=tempout[1] - pval=tempout[2] - end - icrit=floor((1-alpha)*nboot+0.5) - ibot=round(alpha*nboot/2)+1 - itop=nboot-ibot-1 - ci=zeros(2) - if method && side - METHOD="Bootstrap (1-α) confidence interval for the trimmed mean\nusing a bootstrap percentile t method\n" - elseif method && !side - METHOD="Bootstrap (1-α) confidence interval for the trimmed mean\nusing a bootstrap percentile t method\n[NOTE: p value is computed only when side=true]\n" - else - METHOD=nothing - end - if !side - ci[1]=tmean(x, tr=tr)-tempout[itop]*trimse(x, tr=tr) - ci[2]=tmean(x, tr=tr)-tempout[ibot]*trimse(x, tr=tr) - output = testOutput() - output.method = METHOD - output.estimate = tmean(x, tr=tr) - output.ci = ci - output.statistic = test - return output - else - ci[1]=tmean(x, tr=tr)-tval[icrit]*trimse(x, tr=tr) - ci[2]=tmean(x, tr=tr)+tval[icrit]*trimse(x, tr=tr) - output = testOutput() - output.method = METHOD - output.estimate = tmean(x, tr=tr) - output.ci = ci - output.statistic = test - output.p = pval - return output - end -end - - """`procb(x, y; seed=2)` Compute a (1-α) confidence interval for Pearson's correlation coefficient. diff --git a/src/unmaintained.jl b/src/unmaintained.jl index 50209e8..8d908a0 100644 --- a/src/unmaintained.jl +++ b/src/unmaintained.jl @@ -677,3 +677,98 @@ function t1waycore(args...) output.method = METHOD output end + + +# Compute a (1-α) confidence interval for the trimmed mean +# using a bootstrap percentile t method. +# +# The default amount of trimming is tr=.2 +# side=T, for true, indicates the symmetric two-sided method +# +# +# Side=F yields an equal-tailed confidence interval +# +# +# NOTE: p.value is reported when side=T only. +# + +function trimcibt{S <: Real}(x::AbstractArray{S}; tr::Real=0.2, alpha::Real=0.05, nboot::Integer=2000, side::Bool=true, + nullvalue::Real=0, seed=2, method::Bool=true) + if isa(seed, Bool) + if seed + srand(2) + end + else + srand(seed) + end + n=length(x) + test=(tmean(x, tr=tr)-nullval)./trimse(x, tr=tr) + randid=rand(1:n, n*nboot) + tempout=trimcibt_loop(x, n, nboot, tr, side, randid, test) + if side + tval=tempout[1] + pval=tempout[2] + end + icrit=floor((1-alpha)*nboot+0.5) + ibot=round(alpha*nboot/2)+1 + itop=nboot-ibot-1 + ci=zeros(2) + if method && side + METHOD="Bootstrap (1-α) confidence interval for the trimmed mean\nusing a bootstrap percentile t method\n" + elseif method && !side + METHOD="Bootstrap (1-α) confidence interval for the trimmed mean\nusing a bootstrap percentile t method\n[NOTE: p value is computed only when side=true]\n" + else + METHOD=nothing + end + if !side + ci[1]=tmean(x, tr=tr)-tempout[itop]*trimse(x, tr=tr) + ci[2]=tmean(x, tr=tr)-tempout[ibot]*trimse(x, tr=tr) + output = testOutput() + output.method = METHOD + output.estimate = tmean(x, tr=tr) + output.ci = ci + output.statistic = test + return output + else + ci[1]=tmean(x, tr=tr)-tval[icrit]*trimse(x, tr=tr) + ci[2]=tmean(x, tr=tr)+tval[icrit]*trimse(x, tr=tr) + output = testOutput() + output.method = METHOD + output.estimate = tmean(x, tr=tr) + output.ci = ci + output.statistic = test + output.p = pval + return output + end +end + + +function trimcibt_loop(x, n, nboot, tr, side, randid, test) + xbar=tmean(x, tr=tr) + temp=zeros(n) + tval=zeros(nboot) + if side + test=abs(test) + pval=0.0 + for i=1:(nboot*n) + if (i%n)!=0 + temp[i%n]=x[randid[i]]-xbar + else + temp[n]=x[randid[i]]-xbar + tval[div(i, n)]=abs(tmean(temp, tr=tr)./trimse(temp, tr=tr)) + pval += tval[div(i, n)]>=test? 1/nboot :0.0 + end + end + return sort!(tval), pval + else + for i=1:(nboot*n) + if (i%n)!=0 + temp[i%n]=x[randid[i]]-xbar + else + temp[n]=x[randid[i]]-xbar + tval[div(i, n)]=tmean(temp, tr=tr)./trimse(temp, tr=tr) + end + end + return sort!(tval) + end +end diff --git a/src/utils.jl b/src/utils.jl index e538ab5..6cb14ef 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -11,34 +11,3 @@ function duplicated(x::AbstractArray) end false end - - -function trimcibt_loop(x, n, nboot, tr, side, randid, test) - xbar=tmean(x, tr=tr) - temp=zeros(n) - tval=zeros(nboot) - if side - test=abs(test) - pval=0.0 - for i=1:(nboot*n) - if (i%n)!=0 - temp[i%n]=x[randid[i]]-xbar - else - temp[n]=x[randid[i]]-xbar - tval[div(i, n)]=abs(tmean(temp, tr=tr)./trimse(temp, tr=tr)) - pval += tval[div(i, n)]>=test? 1/nboot :0.0 - end - end - return sort!(tval), pval - else - for i=1:(nboot*n) - if (i%n)!=0 - temp[i%n]=x[randid[i]]-xbar - else - temp[n]=x[randid[i]]-xbar - tval[div(i, n)]=tmean(temp, tr=tr)./trimse(temp, tr=tr) - end - end - return sort!(tval) - end -end