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