f() or fVal()

f() or fVal()

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:
Output of f() function

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

Example output:
Output of sdoF


    • Related Articles

    • F test

      F test is a method for using the F ratio and F distribution to compare statistical models.
    • F-Distribution

      The F-Distribution is a probability distribution that models the sampling distribution of F under the empty model (the null hypothesis that there is no effect of the explanatory variable); this theoretical distribution takes into account both model ...
    • t-test

      The t-test uses the t-distribution (a sampling distribution of t) as a method of model comparison when you are evaluating a complex model against the empty model. It is very similar to using the F-distribution for model comparison, and, actually, ...
    • tally()

      The tally() function will count, or tally, the number of cases that are observed in each category of a variable. Example 1: Use tally() to count the number of observations in each category of a categorical variable. # Use tally() to count the number ...
    • anova()

      The anova() function will compute an analysis of variance (ANOVA) for a model, and present the statistics in an ANOVA table, that includes: - sums of squares (Sum Sq) - degrees of freedom (Df) - mean squares (Mean Sq) - F values - p-values (Pr(>F)) ...