knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#",
  fig.path = "man/figures/README",
  out.width = "100%"
)

zfit

CRAN status CRAN status shields R-CMD-check

TL;DR

If you are tired of doing the following:

dat <- mtcars |>
  filter(am == 1)
lm(mpg ~ wt + hp, data=dat)

and would like to do this instead:

mtcars |> 
  filter(am == 1) |>
  zlm(mpg ~ wt + hp)

then this little package might be something for you.

Overview


Installation

Install the release version from CRAN with:

install.packages("zfit")

Install the development version from GitHub with:

remotes::install_github("torfason/zfit")

Examples

The examples below assume that the following packages are loaded:

library(zfit)
library(dplyr)

The most basic use of the functions in this package is to pass a data.frame/tibble to zlm():

cars |> zlm(speed ~ dist)

Often, it is useful to process the data.frame/tibble before passing it to zlm():

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):

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:

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


torfason/zfit documentation built on Sept. 2, 2023, 3:12 p.m.