b1()

b1()

The b1() function will calculate the b1 value for a model.

Idea
Example 1:

Below are various methods for indexing the model in the argument of the b1() function (they will all produce the same output). 

# Method 1: Find the b1 value for the Gender model of Thumb
b1(Thumb ~ Gender, data = Fingers)

# Method 2: Save the model first
gender_model <- lm(Thumb ~ Gender, data = Fingers)
b1(gender_model)

# Method 3: Use the lm() function within the b1() function
b1(lm(Thumb ~ Gender, data = Fingers))

Example output:

Output of b1() function

Idea
Example 2:

Below is an example of using the b1() function to generate a sampling distribution of b1, then plotting the distribution, and plotting the sample b1 value on the graph.

# Generate 1000 b1s from randomized (shuffled) data
# and save them into an object called sdob1
sdob1 <- do(1000) * b1(shuffle(Thumb) ~ Gender, data = Fingers)

# Save and print out the sample b1 value
sample_b1 <- b1(Thumb ~ Gender, data = Fingers)
sample_b1

# Plot the sampling distribution with the sample b1
gf_histogram(~ b1, data = sdob1fill = ~middl(b1, .95)) %>%
    gf_point(0 ~ sample_b1, color = "red")

Example output:

Output of sdob1

    • Related Articles

    • intercept

      Intercept is the value where a line intersects with the y-axis; the value of y when the x is 0; for example, in the equation for a line, y = mx + b, the y-intercept is represented by b.
    • recode()

      The recode() function can be used to rename any of the values of a variable. Example: # recode the variable `Year` and save it is a new column in the data frame Fingers$Year_recode <- recode(Fingers$Year, "1" = "First", "2" = "Second", "3" = "Third", ...
    • Appendix of Data Frames Used in Course Textbook

      All data frames listed below are automatically preloaded when you run library(coursekata). Link to full repository of R documentation: https://www.rdocumentation.org/ Data Frame Name and Link to R Documentation Ames BikeCommute FatMice18 Fingers ...
    • Page Won't Load or Button Doesn't Work

      Page Won't Load / Button Doesn't Work The problem:  You click on a page in CourseKata and the content won't load (page won't load) You click on a button in CourseKata and nothing happens (button doesn't work) What to try:  Note: the suggestions below ...
    • Printing Pages of the Book

      If you need to print pages of the book, you may find that printing them from Chrome results in oddly-formatted pages.  You will get better-formatted pages if you print using either Safari or Firefox as your browser. If using Safari, go the the Safari ...