So let's move on to another example of multi variable regression.
A very important example that underlies the topic of so called ANCOVA.
illustrate fitting multiple lines with different intercepts and different slopes.
So I'm going to use the swiss dataset that we've looked at previously.
the percent of that province that was working in agriculture as the predictor.
education really including those modified the effect of agriculture and fertility.
I just want to show you how to fit different lines, one for each group.
So let's take the Catholic variable.
notice that it's very bimodal.
majority Protestant, from this time period.
CatholicBin variable, and then now let me plot the data.
factor variable, that's zero for majority Protestant and one for majority Catholic.
And you can see the data there, there are some potential issues with the data.
And what I'm going to be describing which is to fit lines to the data.
Particularly these outlyingish looking observations.
we are going to be talking about outliers and influence points.
how they would relate to these model fits.
simply work on fitting a line where here now we want two separate lines.
Catholic provinces, and one for the majority Protestant provinces.
Let me describe some models that we could fit.
So here I have given some notation.
and zero if the province is over Is majority Protestant.
is an intercept plus a slope times x1.
the religion of the province entirely.
Let's consider a second model.
beta not plus beta 1 x1 plus beta 2 x2.
Now Let's think about this.
In the event that X two is equal to zero, if the province is majority protestant.
Then this works out to be beta knot plus beta one X one.
In the event that X two is equal to one.
no interaction Fits two models that have the same slope.
beta not and then beta one plus beta two for the second intercept.
Okay, let's consider one third model.
plus beta 3 X1 times X2.
Beta1X1 is still there Beta2X2 this term go to zero.
And beta 3 X1 times X2 is also zero, because X2 is zero in both those cases.
which is the case when the province is majority Catholic.
because remember X2 is equal to one in this case that we're considering.
there plus beta one plus beta three X one.
then we fit two lines, but now those two lines have different slopes.
If we omitted that interaction term, we fit two lines but they had the same slope.
Is going to be the change in the intercept going from Protestant to Catholic, right?
Here is the intercept for Protestant and here is the intercept for Catholic.
is going to be the change from the slope going from Protestant to Catholic, right?
So the slope for the, When X2 equals one, is beta one plus beta three.
It's going to have that extra term in there.
Okay, so let's try it with some code and I hope it will make sense.
And I think it's a little bit easier to see when you actually do the code.