Course Outline
-
segmentGetting Started (Don't Skip This Part)
-
segmentAlgebra + Data Science
-
segmentChapter 1 - Exploring Variation in Data
-
segmentChapter 2 - Modeling Data with Functions
-
segmentChapter 3 - Assessing How Well Models Fit the Data
-
segmentResources
list High School / Algebra + Data Science (G)
2.5 Exploring Y-intercept
We have already explored how to use the intercept (\(b_0\)) and slope (\(b_1\)) to adjust where our linear function is on a graph. Now let’s dig a little deeper into these concepts.
Below we have depicted our function (\(\text{our_function}(X) = -5.5 + 49X\)) on a scatter plot using this code:
our_function <- function(X){-5.5 + 49*X}
gf_point(body_mass_kg ~ flipper_length_m, data = penguins) %>%
gf_function(our_function, color = "steelblue")
Trying to figure out where the y-intercept just by looking at the graph only works when the graph shows the y-axis all the way down to where \(X\) equals 0. That’s because the definition of y-intercept is the value of \(Y\) when \(X = 0\).
\(X=0\) not visible | \(X=0\) visible |
---|---|
|
|
The reason R doesn’t draw the y-axis down to the point where \(X=0\) in the scatter plot we’ve been looking at is because there are no penguins with flipper lengths of 0. If the scatter plot did go down to 0 on the x-axis, it would look like the graph on the right.
In the code block below, overlay a red dot to show the predicted \(Y\) when \(X = 0\). Hopefully the result will help us see how -5.5 is the y-intercept of our function.
require(coursekata)
# this creates our custom function
our_function <- function(X){-5.5 + 49*X}
# add a red dot at the predicted y when x=0 to this graph
gf_point(body_mass_kg ~ flipper_length_m, data = penguins) %>%
gf_function(our_function, color = "steelblue")
# this creates our custom function
our_function <- function(X){-5.5 + 49*X}
# add a red dot at the predicted y when x=0 to this graph
gf_point(body_mass_kg ~ flipper_length_m, data = penguins) %>%
gf_function(our_function, color = "steelblue") %>%
gf_point(our_function(0) ~ 0, color = "red")
ex() %>% {
check_function(., "gf_point", index = 1) %>% {
check_arg(., "object") %>% check_equal()
check_arg(., "data") %>% check_equal()
}
check_function(., "gf_function") %>% {
check_arg(., "object") %>% check_equal()
}
check_function(., "gf_point", index = 2) %>% {
check_arg(., 1) %>% check_equal()
check_arg(., 2) %>% check_equal()
}
}