# How to calculate Scheffe’s Test in R

How to calculate Scheffes Test in R, A one-way ANOVA is used to check if there is a statistically significant difference between the means of three or more independent groups.

If the aggregate p-value from the ANOVA table is less than a certain level of significance (ie, 0.05), we have enough evidence to conclude that at least one of the groups’ means differs from the others.

This, however, does not reveal which groups are distinct from one another. It simply indicates that the group means are not all equal.

We need to do a post-hoc test that can regulate the family-wise error rate in order to figure out exactly which groups are distinct from each other.

Scheffe’s test is one of the most widely used post hoc tests. This tutorial will show you how to use R to perform Scheffe’s test.

Before starting let’s make a quick view about Scheffé test

1) A Scheffé test is a type of statistical analysis test used to perform unintended comparisons after the fact.

2) Henry Scheffé, an American statistician, provided the inspiration for the exam.

3) In an analysis of variance (ANOVA) experiment, the Scheffé test is used to conduct unexpected comparisons between group means rather than intended comparisons.

4) The Scheffé test has the benefit of allowing the investigator to test any comparisons that seem intriguing.

5) The Scheffé test has less statistical power than tests designed for pre-planned comparisons, which is a drawback.

## Example: Scheffe’s Test in R

Let’s say we’re trying to figure out if three different species have varied sepal lengths. We can utilize the iris dataset to test this.

We can construct a one-way ANOVA to test for differences in mean sepal length across the three groups and apply Scheffe’s test to discover which groups are different using the procedures below in R.

Let’s say we’re trying to figure out if three different species have varied sepal lengths. We can utilize the iris dataset to test this.

We can construct a one-way ANOVA to test for differences in mean sepal length across the three groups and apply Scheffe’s test to discover which groups are different using the procedures below in R.

### Step 1: Load the dataset.

data("iris") head(iris)

Let’s view the first six rows of the data frame

Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1 5.1 3.5 1.4 0.2 setosa 2 4.9 3.0 1.4 0.2 setosa 3 4.7 3.2 1.3 0.2 setosa 4 4.6 3.1 1.5 0.2 setosa 5 5.0 3.6 1.4 0.2 setosa 6 5.4 3.9 1.7 0.4 setosa

### Step 2: Visualize the sepal length scores for each group.

The following code demonstrates how to visualize the distribution of sepal length scores for each group using boxplots.

boxplot(Sepal.Length ~ Species, data = iris, main = "Sepal Lengths by Species", xlab = "Species", ylab = "Sepal Length", col = "red", border = "black")

### Step 3: one-way ANOVA.

The following code demonstrates how to use a one-way ANOVA to compare mean sepal length scores in each group:

Now we can fit the one-way ANOVA model

model <- aov(Sepal.Length ~ Species, data = iris)

view the model summary

summary(model)

Df Sum Sq Mean Sq F value Pr(>F) Species 2 63.21 31.606 119.3 <2e-16 *** Residuals 147 38.96 0.265 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

The fact that the overall p-value is less than 0.05 indicates that each group’s sepal length score is different.

### Step 4: Perform Scheffe’s Test.

Now we can perform Scheffe’s test to see whether groups are distinct.

We’ll use the ScheffeTest() function from the DescTools package to run Scheffe’s test.

For our example, the following code demonstrates how to utilize this function.

library(DescTools) ScheffeTest(model)

Posthoc multiple comparisons of means: Scheffe Test

95% family-wise confidence level $Species diff lwr.ci upr.ci pval versicolor-setosa 0.930 0.6753953 1.1846047 8.1e-15 *** virginica-setosa 1.582 1.3273953 1.8366047 < 2e-16 *** virginica-versicolor 0.652 0.3973953 0.9066047 2.0e-08 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

**Average**

aggregate(. ~ Species, iris[,c(-2,-3,-4)], mean)

Species Sepal.Length 1 setosa 5.006 2 versicolor 5.936 3 virginica 6.588

The following is how to interpret the results:

A significant difference was observed between the following pairs since the p-value is less than 0.05.

- Versicolor and setosa
- Virginica and setosa
- Virginica and versicolor

In other words,

Versicolor showed significantly higher sepal length compared to setosa (p<0.05)

virginica showed significantly higher sepal length compared to setosa and versicolor (p<0.05).

Linear optimization using R » Optimal Solution »

Subscribe to our newsletter!