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

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 )
#> 
#> Call:
#> lm(formula = dist ~ speed, data = cars)
#> 
#> Coefficients:
#> (Intercept)        speed  
#>     -17.579        3.932  
#> 

# zfit works well with dplyr
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)
}
#> 
#> Call:
#> lm(formula = Sepal.Length ~ Sepal.Width + Petal.Width, data = .)
#> 
#> Coefficients:
#> (Intercept)  Sepal.Width  Petal.Width  
#>      2.6300       0.6664       0.3723  
#> 

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

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

  # Extremely naive filtering function for piped usage
  filter_naive <- function(data, column, value) {
    data[data[,column]==value,]
  }

  # 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_naive("Species","setosa") |>
    zlm(Sepal.Length ~ Sepal.Width + Petal.Width) |>
    zprint(summary)
}
#> Error in filter_naive(iris, "Species", "setosa"): could not find function "filter_naive"