Learn R Programming

equatiomatic (version 0.1.0)

extract_rhs: Extract right-hand side

Description

Extract a data frame with list columns for the primary terms and subscripts from all terms in the model

Usage

extract_rhs(model)

Arguments

model

A fitted model

Value

A list with one element per future equation term. Term components like subscripts are nested inside each list element. List elements with two or more terms are interactions.

Examples

Run this code
# NOT RUN {
library(palmerpenguins)
mod1 <- lm(body_mass_g ~ bill_length_mm + species * flipper_length_mm, penguins)

extract_rhs(mod1)
#> # A tibble: 7 x 8
#>                                 term     estimate ...           primary  subscripts
#> 1                        (Intercept) -3341.615846 ...
#> 2                     bill_length_mm    59.304539 ...    bill_length_mm
#> 3                   speciesChinstrap   -27.292519 ...           species   Chinstrap
#> 4                      speciesGentoo -2215.913323 ...           species      Gentoo
#> 5                  flipper_length_mm    24.962788 ... flipper_length_mm
#> 6 speciesChinstrap:flipper_length_mm    -3.484628 ... flipper_length_mm Chinstrap,
#> 7    speciesGentoo:flipper_length_mm    11.025972 ... flipper_length_mm    Gentoo,

str(extract_rhs(mod1))
#> Classes <U+2018>lm<U+2019> and 'data.frame':	7 obs. of  8 variables:
#>  $ term      : chr  "(Intercept)" "bill_length_mm" "speciesChinstrap" "speciesGentoo" ...
#>  $ estimate  : num  -3341.6 59.3 -27.3 -2215.9 25 ...
#>  $ std.error : num  810.14 7.25 1394.17 1328.58 4.34 ...
#>  $ statistic : num  -4.1247 8.1795 -0.0196 -1.6679 5.7534 ...
#>  $ p.value   : num  4.69e-05 5.98e-15 9.84e-01 9.63e-02 1.97e-08 ...
#>  $ split     :List of 7
#>   ..$ : chr "(Intercept)"
#>   ..$ : chr "bill_length_mm"
#>   ..$ : chr "speciesChinstrap"
#>   ..$ : chr "speciesGentoo"
#>   ..$ : chr "flipper_length_mm"
#>   ..$ : chr  "speciesChinstrap" "flipper_length_mm"
#>   ..$ : chr  "speciesGentoo" "flipper_length_mm"
#>  $ primary   :List of 7
#>   ..$ : chr
#>   ..$ : chr "bill_length_mm"
#>   ..$ : chr "species"
#>   ..$ : chr "species"
#>   ..$ : chr "flipper_length_mm"
#>   ..$ : chr  "species" "flipper_length_mm"
#>   ..$ : chr  "species" "flipper_length_mm"
#>  $ subscripts:List of 7
#>   ..$ : chr ""
#>   ..$ : chr ""
#>   ..$ : chr "Chinstrap"
#>   ..$ : chr "Gentoo"
#>   ..$ : chr ""
#>   ..$ : Named chr  "Chinstrap" ""
#>   .. ..- attr(*, "names")= chr [1:2] "species" "flipper_length_mm"
#>   ..$ : Named chr  "Gentoo" ""
#>   .. ..- attr(*, "names")= chr [1:2] "species" "flipper_length_mm"
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab