lm_test {tidyrstats}R Documentation

Linear Model Testing for Grouped, Nested, or Ungrouped Data

Description

Applies a linear model to a data frame and returns tidy model summaries. Supports ungrouped, grouped (dplyr::group_by()), and nested (tidyr::nest_by()) input data.

Usage

lm_test(input_data, formula)

Arguments

input_data

A data frame or tibble. Can be ungrouped, grouped, or nested.

formula

A model formula, either quoted or unquoted (e.g., y ~ x * z , or "y ~ x * z").

Details

Designed to allow seamless 'in-line' chaining to fit linear models to columns of a tibble. Compatible with ungrouped, grouped or nested input. Compatible with native and magrittr pipe. Uses broom::tidy() to extract model summaries.

Value

A tibble with tidy model output sorted by p value, including:

term

Model term (e.g., intercept, predictors, interactions)

estimate

Estimated coefficient / beta

std.error

Standard error of the estimate

statistic

t-statistic

p.value

p-value for the hypothesis test

If the input is grouped or nested, group identifiers are retained in the output. In the nested case, nested terms are relocated to the left-most column of the tibble.

Examples

library(ggplot2)
library(dplyr)

# Ungrouped
mpg |> lm_test( cty ~ hwy * cyl)

# Grouped
mpg |> group_by(class) |> lm_test(cty ~ hwy * cyl)

# Nested
mpg  |> nest_by(class) |> lm_test(cty ~ hwy * cyl)


[Package tidyrstats version 0.1.0 Index]