The b1() function will calculate the b1 value for a model.
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 Sex model of Thumb
b1(Thumb ~ Sex, data = Fingers)
# Method 2: Save the model first
Sex_model <- lm(Thumb ~ Sex, data = Fingers)
b1(Sex_model)
# Method 3: Use the lm() function within the b1() function
b1(lm(Thumb ~ Sex, data = Fingers))
Example output:
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) ~ Sex, data = Fingers)
# Save and print out the sample b1 value
sample_b1 <- b1(Thumb ~ Sex, data = Fingers)
sample_b1
# Plot the sampling distribution with the sample b1
gf_histogram(~ b1, data = sdob1, fill = ~middl(b1, .95)) %>%
gf_point(0 ~ sample_b1, color = "red")