Modify Example 27.2.2 so that it runs a loop over degrees from 1 to 7 and within that loop, \(R^2\) is computed for each degree \(d\text{.}\) The code should find the value of \(d\) with maximal \(R^2\text{,}\) display this \(R^2\) value, and plot the graph of polynomial with optimal \(d\text{.}\)
Write a script that takes degree \(d\) as input, fits a polynomial of degree \(d\) to the data, displays the t-statistic for the leading coefficient as in Example 27.3.1, and plots the polynomial together with the data points. What value of \(d\) works best for this data, based on the t-statistic and the plot?