The plotly package will let us make some interactive 3D plots

Education Spending and SAT Scores

First we load the data.

Visualizing the Data and Model in 3D

Let’s make a 3D plot of the two variable model.

How do the residuals look?

Not great. We probably want a quadratic term for frac… but first…

An Interaction Model

Let’s fit a model with an interaction

## (Intercept)        frac      expend frac:expend 
##     1057.12       -4.23        0.63        0.24

Not necessarily what we needed in this case.

A Quadratic Control for frac

Let’s add a quadratic term for frac to the no-interaction model

## (Intercept)        frac   I(frac^2)      expend 
##     1051.89       -6.38        0.05        7.91

That definitely looks better…

Quadratic and Interaction Together

What if we have both the quadratic term and the interaction?

## (Intercept)        frac      expend   I(frac^2) frac:expend 
##     1020.33       -6.04       14.70        0.05       -0.15

Nested Tests to Answer Targeted Questions

Does expenditure have additional predictive value after controlling for participation rate?

Let’s fit a reduced model that doesn’t use expenditure.

Now we can do a nested test to compare this to our model that has expenditure as well as the interaction.

## Analysis of Variance Table
## 
## Model 1: sat ~ frac + I(frac^2)
## Model 2: sat ~ frac + expend + I(frac^2) + expend:frac
##   Res.Df   RSS Df Sum of Sq      F  Pr(>F)  
## 1     47 34780                              
## 2     45 30467  2      4313 3.1852 0.05084 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Seems like the evidence is on the borderline of the standard threshold for statistical significance.