11const SymbolCollection = Union{Symbol,Tuple{Symbol,Vararg{Symbol}},AbstractVector{Symbol}}
22
3+ """
4+ IccBootstrap{T} <: AbstractVector{T}
5+
6+ Thin wrapper around the per-iteration ICC values computed by [`icc`](@ref) from a
7+ `MixedModelBootstrap`. Behaves like the underlying vector for all `AbstractArray`
8+ purposes (indexing, iteration, `sort`, `quantile`, etc.), but is a distinct type so
9+ that [`confint`](@ref) can be specialized for it without pirating `MixedModelBootstrap`.
10+ """
11+ struct IccBootstrap{T} <: AbstractVector{T}
12+ values:: Vector{T}
13+ end
14+
15+ Base. size (x:: IccBootstrap ) = size (x. values)
16+ Base. getindex (x:: IccBootstrap , i:: Int ) = getindex (x. values, i)
17+ Base. setindex! (x:: IccBootstrap , v, i:: Int ) = setindex! (x. values, v, i)
18+ Base. IndexStyle (:: Type{<:IccBootstrap} ) = IndexLinear ()
19+ Base. similar (x:: IccBootstrap , :: Type{S} , dims:: Dims ) where {S} = similar (x. values, S, dims)
20+
321function _group_var (vc:: VarCorr , group:: Symbol )
422 return sum (abs2, vc. σρ[group]. σ)
523end
@@ -105,13 +123,13 @@ function icc(boot::MixedModelBootstrap,
105123 groups:: Union{Symbol,SymbolCollection} )
106124 all (ismissing, boot. σ) &&
107125 throw (ArgumentError (" Bootstrapping GLMM requires specifying the family." ))
108- return _icc (boot. σs, groups, abs2 .(boot. σ))
126+ return IccBootstrap ( _icc (boot. σs, groups, abs2 .(boot. σ) ))
109127end
110128
111129function icc (boot:: MixedModelBootstrap , family,
112130 groups:: Union{Symbol,SymbolCollection} )
113131 σ²res = _residual_variance (family)
114- return _icc (boot. σs, groups, σ²res)
132+ return IccBootstrap ( _icc (boot. σs, groups, σ²res) )
115133end
116134
117135function _icc (tbl, groups:: Union{Symbol,SymbolCollection} , σ²res)
@@ -121,40 +139,21 @@ function _icc(tbl, groups::Union{Symbol,SymbolCollection}, σ²res)
121139 return σ²_α ./ σ²
122140end
123141
124- function _icc_confint (values, level, method)
125- method in (:shortest , :equaltail ) ||
126- throw (ArgumentError (" `method` must be either :shortest or :equaltail." ))
127- method === :shortest && return shortestcovint (values, level)
128- tails = ((1 - level) / 2 , (1 + level) / 2 )
129- return Tuple (quantile (values, tails))
130- end
131-
132142"""
133- confint(boot::MixedModelBootstrap, groups; level::Real=0.95, method=:shortest)
134- confint(boot::MixedModelBootstrap, family, [groups]; level::Real=0.95, method=:shortest)
135-
136- Compute a bootstrap confidence interval for the [`icc`](@ref) computed from `boot`.
143+ confint(icc_boot::IccBootstrap; level::Real=0.95, method=:shortest)
137144
138- The `groups` and `family` arguments are as for [`icc`](@ref).
145+ Compute a bootstrap confidence interval for an [`IccBootstrap`](@ref), i.e. the
146+ result of calling [`icc`](@ref) on a `MixedModelBootstrap`.
139147
140148The keyword argument `level` is the confidence level (0.95 by default). The keyword
141149argument `method` determines whether the `:shortest`, i.e. highest density, interval
142150is used (the default) or the `:equaltail`, i.e. quantile-based, interval is used --
143151matching the behavior of `confint(::MixedModelBootstrap)` from MixedModels.jl.
144152"""
145- function StatsBase. confint (boot:: MixedModelBootstrap ,
146- groups:: Union{Symbol,SymbolCollection} ;
147- level:: Real = 0.95 , method= :shortest )
148- return _icc_confint (icc (boot, groups), level, method)
149- end
150-
151- function StatsBase. confint (boot:: MixedModelBootstrap , family;
152- level:: Real = 0.95 , method= :shortest )
153- return _icc_confint (icc (boot, family), level, method)
154- end
155-
156- function StatsBase. confint (boot:: MixedModelBootstrap , family,
157- groups:: Union{Symbol,SymbolCollection} ;
158- level:: Real = 0.95 , method= :shortest )
159- return _icc_confint (icc (boot, family, groups), level, method)
153+ function StatsBase. confint (icc_boot:: IccBootstrap ; level:: Real = 0.95 , method= :shortest )
154+ method in (:shortest , :equaltail ) ||
155+ throw (ArgumentError (" `method` must be either :shortest or :equaltail." ))
156+ method === :shortest && return shortestcovint (icc_boot, level)
157+ tails = ((1 - level) / 2 , (1 + level) / 2 )
158+ return Tuple (quantile (icc_boot, tails))
160159end
0 commit comments