-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
114 lines (82 loc) · 3.51 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#",
fig.path = "man/figures/README",
out.width = "100%"
)
```
[zfunction()]: https://torfason.github.io/zfit/reference/zfunction.html
[zfitter()]: https://torfason.github.io/zfit/reference/zfitter.html
[zprint()]: https://torfason.github.io/zfit/reference/zprint.html
[zlm()]: https://torfason.github.io/zfit/reference/zlm.html
[zglm()]: https://torfason.github.io/zfit/reference/zglm.html
[zlogit()]: https://torfason.github.io/zfit/reference/zglm.html
[zprobit()]: https://torfason.github.io/zfit/reference/zglm.html
[zpoisson()]: https://torfason.github.io/zfit/reference/zglm.html
# zfit <a href='https://github.com/torfason/zfit/'><img src='man/figures/logo.png' align="right" width="140px" /></a>
<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/zfit)](https://cran.r-project.org/package=zfit)
[![CRAN status shields](https://img.shields.io/badge/Git-`r desc::desc_get_version() `-success)](https://github.com/torfason/zmisc)
[![R-CMD-check](https://github.com/torfason/zfit/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/torfason/zfit/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
## TL;DR
If you are tired of doing the following:
``` r
dat <- mtcars |>
filter(am == 1)
lm(mpg ~ wt + hp, data=dat)
```
and would like to do this instead:
``` r
mtcars |>
filter(am == 1) |>
zlm(mpg ~ wt + hp)
```
then this little package might be something for you.
## Overview
```{r child="man/include/overview.Rmd"}
```
## Installation
Install the release version from [CRAN](https://CRAN.R-project.org/package=zfit) with:
``` r
install.packages("zfit")
```
Install the development version from [GitHub](https://github.com/torfason/zfit) with:
``` r
remotes::install_github("torfason/zfit")
```
## Examples
The examples below assume that the following packages are loaded:
``` r
library(zfit)
library(dplyr)
```
The most basic use of the functions in this package is to pass a `data.frame`/`tibble` to `zlm()`:
``` r
cars |> zlm(speed ~ dist)
```
Often, it is useful to process the `data.frame`/`tibble` before passing it to `zlm()`:
``` r
iris |>
filter(Species=="setosa") |>
zlm(Sepal.Length ~ Sepal.Width + Petal.Width)
```
The `zprint()` function provides a simple way to "tee" the piped object for printing a derived object, but then passing the *original* object onward through the pipe. The following code pipes an estimation model object into `zprint(summary)`. This means that the `summary()` function is called on the model being passed through the pipe, and the resulting summary is printed. However, `zprint(summary)` then returns the original model object, which is assigned to `m` (instead of assigning the summary object):
``` r
m <- iris |>
filter(Species=="setosa") |>
zlm(Sepal.Length ~ Sepal.Width + Petal.Width) |>
zprint(summary)
```
The `zprint()` function is quite useful within an estimation pipeline to print a summary of an object without returning the summary (using `zprint(summary)` as above), but it can also be used independently from estimation models, such as to print a summarized version of a tibble within a pipeline before further processing, without breaking the pipeline:
``` r
sw_subset <- starwars |>
zprint(count, homeworld, sort=TRUE) |> # prints counts by homeworld
filter(homeworld=="Tatooine")
sw_subset # sw_subset is ungrouped, but filtered by homeworld
```