Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nalimilan committed Jun 25, 2017
1 parent d249762 commit 7c02e23
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 21 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ git:
# - julia -e 'Pkg.clone(pwd()); Pkg.build("StatsBase"); Pkg.test("StatsBase"; coverage=true)'
after_success:
- julia -e 'cd(Pkg.dir("StatsBase")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
- julia -e 'Pkg.add("Documenter")'
- julia -e 'cd(Pkg.dir("StatsBase")); include(joinpath("docs", "make.jl"))'
- julia -e 'Pkg.add("Documenter"); cd(Pkg.dir("StatsBase")); include(joinpath("docs", "make.jl"))'
2 changes: 2 additions & 0 deletions docs/src/statmodels.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ coeftable
confint
deviance
dof
fit
fit!
loglikelihood
nobs
nulldeviance
Expand Down
25 changes: 14 additions & 11 deletions src/counts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#### functions for counting a single list of integers (1D)
"""
addcounts!(r, x, levels, [wv])
addcounts!(r, x, levels::UnitRange{<:Int}, [wv::AbstractWeights])
Add the number of occurrences in `x` of each value in `levels` to an existing
array `r`. If a weighting vector `wv` is specified, the sum of weights is used
Expand Down Expand Up @@ -55,23 +55,26 @@ end


"""
counts(x, levels=span(x), [wv::AbstractWeights])
counts(x, [wv::AbstractWeights])
counts(x, levels::UnitRange{<:Integer}, [wv::AbstractWeights])
counts(x, k::Integer, [wv::AbstractWeights])
Count the number of times each value in `x` occurs. If `levels` is provided, only values
falling in that range will be considered (the others will be ignored without
raising an error or a warning). If an integer `k` is provided, only values in the
range `1:k` will be considered.
Count the number of times that values in the range `levels` occur in
`x`. The output is a vector of length `length(levels)`. If a weighting
vector `wv` is specified, the sum of the weights is used rather than the
If a weighting vector `wv` is specified, the sum of the weights is used rather than the
raw counts.
The output is a vector of length `length(levels)`.
"""
function counts end

counts(x::IntegerArray, levels::IntUnitRange) =
addcounts!(zeros(Int, length(levels)), x, levels)
counts(x::IntegerArray, levels::IntUnitRange, wv::AbstractWeights) =
addcounts!(zeros(eltype(wv), length(levels)), x, levels, wv)

"""
counts(x, k::Integer, [wv::AbstractWeights])
Count the number of times integers in the range 1 to `k` occur in `x`.
"""
counts(x::IntegerArray, k::Integer) = counts(x, 1:k)
counts(x::IntegerArray, k::Integer, wv::AbstractWeights) = counts(x, 1:k, wv)
counts(x::IntegerArray) = counts(x, span(x))
Expand Down
1 change: 0 additions & 1 deletion src/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ julia> indicatormat([1 2 2], 2)
2×3 Array{Bool,2}:
true false false
false true true
```
"""
function indicatormat(x::IntegerArray, k::Integer; sparse::Bool=false)
Expand Down
7 changes: 4 additions & 3 deletions src/sampling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,12 @@ Pseudo-code:
n = length(a)
k = length(x)
create an array of index inds = [1:n]
# Create an array of the indices
inds = collect(1:n)
for i = 1:k
swap inds[i] with a random one in inds[i:n]
set x[i] = a[inds[i]]
# swap element `i` with another random element in inds[i:n]
# set element `i` in `x`
end
```
Expand Down
7 changes: 7 additions & 0 deletions src/statmodels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,14 @@ Return the variance-covariance matrix for the coefficients of the model.
"""
vcov(obj::StatisticalModel) = error("vcov is not defined for $(typeof(obj)).")

"""
Fit a statistical model.
"""
fit(obj::StatisticalModel, args...) = error("fit is not defined for $(typeof(obj)).")

"""
Fit a statistical model in-place.
"""
fit!(obj::StatisticalModel, args...) = error("fit! is not defined for $(typeof(obj)).")

"""
Expand Down
8 changes: 4 additions & 4 deletions src/weights.jl
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,8 @@ Compute the weighted median of `x`, using weights given by a weight vector `w`
(of type `AbstractWeights`). The weight and data vectors must have the same length.
The weighted median ``x_k`` is the element of `x` that satisfies
``\sum_{x_i < x_k} w_i \le \frac{1}{2} \sum_{j} w_j`` and
``\sum_{x_i > x_k} w_i \le \frac{1}{2} \sum_{j} w_j``.
``\\sum_{x_i < x_k} w_i \\le \\frac{1}{2} \\sum_{j} w_j`` and
``\\sum_{x_i > x_k} w_i \\le \\frac{1}{2} \\sum_{j} w_j``.
If a weight has value zero, then its associated data point is ignored.
If none of the weights are positive, an error is thrown.
Expand Down Expand Up @@ -563,9 +563,9 @@ values `p`, using weights given by a weight vector `w` (of type `AbstractWeights
Weights must not be negative. The weights and data vectors must have the same length.
The quantile for `p` is defined as follows. Denoting
``S_k = (k-1)w_k + (n-1) \sum_{i<k}w_i``, define ``x_{k+1}`` the smallest element of `x`
``S_k = (k-1)w_k + (n-1) \\sum_{i<k}w_i``, define ``x_{k+1}`` the smallest element of `x`
such that ``S_{k+1}/S_{n}`` is strictly superior to `p`. The function returns
``(1-\gamma) x_k + \gamma x_{k+1}`` with ``\gamma = (pS_n- S_k)/(S_{k+1}-S_k)``.
``(1-\\gamma) x_k + \\gamma x_{k+1}`` with ``\\gamma = (pS_n- S_k)/(S_{k+1}-S_k)``.
This corresponds to R-7, Excel, SciPy-(1,1) and Maple-6 when `w` contains only ones
(see [Wikipedia](https://en.wikipedia.org/wiki/Quantile)).
Expand Down

0 comments on commit 7c02e23

Please sign in to comment.