What is first value that is passed into StatsModels predict function?
<p>I have the following OLS model from StatsModels:</p>

<pre><code>X = df['Grade']
y = df['Results']

X = statsmodels.tools.tools.add_constant(X)

mod = sm.OLS(y,X)
results = mod.fit() 
</code></pre>

<p>When trying to predict a new Y value for an X value of 4, I have to pass the following:</p>

<pre><code>results.predict([1,4])
</code></pre>

<p>I don't understand why an array with the first value being '1' needs to be passed in order for the predict function to work correctly. Why do I need to include a 1 instead of just saying:</p>

<pre><code>results.predict([4])
</code></pre>

<p>I'm not clear on the concept at work here. Does anybody know what's going on?</p>

<p>You are adding a constant to the regression equation with <code>X = statsmodels.tools.tools.add_constant(X)</code>. So your regressor X has two columns where the first column is a array of ones.</p>

<p>You need to do the same with the regressor that is used in prediction. So, the <code>1</code> means include the constant in the prediction. If you use zero instead, then the contribution of the constant (<code>0 * params[0]</code>) is zero and the prediction is only the slope effect.</p>

<p>The formula interface adds the constant automatically both for the regressor in the model and for the regressor in the prediction. However, with the pandas DataFrame or numpy ndarray interface, the constant needs to be added by the user both for the model and for predict.</p>

python statsmodels