Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve documentation for new design, continuation of draft PR #49 #54

Merged
merged 63 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
d840ed4
Add sampfraction ignorefpc to print function
smishr Sep 5, 2022
67aeb5e
Add type specification (`Symbol`) for first argument of `svymean`
iuliadmtru Sep 5, 2022
62b60aa
Add Index and API to the documentation, incomplete
iuliadmtru Sep 5, 2022
de5524c
Add error checks key args of SRS contructor
smishr Sep 6, 2022
298c41f
Rename "example.jl" to "load_data.jl", change documentation for `load…
iuliadmtru Sep 7, 2022
7176b42
Add documentation for `load_data`
iuliadmtru Sep 7, 2022
f6c16d0
Merge branch 'xKDR:design_update' into design_update
smishr Sep 7, 2022
a7f5df5
Merge branch 'design_update' into design_update
ayushpatnaikgit Sep 8, 2022
e4c5216
save commits Add isa for categorical variables
smishr Sep 9, 2022
f35be8a
Merge branch 'design_update' of https://github.com/smishr/Survey.jl i…
smishr Sep 9, 2022
c802774
Pull changes from `design_update` and add documentation for `svymean`…
iuliadmtru Sep 9, 2022
5623a16
Redid old PR update, changed/updated tests for new design
smishr Sep 19, 2022
862b236
Add svymean categoricalarray functionality
smishr Sep 21, 2022
a0d3544
Add svytotal CategoricalArray output support
smishr Sep 21, 2022
1ef381d
edit column name from count to counts
smishr Sep 21, 2022
06f9bbd
Merge pull request #53 from smishr/design_update
ayushpatnaikgit Sep 21, 2022
8a4d12c
Add Stratified Sample object struct
smishr Sep 21, 2022
f990e6d
Add svymean mutliple dispatch and support Stratified mean
smishr Sep 21, 2022
04f3d84
Merge branch 'xKDR:design_update' into design_update
smishr Sep 23, 2022
5f398c7
Add sbytotal for Stratified
smishr Sep 23, 2022
a1b0e28
demerge
smishr Sep 23, 2022
86f8ed4
Add variance for StratifiedSample svymean and svytotal
smishr Sep 29, 2022
84a2636
Add categorical support svytotal svymean, not fully correct yet
smishr Sep 30, 2022
13c829f
svytotal strata case
smishr Sep 30, 2022
e93ae7a
Shikhar manual testing code
smishr Sep 30, 2022
1bfdfa9
Merge pull request #58 from smishr/design_update
smishr Sep 30, 2022
d25f884
Change ... to reduce.
sayantikaSSG Oct 7, 2022
d1bf631
Merge pull request #61 from sayantikaSSG/design_update
ayushpatnaikgit Oct 8, 2022
9c68108
Remove duplicate code and comments and rephrase error messages for SRS
iuliadmtru Oct 8, 2022
6458bfa
Remove duplicate code and comments and rephrase error messages for St…
iuliadmtru Oct 9, 2022
a1367e7
CompatHelper: bump compat for CairoMakie to 0.9, (keep existing compat)
Oct 13, 2022
ebfc090
Remove duplicate code and comments and add TODO comments
iuliadmtru Oct 15, 2022
f934c37
Generalize `show` method for all `AbstractSurveyDesign` subtypes
iuliadmtru Oct 15, 2022
7f5a271
Change description of helper function and move `show` method to the top
iuliadmtru Oct 15, 2022
6a0df4b
Remove unnecessary comment
iuliadmtru Oct 15, 2022
63edd63
Remove comments and format code
iuliadmtru Oct 15, 2022
8cff71a
Add TODO comment inside function body, not inside docstring
iuliadmtru Oct 15, 2022
d8ee896
Remove unnecessary comment
iuliadmtru Oct 15, 2022
b726657
Remove unnecessary comments and format code
iuliadmtru Oct 15, 2022
1254224
Remove comments and error case for not passing `q` parameter
iuliadmtru Oct 15, 2022
c32c543
Remove and rephrase comments and docstrings
iuliadmtru Oct 15, 2022
8b02ab6
Remove comments
iuliadmtru Oct 15, 2022
e24da83
Remove and rephrase comments
iuliadmtru Oct 15, 2022
fbe9f00
Remove and rephrase comments
iuliadmtru Oct 15, 2022
1d12f7d
Remove comments
iuliadmtru Oct 15, 2022
466cc35
Remove and rephrase comments
iuliadmtru Oct 15, 2022
21d784d
Remove comments
iuliadmtru Oct 15, 2022
2b4f4a6
Remove and rephrase comments
iuliadmtru Oct 15, 2022
44079c6
Remove and rephrase comments
iuliadmtru Oct 15, 2022
86d139d
Implement new function for nice printing and move `show` to a separat…
iuliadmtru Oct 15, 2022
2ba7766
Merge pull request #62 from xKDR/compathelper/new_version/2022-10-13-…
ayushpatnaikgit Oct 16, 2022
ffea267
Merge pull request #63 from iuliadmtru/minor_corrections
ayushpatnaikgit Oct 16, 2022
e2a35b6
Merge pull request #65 from xKDR/main
iuliadmtru Oct 17, 2022
6151336
Merge branch 'xKDR:main' into docs_improve
iuliadmtru Oct 17, 2022
0a110cd
Pull and integrate changes from `design_update` and `main`
iuliadmtru Oct 17, 2022
5668157
Merge branch 'docs_improve' of github.com:iuliadmtru/Survey.jl into d…
iuliadmtru Oct 17, 2022
406eb4a
Rephrase and reorder docstrings
iuliadmtru Oct 23, 2022
96cfd2f
Correct `show` for `svydesign` and move it to the show.jl file
iuliadmtru Oct 26, 2022
48c3851
Include show.jl after svydesign.jl
iuliadmtru Oct 26, 2022
40685c7
Correct doctests
iuliadmtru Oct 26, 2022
4c5d5e7
Rename `GeneralSample` back to `ClusterSample`
iuliadmtru Oct 31, 2022
3f52fc5
Correct the path for doc image
iuliadmtru Oct 31, 2022
93c686c
Rephrase and remove outdated documentation
iuliadmtru Oct 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ version = "0.11.1"
AlgebraOfGraphics = "cbdf2221-f076-402e-a563-3d30da359d67"
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
GLM = "38e38edf-8417-5370-95a0-9cbb8c7f171a"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand All @@ -16,7 +17,7 @@ StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
[compat]
AlgebraOfGraphics = "0.6"
CSV = "0.10"
CairoMakie = "0.8"
CairoMakie = "0.8, 0.9"
DataFrames = "1"
GLM = "1"
StatsBase = "0.33"
Expand Down
Binary file modified docs/src/assets/hist.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/src/assets/scatter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 58 additions & 3 deletions docs/src/examples.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,62 @@
# Examples

The following examples use the Academic Performance Index (API) dataset for Californian schools.
The following examples use the
[Academic Performance Index](https://r-survey.r-forge.r-project.org/survey/html/api.html)
(API) dataset for Californian schools. The data sets contain information for all schools
with at least 100 students and for various probability samples of the data.

```@docs
svyby(formula::Symbol, by, design::svydesign, func::Function, params = [])
The API program has been discontinued at the end of 2018. Information is archived at
[https://www.cde.ca.gov/re/pr/api.asp](https://www.cde.ca.gov/re/pr/api.asp)

## Simple Random Sample

Firstly, a survey design needs a dataset from which to gather information. A dataset
can be loaded as a `DataFrame` using the `load_data` function:

```julia
julia> apisrs = load_data("apisrs");
```

Next, we can build a design. The most basic survey design is a simple random sample design.
A [`SimpleRandomSample`](@ref) can be instantianted by calling the constructor:

```julia
julia> srs = SimpleRandomSample(apisrs; weights = :pw)
SimpleRandomSample:
data: 200x42 DataFrame
weights: 31.0, 31.0, 31.0, ..., 31.0
probs: 0.0323, 0.0323, 0.0323, ..., 0.0323
fpc: 6194, 6194, 6194, ..., 6194
popsize: 6194
sampsize: 200
sampfraction: 0.0323
ignorefpc: false
```

With a `SimpleRandomSample` (as well as with any subtype of [`AbstractSurveyDesign`](@ref))
it is possible to calculate estimates of the mean or population total for a given variable,
along with the corresponding standard errors.

```julia
julia> svymean(:api00, srs)
1×2 DataFrame
Row │ mean sem
│ Float64 Float64
─────┼──────────────────
1 │ 656.585 9.24972

julia> svytotal(:api00, srs)
1×2 DataFrame
Row │ total se_total
│ Float64 Float64
─────┼─────────────────────
1 │ 4.06689e6 57292.8
```

The design can be tweaked by specifying the population or sample size or whether
or not to account for finite population correction (fpc). By default the weights
are equal to one, the sample size is equal to the number of rows in `data` and the
fpc is not ignored. The population size is calculated from the weights.

When `ignorefpc` is set to `false` the `fpc` is calculated from the sample and population
sizes. When it is set to `true` it is set to 1.
30 changes: 27 additions & 3 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,32 @@ This package is the Julia implementation of the [Survey package in R](https://cr

At [xKDR](https://xkdr.org/) we processed millions of records from household surveys using the survey package in R. This process took hours of computing time. By implementing the code in Julia, we are able to do the processing in seconds. In this package we have implemented the functions `svymean`, `svyquantile` and `svysum`. We have kept the syntax between the two packages similar so that we can easily move our existing code to the new language.

Documentation for [Survey](https://github.com/Survey.jl).
## Index

```@autodocs
Modules = [Survey]
```@index
Module = [Survey]
Private = false
```

## API
```@docs
load_data
AbstractSurveyDesign
SimpleRandomSample
StratifiedSample
ClusterSample
dim(design::AbstractSurveyDesign)
colnames(design::AbstractSurveyDesign)
dimnames(design::AbstractSurveyDesign)
svymean(x::Symbol, design::SimpleRandomSample)
svytotal(x::Symbol, design::SimpleRandomSample)
svyby
svyglm
svyplot(design::AbstractSurveyDesign, x::Symbol, y::Symbol; kwargs...)
svyhist(design::AbstractSurveyDesign, var::Symbol,
bins::Union{Integer, AbstractVector} = freedman_diaconis(design, var);
normalization = :density,
kwargs...
)
svyboxplot(design::AbstractSurveyDesign, x::Symbol, y::Symbol; kwargs...)
```
6 changes: 5 additions & 1 deletion src/Survey.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,29 @@ using GLM
using LinearAlgebra
using CairoMakie
using AlgebraOfGraphics
using CategoricalArrays

include("SurveyDesign.jl")
include("svydesign.jl")
include("svymean.jl")
include("svyquantile.jl")
include("svytotal.jl")
include("example.jl")
include("load_data.jl")
include("svyglm.jl")
include("svyhist.jl")
include("svyplot.jl")
include("dimnames.jl")
include("svyboxplot.jl")
include("svyby.jl")
include("ht.jl")
include("show.jl")

export load_data
export AbstractSurveyDesign, SimpleRandomSample, StratifiedSample
export svydesign
export svyglm
export svyby
export ht_calc
export dim, colnames, dimnames
export svymean, svytotal, svyquantile
export @formula
Expand Down
Loading