Fall 2024
Advanced Statistical Modeling
Population of 1000 pairs
x
is uniformly distributed between 1 and 5.y
has a known linear relationship to x
: y = a * x + b
.a
is 1.5.b
is normally distributed, with a mean of 0.List columns can store values of arbitrary types
This code puts the fitted model in a column named model
. This is very useful when working with more complex data structures and avoids unnecessary (un)nesting.
Letβs first define three helper functions for simplicity:
Tidy vs. base R
get_R2
is a base R solution; get_slope
and get_icept
use tidy
from the broom
package.tidy(x)
converts x
into a tibble, which makes it easier to code * * consistently.pull
is similar to select
, except it returns a vector (as opposed to a tibble).The map
functions
map
applies a given function to each element of a vectormap_dbl
treats (coerces) the returned value as doublePlot all intercepts instead
Run plot(m)
for all diagnostic plots