When we are comparing
the difference in means or when we are
comparing the averages between
groups that are more than two,
we will use ANOVA or analysis of variance.
We know that if there are only two groups,
we can use the t-test,
but when we are comparing
averages for more than two groups,
we use analysis of variance.
Working with our teaching evaluation dataset,
we took the teaching evaluation scores
and then we wanted to see what
would happen if we took
the instructors and divide them into three groups,
40 years and younger,
those between 40 and 57 years of age
and those that are 57 years or older.
We computed the average value for
teaching evaluation score for the three groups.
We wanted to determine if
the three mean values were statistically different.
To recap, we ran the analysis of
variance test, which uses F-distribution.
The p-value is less than 0.05.
We reject the null hypothesis
that averages of the group are
equal and concluded that
the differences are statistically significant.
Now, let us do this with the regression model.
We will use the statsmodel library
and also import the OLS function.
We will create or
initiate a linear model of the beauty score,
which is our y-variable.
Please note that when dealing with
a linear regression model,
the y-variable has to be a continuous variable.
Otherwise results will not be accurate.
Now, create the linear model
and fit it using the fit function.
Use the ANOVA_IM function to create
a table that prints out
the results of the test statistics.
The results will look like this.
It will print out the degree of freedom,
the sum of square F statistic and the p-value.
Like ANOVA from this api package,
we get the same results,
which is that we will reject the null hypothesis,
the averages of the group are equal and
conclude that the differences
are statistically significant.
You can also turn the age group values into
dummy values and run it like you
run the regression for t-test.
To do that, you will need to
create dummy variables for the age groups
using the get_dummies function in pandas.
It will look like this, where one means they
belong to that group and zero means otherwise.
Just like a binary variable,
values can only belong to one group.
Run the same as you did for the t-test by fitting
the variables into an OLS function,
predict, and print out the model summary.
We will get results like this.
Taking a closer look,
we can see the same results for
the F statistic and the p-value.