Skip to content

Commit

Permalink
Merge pull request #126 from iuliadmtru/remove_old_design
Browse files Browse the repository at this point in the history
Remove old design
  • Loading branch information
smishr authored Dec 6, 2022
2 parents 5107796 + 0c32205 commit de52790
Show file tree
Hide file tree
Showing 10 changed files with 8 additions and 161 deletions.
2 changes: 0 additions & 2 deletions src/Survey.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ using AlgebraOfGraphics
using CategoricalArrays

include("SurveyDesign.jl")
include("design.jl")
include("mean.jl")
include("quantile.jl")
include("total.jl")
Expand All @@ -25,7 +24,6 @@ include("show.jl")
export load_data
export AbstractSurveyDesign, SimpleRandomSample, StratifiedSample
export SurveyDesign
export design
export by
export ht_calc
export dim, colnames, dimnames
Expand Down
8 changes: 0 additions & 8 deletions src/boxplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,3 @@ function boxplot(design::AbstractSurveyDesign, x::Symbol, y::Symbol; kwargs...)

data * visual(BoxPlot) * map |> draw
end

function boxplot(design::design, x::Symbol, y::Symbol; kwargs...)
# TODO: change function, make it a wrapper
map = mapping(x, y; kwargs...)
data = AlgebraOfGraphics.data(design.variables)

data * visual(BoxPlot) * map |> draw
end
79 changes: 0 additions & 79 deletions src/design.jl

This file was deleted.

