R/p_lm.r

Defines functions p_lm

Documented in p_lm

#' Fits linear models, with support for piping
#' 
#' A wrapper function for `lm()`, with the `data` argument listed first to support native piping.
#'
#' @param data the data
#' @param formula the formula
#' @param ... additional arguments passed to [stats::lm()].
#'
#' @returns an `lm` object
#' @export
#'
#' @examples
#' # load the data
#' data(nhanes)
#'
#' # define country
#' nhanes<-nhanes |> transform(
#'   country=base_match(dmdborn4,'USA'=1,'Other'=2)
#' )
#'
#' # fit a model
#' my_model<-nhanes |> p_lm(bpxosy1~country)
#' 
#' # obtain model details
#' my_model |> summary()
#' 
#' # obtain confidence interval
#' my_model |> confint()
p_lm<-function(data,formula,...) {
  stats::lm(formula=formula,data=data,...)
}

Try the baseverse package in your browser

Any scripts or data that you put into this service are public.

baseverse documentation built on April 29, 2026, 1:08 a.m.