Week4 Modified
Week4 Modified
● If our test statistics are at least as extreme as our null hypothesis and within the region where they are
more “in favor” of the alternative, then we must reject the null
Hypothesis testing example
● It is believed that a bag of Lays is actually only 60% full, and
the rest of the bag is just air. A factory worker states that this is
no longer true and that Lays does not make bags that are 60%
full of air. What is the null and alternative hypothesis?
○ H0: µ = 0.6 The mean air in a bag of Lays is equal to 60%.
○ HA: µ ≠ 0.6 The mean air in a bag of Lays is not equal to 60%.
● You can likely imagine that the probability of this event being
observed is EXTREMELY small
● P(T ≤ t5) = 0. So we REJECT the null hypothesis in favor of the
alternative hypothesis.
● Alternatively, once we have the our test statistic, we can
determine what the rejection statistic needs to be such that we
reject.
○ t0.02,5 = -2.7565. Since our test statistic is lower, REJECT.
BREAK!
Other measures to assess linear regression
● We left off fitting a linear regression model, finding the Least
Squares estimation and assessing our model using R2.
● What other measures can we use to assess linear regression
models?
● The first is mean squared error (MSE). Literally the average
sum of squares of the residuals (or error).
MSE = (1/n)Σ(yi-ŷi)2
● The second is mean absolute error (MAE). Literally the
average absolute value of the residuals (or error).
MAE = (1/n)Σ|yi-ŷi|
● We’ll look at this top down, starting with the F-test…
○ Top-down meaning, start at the broadest test, and then
narrow down our methods.
F-tests
● Without involving the statistical theory, all we need to know is
that the F-test is much like a z-test or a t-test - it’s another
statistic from a distribution.
● However, this distribution tests if all the coefficients of the
linear regression model are 0. It’s a hypothesis test!
○ H 0: β 1 = β 2 = β 3 = β 4 = … = β p = 0
○ H A: β i ≠ 0
● In english, the null hypothesis states that your model is better
off having no variables (Just use the average value of your
dependent variable to predict). The alternative is that at least 1
is not equal to 0.
● The p-value for the F-test is assuming the null is true. If it’s less
than 5%, we REJECT the null hypothesis and have evidence
that having at least one of the coefficients is beneficial to our
model!
Individual t-tests for coefficients!
● Some of you may have spotted that our coefficients had t-value
statistics associated to them. What does this mean?...
● Since our model is based on our data, we ultimately come up
with a test statistic for our coefficients in the process!
● Our hypothesis testing for a simple linear regression model for
β1 would be:
○ H 0: β 1 = 0
○ H A: β 1 ≠ 0
○ This means that the population coefficient for the first
independent variable equals 0 is our null hypothesis. A
p-value less than 5% indicates we reject our null
hypothesis.
Variable / Feature selection for linear models
● We now have established that the p-values for the coefficients
is a good method of understanding if that coefficient should be
removed from our model. But what do we do now?
● Backward Selection is a process where we start off with every
variable in the model and remove one variable at a time until a
stopping rule (like p-value threshold, adjusted R2, etc) is hit,
until you cannot remove any more or all are removed.
● Forward Selection is a process where we start off with no
variable in the model and add one variable at a time based on a
stopping rule (greatest improvement to R2, greatest reduction
in MSE, etc) until you can no longer add more or all are added.
● Stepwise Selection is a process where you add a variable,
evaluate, then try backward selection, and then repeat by
adding another variable, trying backward selection, etc.
Challenges with step selections
● Doing any of the previously described methods come with
potential challenges…
● If you have a lot of variables and a lot of data - this could be
a very computationally expensive task refitting all these
models, so you must be less strict with your stopping rule …
which yields to poorer model performance.
● A variable dropped or not considered to be added might be
better to keep at a later step.
○ Say you did forward selection, you have 10 variables and
currently your selection stops are using Var1, Var4 and
Var6. Maybe Var8 is worth adding and does a good job to
helping your model, but only after you add a less
significant variable like Var 5.
Recommended Strategy
a
1 2 3 4
Ev
28