3 changes: 0 additions & 3 deletions src/dimnames.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ julia> dim(srs)
```
"""
dim(design::AbstractSurveyDesign) = size(design.data)
dim(design::design) = size(design.variables)

"""
colnames(design)
Expand Down Expand Up @@ -50,7 +49,6 @@ julia> colnames(srs)
```
"""
colnames(design::AbstractSurveyDesign) = names(design.data)
colnames(design::design) = names(design.variables)

"""
dimnames(design)
Expand All @@ -69,4 +67,3 @@ julia> dimnames(srs)
```
"""
dimnames(design::AbstractSurveyDesign) = [string.(1:size(design.data, 1)), names(design.data)]
dimnames(design::design) = [string.(1:size(design.variables, 1)), names(design.variables)]
18 changes: 0 additions & 18 deletions src/hist.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
sturges(n::Integer) = ceil(Int, log2(n)) + 1
sturges(vec::AbstractVector) = ceil(Int, log2(length(vec))) + 1
sturges(df::DataFrame, var::Symbol) = ceil(Int, log2(size(df[!, var], 1))) + 1
sturges(design::design, var::Symbol) = sturges(design.variables, var)

"""
sturges(design::SurveyDesign, var::Symbol)
Expand All @@ -22,7 +21,6 @@ sturges(design::AbstractSurveyDesign, var::Symbol) = sturges(design.data, var)

freedman_diaconis(v::AbstractVector) = round(Int, length(v)^(1 / 3) * (maximum(v) - minimum(v)) / (2 * iqr(v)))
freedman_diaconis(df::DataFrame, var::Symbol) = freedman_diaconis(df[!, var])
freedman_diaconis(design::design, var::Symbol) = freedman_diaconis(design.variables[!, var])

"""
freedman_diaconis(design::SurveyDesign, var::Symbol)
Expand Down Expand Up @@ -85,19 +83,3 @@ function hist(design::AbstractSurveyDesign, var::Symbol,
)
hist(design, var, bins(design, var); kwargs...)
end

function hist(design::design, var::Symbol,
bins::Union{Integer, AbstractVector} = freedman_diaconis(design, var);
normalization = :density,
kwargs...
)
hist = histogram(bins = bins, normalization = normalization, kwargs...)
data(design.variables) * mapping(var, weights = :weights) * hist |> draw
end

function hist(design::design, var::Symbol,
bins::Function;
kwargs...
)
hist(design, var, bins(design, var); kwargs...)
end
4 changes: 0 additions & 4 deletions src/plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,3 @@ save("scatter.png", s); nothing # hide
function plot(design::AbstractSurveyDesign, x::Symbol, y::Symbol; kwargs...)
data(design.data) * mapping(x, y, markersize = :weights) * visual(Scatter, marker = '') |> draw
end

function plot(design::design, x::Symbol, y::Symbol; kwargs...)
data(design.variables) * mapping(x, y, markersize = :weights) * visual(Scatter, marker = '') |> draw
end
9 changes: 0 additions & 9 deletions src/quantile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ function quantile(var, design::StratifiedSample, q)
return df
end

function quantile(var, design::design, q)
x = design.variables[!, var]
w = design.variables.probs
df = DataFrame(tmp = Statistics.quantile(Float32.(x), weights(w), q))
rename!(df, :tmp => Symbol(string(q) .* "th percentile"))

return df
end

# Inner method for `by`
function quantile(x, w, _, q)
df = DataFrame(tmp = Statistics.quantile(Float32.(x), weights(w), q))
Expand Down
16 changes: 0 additions & 16 deletions src/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,3 @@ function Base.show(io::IO, ::MIME"text/plain", design::SurveyDesign)
printinfo(io, "sampfraction", makeshort(design.sampfraction))
printinfo(io, "ignorefpc", string(design.ignorefpc); newline=false)
end

"Print information about a survey design initialized using `design`."
function Base.show(io::IO, ::MIME"text/plain", design::design)
printstyled(io, "Survey Design:\n"; bold=true)
printstyled(io, "variables: "; bold=true)
println(io, size(design.variables, 1), "x", size(design.variables, 2), " DataFrame")
printinfo(io, "id", makeshort(design.id))
printinfo(io, "strata", makeshort(design.variables.strata))
printinfo(io, "probs", makeshort(design.variables.probs))
printinfo(io, "fpc:\n popsize", makeshort(design.variables.popsize))
printinfo(io, " sampsize", makeshort(design.variables.sampsize); newline=false)
printstyled("\nnest: "; bold=true)
print(design.nest)
printstyled("\ncheck_strat: "; bold=true)
print(design.check_strat)
end
18 changes: 5 additions & 13 deletions test/dimnames.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,14 @@
apisrs = load_data("apisrs")
# make a copy to not modify the original dataset
apisrs_copy = copy(apisrs)
srs_new = SimpleRandomSample(apisrs_copy,popsize=:fpc,ignorefpc = true)
# make a new copy to use for the old design
apisrs_copy = copy(apisrs)
srs_old = design(id = :1, data = apisrs)
srs = SimpleRandomSample(apisrs_copy,popsize=:fpc,ignorefpc = true)
# `dim`
@test dim(srs_new)[1] == dim(srs_old)[1]
@test dim(srs_new)[2] == 42
@test dim(srs_old)[2] == 45
@test dim(srs)[2] == 42
# `colnames`
@test length(colnames(srs_new)) == dim(srs_new)[2]
@test length(colnames(srs_old)) == dim(srs_old)[2]
@test length(colnames(srs)) == dim(srs)[2]
# `dimnames`
@test length(dimnames(srs_new)[1]) == parse(Int, last(dimnames(srs_new)[1]))
@test dimnames(srs_new)[2] == colnames(srs_new)
@test length(dimnames(srs_old)[1]) == parse(Int, last(dimnames(srs_old)[1]))
@test dimnames(srs_old)[2] == colnames(srs_old)
@test length(dimnames(srs)[1]) == parse(Int, last(dimnames(srs)[1]))
@test dimnames(srs)[2] == colnames(srs)

# Stratified sampling tests
end
12 changes: 3 additions & 9 deletions test/quantile.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
@testset "quantile.jl" begin
# SimpleRandomSample
apisrs = load_data("apisrs")
apisrs_original = load_data("apisrs")

srs_new = SimpleRandomSample(apisrs,popsize=:fpc,ignorefpc = true)
srs_old = design(id = :1, data = apisrs)
apisrs = copy(apisrs_original)
srs_new = SimpleRandomSample(apisrs; popsize=:fpc, ignorefpc=true)
# 0.5th percentile
q_05_new = quantile(:api00, srs_new, 0.5)
q_05_old = quantile(:api00, srs_old, 0.5)
@test q_05_new == q_05_old
# 0.25th percentile
q_025_new = quantile(:api00, srs_new, 0.25)
q_025_old = quantile(:api00, srs_old, 0.25)
@test q_025_new == q_025_old

# StratifiedSample
end

0 comments on commit de52790

Please sign in to comment.