Learn R Programming

doBy (version 4.6-3)

by-lmby: List of lm objects with a common model

Description

The data is split into strata according to the levels of the grouping factors and individual lm fits are obtained for each stratum.

Usage

lmBy(formula, data, id = NULL, ...)

Arguments

formula

A linear model formula object of the form y ~ x1 + ... + xn | g1 + ... + gm. In the formula object, y represents the response, x1,...,xn the covariates, and the grouping factors specifying the partitioning of the data according to which different lm fits should be performed.

data

A dataframe

id

A formula describing variables from data which are to be available also in the output.

Additional arguments passed on to lm().

Value

A list of lm fits.

Examples

Run this code
# NOT RUN {
bb <- lmBy(1 / uptake ~ log(conc) | Treatment, data=CO2)

coef(bb)

fitted(bb)
residuals(bb)

summary(bb)
coef(summary(bb))
coef(summary(bb), simplify=TRUE)

## A more modern alternative based on tidyverse end broom

if (require(tidyverse) && require(broom)){
  gg <- CO2 %>% group_by(Treatment)
  gg %>% do(broom::tidy(lm(1 / uptake ~ log(conc), data=.)))
}

# }

Run the code above in your browser using DataLab