You are on page 1of 1

Lab 7

Autoregression and Piecewise linear regression

1. The data set (google_stock.xlsx) consists of n = 105 values which are the closing stock price of a share
of Google stock during 2-7-2005 to 7-7-2005.

a. Load the data using xlsread. See help on xlsread.


b. Plot the data.
c. Fit the data using an AR(1) model: 𝑦𝑖+1 = 𝛽0 + 𝛽1 . 𝑦𝑖 , where 𝑦𝑖 is the stock price on day i.
d. Plot the predictions.
e. Compute the 𝑟 2 value for the fit. Recall 𝑟 2 = 1 − 𝑆𝑆𝐸/𝑆𝑆𝑇. (See lab 3)

2. Let yt = the annual number of worldwide earthquakes with magnitude greater than 7 on the Richter
scale for n = 100 years (earthquakes.xlsx data obtained from https://earthquake.usgs.gov).

Fit a AR(2) and AR(3) model to the data and plot the predictions. Compute 𝑟 2 value for both fits.

3. The shipment data set (shipment.txt) contains the cost of a shipment (in thousand dollars) and the
size of the shipment (in thousand parts).

a. Read the data using dlmread as the columns are separated by white space/tabs
b. Plot the data
c. First fit a linear line to the data to predict cost using size.
d. Use size = 250 as a knot and do a piecewise linear regression.
e. Plot both fitted lines.
f. Compute 𝑟 2 for both cases.

You might also like