list High School / Algebra + Data Science (G)

Book
  • High School / Advanced Statistics and Data Science I (ABC)
  • High School / Statistics and Data Science I (AB)
  • High School / Statistics and Data Science II (XCD)
  • High School / Algebra + Data Science (G)
  • College / Introductory Statistics with R (ABC)
  • College / Advanced Statistics with R (ABCD)
  • College / Accelerated Statistics with R (XCD)
  • CKHub: Jupyter made easy

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") 

A scatter plot of body_mass_kg predicted by flipper_length_m. A blue line of best fit is plotted on the graph and runs through the center of the data points.

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

On the left, a scatter plot of body_mass_kg predicted by flipper_length_m. A blue line of best fit is plotted on the graph and runs through the center of the data points. The x-axis begins at a flipper length of 0.17. A flipper length of zero is not visible on the plot.

On the right, a scatter plot of body_mass_kg predicted by flipper_length_m. A blue line of best fit is plotted on the graph and runs through the center of the data points. The x-axis is extended to begin at a flipper length of 0, and the y-axis is extended to a body mass of negative six. Since no penguins have a flipper length less than 0.17, all of the data points are clumped in the top right corner of the graph in order to make a flipper length of zero visible on the graph.

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() } }

A scatter plot of body_mass_kg predicted by flipper_length_m. A blue line of best fit is plotted on the graph and runs through the center of the data points. The x-axis is extended to begin at a flipper length of 0, and the y-axis is extended to a body mass of negative six. A red dot is plotted where x equals zero and y equals negative 5.5. The caption says: The predicted Y (body mass) is the y-intercept, -5.5.

Responses