title: How do I do an F-test to compare nested linear models in Python?
body: <p>I want to compare two nested linear models, call them m01, and m02 where m01 is the reduced model and m02 is the full model. I want to do a simple F-test to see if the full model adds significant utility over the reduced model.</p>
  
  <p>This is very simple in R. For example:</p>
  
  <pre><code>mtcars &lt;- read.csv("https://raw.githubusercontent.com/focods/WonderfulML/master/data/mtcars.csv")
  m01 &lt;- lm(mpg ~ am + wt, mtcars)
  m02 &lt;- lm(mpg ~ am + am:wt, mtcars)
  anova(m01, m02)
  </code></pre>
  
  <p>Gives me the following output:</p>
  
  <p><a href="https://i.stack.imgur.com/VwCUr.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/VwCUr.jpg" alt="enter image description here"></a></p>
  
  <p>Which tells me that adding the <strong>am: wt</strong> interaction term significantly improves the model. Is there a way to do something similar to this in Python/sklearn/statsmodels?</p>
  
  <p><strong>Edit:</strong> I looked at <a href="https://stackoverflow.com/questions/45243802/how-do-i-do-an-f-test-to-compare-nested-linear-models-in-python">this question</a> before posting this one and can not figure out how they are the same.  The other question is doing an F-test on two vectors.  This question is about comparing 2 nested linear models.</p>
  
  <p>I think this is what I need:</p>
  
  <p><a href="http://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.f_regression.html#sklearn.feature_selection.f_regression" rel="noreferrer">http://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.f_regression.html#sklearn.feature_selection.f_regression</a></p>
  
  <p>but am not sure what exactly to pass this function.  If anyone could provide or point to an example, that would be extremely helpful.</p>