introduce error analysis in linear regression

This commit is contained in:
mhjensen
2018-05-17 16:29:36 -04:00
parent 643bdc4580
commit e7b42c6db5
67 changed files with 3452 additions and 1699 deletions
+14 -3
View File
@@ -269,7 +269,12 @@ meaning that the solution for $\hat{\beta}$ is the one which minimizes the resid
!split
===== Simple regression model =====
We are now ready to write our first program which aims at solving the above linear regression equations. We start with data we have produced ourselves, in this case normally distributed random numbers along the $x$-axis. These numbers define then the value of a function $y(x)=4+3x+N(0,1)$. Thereafter we order the $x$ values and employ our linear regression algorithm to set up the best fit.
We are now ready to write our first program which aims at solving the above linear regression equations. We start with data we have produced ourselves, in this case normally distributed random numbers along the $x$-axis. These numbers define then the value of a function $y(x)=4+3x+N(0,1)$. Thereafter we order the $x$ values and employ our linear regression algorithm to set up the best fit. Here we find it useful to use the numpy function $c\_$ arrays where arrays are stacked along their last axis after being upgraded to at least two dimensions with ones post-pended to the shape. The following examples help in understanding what happens
!bc pycod
import numpy as np
print(np.c_[np.array([1,2,3]), np.array([4,5,6])])
print(np.c_[np.array([[1,2,3]]), 0, 0, np.array([[4,5,6]])])
!ec
!bc pycod
# Importing various packages
@@ -296,14 +301,16 @@ plt.show()
!ec
We see that, as expected, a linear fit gives a seemingly (from the graph) good representation of the data.
!split
===== Simple regression model, now using _scikit-learn_ =====
We can repeat the above algorithm using _scikit-learn_ as follows.
We can repeat the above algorithm using _scikit-learn_ as follows
!bc pycod
# Importing various packages
from random import random, seed
@@ -339,6 +346,10 @@ correlation function defined as
!et
Another quantity is the autocorrelation function we discussed in our chapter on statistical analysis.
Let us now try to assess the quality of our fit by studying various measures.
!split
===== Estimate of the error =====
!split
===== The $\chi^2$ function =====