The f() function (and, similarly, the fVal() function) will calculate the F value for a model.
Example 1:
Below are various methods for indexing the model in the argument of the f() function (they will all produce the same output). For any of these, f() can be replaced with fVal().
# Method 1: Find the F value for the Sex model of Thumb
f(Thumb ~ Sex, data = Fingers)
# Method 2: Save the model first
Sex_model <- lm(Thumb ~ Sex, data = Fingers)
f(Sex_model)
# Method 3: Use the lm() function within the f() function
f(lm(Thumb ~ Sex, data = Fingers))
Example output:
Example 2:
Below is an example of using the f() function to generate a sampling distribution of F, then plotting the distribution, and plotting the sample F value on the graph.
# Generate 1000 Fs from randomized (shuffled) data
# and save them into an object called sdoF
sdoF <- do(1000) * f(shuffle(Thumb) ~ Sex, data = Fingers)
# Save and print out the sample F value
sample_f <- f(Thumb ~ Sex, data = Fingers)
sample_f
# Plot the sampling distribution with the sample F
gf_histogram(~ f, data = sdoF, fill = ~lower(f, .95)) %>%
gf_point(0 ~ sample_f, color = "red")