forked from gergness/srvyr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
80 lines (63 loc) · 2.25 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
---
output:
md_document:
variant: markdown_github
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
# srvyr
[![Travis-CI Build Status](https://travis-ci.org/gergness/srvyr.svg?branch=master)](https://travis-ci.org/gergness/srvyr)
[![Coverage Status](https://img.shields.io/codecov/c/github/gergness/srvyr/master.svg)](https://codecov.io/github/gergness/srvyr?branch=master)
srvyr brings parts of [dplyr's](https://github.com/hadley/dplyr/) syntax to survey
analysis, using the [survey](https://CRAN.R-project.org/package=survey)
package.
srvyr focuses on calculating summary statistics from survey data, such as the
mean, total or quantile. It allows for the use of many dplyr verbs, such as
`summarize`, `group_by`, and `mutate`, the convenience of pipe-able functions,
lazyeval's style of non-standard evaluation and more consistent return types
than the survey package.
You can try it out:
```R
install.packages("srvyr")
# or for development version
# devtools::install_github("gergness/srvyr")
```
To create a `tbl_svy` object (the core concept behind the srvyr package),
use the function `as_survey_design()` with the bare column names of the names
you would use in `survey::svydesign()` object.
```R
library(survey)
data(api)
dstrata <- apistrat %>%
as_survey_design(strata = stype, weights = pw)
```
Now many of the dplyr verbs are available.
* Use `mutate()` if you want to add or modify a variable.
```R
dstrata <- dstrata %>%
mutate(api_diff = api00 - api99)
```
* `summarise()` calculates summary statistics such as mean, total, quantile or ratio.
```R
dstrata %>%
summarise(api_diff = survey_mean(api_diff, vartype = "ci")))
```
* Use `group_by()` if you want to summarise by groups.
```R
dstrata %>%
group_by(stype) %>%
summarise(api_diff = survey_mean(api_diff, vartype = "ci")))
```
You can still use functions from the survey package if you'd like to:
```R
svyglm(api99 ~ stype, dstrata)
```
If you'd like to contribute, please let me know! I started this as a way to learn
about R package development, so you'll have to bear with me as I learn, but I would
appreciate bug reports, pull requests or other suggestions!