Skip to content

Instantly share code, notes, and snippets.

@andrewheiss
Last active September 11, 2020 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewheiss/5541f3fb30a90aef10ccb9fc9c808d75 to your computer and use it in GitHub Desktop.
Save andrewheiss/5541f3fb30a90aef10ccb9fc9c808d75 to your computer and use it in GitHub Desktop.
library(tidyverse)
library(broom)

cars <- cars %>% 
  mutate(speed.c = scale(speed, center = TRUE, scale = FALSE))

mod1 <- lm(dist ~ speed.c, data = cars)

tidy(mod1)
#> # A tibble: 2 x 5
#>   term        estimate std.error statistic  p.value
#>   <chr>          <dbl>     <dbl>     <dbl>    <dbl>
#> 1 (Intercept)    43.0      2.18      19.8  1.06e-24
#> 2 speed.c         3.93     0.416      9.46 1.49e-12

glance(mod1)
#> # A tibble: 1 x 12
#>   r.squared adj.r.squared sigma statistic  p.value    df logLik   AIC   BIC
#>       <dbl>         <dbl> <dbl>     <dbl>    <dbl> <dbl>  <dbl> <dbl> <dbl>
#> 1     0.651         0.644  15.4      89.6 1.49e-12     1  -207.  419.  425.
#> # … with 3 more variables: deviance <dbl>, df.residual <int>, nobs <int>

summary(mod1)
#> 
#> Call:
#> lm(formula = dist ~ speed.c, data = cars)
#> 
#> Residuals:
#>     Min      1Q  Median      3Q     Max 
#> -29.069  -9.525  -2.272   9.215  43.201 
#> 
#> Coefficients:
#>             Estimate Std. Error t value Pr(>|t|)    
#> (Intercept)  42.9800     2.1750  19.761  < 2e-16 ***
#> speed.c       3.9324     0.4155   9.464 1.49e-12 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Residual standard error: 15.38 on 48 degrees of freedom
#> Multiple R-squared:  0.6511, Adjusted R-squared:  0.6438 
#> F-statistic: 89.57 on 1 and 48 DF,  p-value: 1.49e-12

Created on 2020-09-11 by the reprex package (v0.3.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment