zlm: Run an lm model in a pipe.

zlmR Documentation

Run an lm model in a pipe.

Description

This function wraps around the lm function in order to make it more friendly to pipe syntax (with the data first).

Usage

zlm(
  data,
  formula,
  subset,
  weights,
  na.action,
  method = "qr",
  model = TRUE,
  x = FALSE,
  y = FALSE,
  qr = TRUE,
  singular.ok = TRUE,
  contrasts = NULL,
  offset,
  ...
)

Arguments

data

A data.frame containing the model data.

formula

The formula to be fitted.

subset

See the lm function.

weights

See the lm function.

na.action

See the lm function.

method

See the lm function.

model

See the lm function.

x

See the lm function.

y

See the lm function.

qr

See the lm function.

singular.ok

See the lm function.

contrasts

See the lm function.

offset

See the lm function.

...

Other arguments to be passed to the lm function.

Value

A fitted model.

See Also

  • zglm is a wrapper for glm, to fit generalized linear models.

Examples

# Usage is possible without pipes
zlm( cars, dist ~ speed )

# zfit works well with dplyr and magrittr pipes
if ( require("dplyr", warn.conflicts=FALSE) ) {

  # Pipe cars dataset into zlm for fitting
  cars %>% zlm(speed ~ dist)

  # Process iris with filter before piping to zlm
  iris %>%
    filter(Species == "setosa") %>%
    zlm(Sepal.Length ~ Sepal.Width + Petal.Width)
}

# zfit also works well with the native pipe
if ( require("dplyr") && getRversion() >= "4.1.0" ) {

  # Pipe cars dataset into zlm for fitting
  cars |> zlm(speed ~ dist)

  # Process iris with filter() before piping. Print a
  # summary of the fitted model using zprint() before
  # assigning the model itself (not the summary) to m.
  m <- iris |>
    filter(Species == "setosa") |>
    zlm(Sepal.Length ~ Sepal.Width + Petal.Width) |>
    zprint(summary)
}


zfit documentation built on Aug. 27, 2023, 5:06 p.m.

Related to zlm in zfit...