{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Lab 5-1: Multiple Linear Regression\n", "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We are going to try and improve upon our simple linear regression model from Lab 4-1 with the snow water equivalent (SWE) data (if you're interested, [read about SWE and snow pillows here](https://www.nrcs.usda.gov/wps/portal/nrcs/detail/null/?cid=nrcseprd1314833)). In Lab 4-1 we used SWE observations from Slide Canyon to predict SWE at Blue Canyon. In this lab we will use two explanatory variables, SWE at Slide Canyon and time, to try and predict SWE at Blue Canyon. We can also compare both of these to the quantile regression model from Lab 4-2." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "import scipy.stats as stats\n", "from scipy.linalg import lstsq # for the multiple linear regression, we'll use the scipy linear algebra least-squares function\n", "from scipy.interpolate import interp1d # for quantile regression, we'll want this 1d interpolation function\n", "import matplotlib.pyplot as plt\n", "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Load the csv file with snow water equivalent (SWE) measurements from two sites in California's Sierra Nevada. " ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | years | \n", "BLC_max | \n", "SLI_max | \n", "
---|---|---|---|
0 | \n", "1983 | \n", "688 | \n", "2446 | \n", "
1 | \n", "1984 | \n", "112 | \n", "1471 | \n", "
2 | \n", "1985 | \n", "216 | \n", "1143 | \n", "
3 | \n", "1986 | \n", "150 | \n", "1085 | \n", "
4 | \n", "1987 | \n", "94 | \n", "569 | \n", "