<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 regression - fitting a model to data.  The goal is to describe the relationship between the dependent variables and the explanatory variables.
multiple regression multiple explanatory variables.
linear regression wen the relationship is linear.
$$
y = \beta_0 + \beta_1x_1 + \beta_2x_2 + \epsilon
$$
where $\beta_0$ is the intercept, $\beta_1$ is the parameter association with $x_1$, $\beta_2$ is the parameter associated with $x_2$ and $\epsilon$ is the residual due to random variation or unknown factors.
ordinary least squares.  Given a sequence of values for y and sequences for $x_1$ and $x_2$, we can find the beta parameters that minimize $epsilon^2$
Step1:  spurious - result for which there is no obvious mechanism that would explain it. e.g. why would first babies be lighter than others?  Perhaps because mothers of first babies are younger...
<ASSISTANT_TASK:>
Python Code:
live, firsts, others = first.MakeFrames()
formula = 'totalwgt_lb ~ agepreg'
model = smf.ols(formula, data=live)
results = model.fit()
regression.SummarizeResults(results)
##Results are also available as parameters:
inter = results.params['Intercept']
slope = results.params['agepreg']
slope_pvalue = results.pvalues['agepreg']
results.rsquared
##this gives the p-value associated with the model as a whole
results.f_pvalue
residuals = results.resid
##this returns a sequence of values corresponding
##to agepreg.
fitted_values = results.fittedvalues
# results.summary() provides a lot of info
#the following is easier:
regression.SummarizeResults(results)
Explanation: regression - fitting a model to data.  The goal is to describe the relationship between the dependent variables and the explanatory variables.
multiple regression multiple explanatory variables.
linear regression wen the relationship is linear.
$$
y = \beta_0 + \beta_1x_1 + \beta_2x_2 + \epsilon
$$
where $\beta_0$ is the intercept, $\beta_1$ is the parameter association with $x_1$, $\beta_2$ is the parameter associated with $x_2$ and $\epsilon$ is the residual due to random variation or unknown factors.
ordinary least squares.  Given a sequence of values for y and sequences for $x_1$ and $x_2$, we can find the beta parameters that minimize $epsilon^2$
End of explanation
diff_weight = firsts.totalwgt_lb.mean() - others.totalwgt_lb.mean()
diff_weight
diff_age = firsts.agepreg.mean() - others.agepreg.mean()
diff_age
Explanation: spurious - result for which there is no obvious mechanism that would explain it. e.g. why would first babies be lighter than others?  Perhaps because mothers of first babies are younger...
End of explanation
<END_TASK>