{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Lab 4-2: Quantile Regression" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Why quantile regression?\n", "What if we think that the rank order of values is basically the same in two datasets, but we don’t know if they’re linearly related. We can use a quantile regression to model a relationship between two variables without needing to assume anything about the function of that relationship (linear, or otherwise).\n", "\n", "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this example we're again considering [SWE](https://www.nrcs.usda.gov/wps/portal/nrcs/detail/null/?cid=nrcseprd1314833) measurements from two sites in California's Sierra Nevada, and want to evaluate the question:\n", "\n", "**Quantile regression**: Could we use SWE measurements at Slide Canyon to predict SWE at Blue Canyon?" ] }, { "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", "import matplotlib.pyplot as plt\n", "%matplotlib inline\n", "\n", "# we will aslo need this 1d interpolation function\n", "from scipy.interpolate import interp1d" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | years | \n", "BLC_max | \n", "SLI_max | \n", "
---|---|---|---|
21 | \n", "2006 | \n", "761 | \n", "1692 | \n", "
22 | \n", "2007 | \n", "99 | \n", "597 | \n", "
23 | \n", "2008 | \n", "926 | \n", "899 | \n", "
24 | \n", "2009 | \n", "439 | \n", "935 | \n", "
25 | \n", "2010 | \n", "553 | \n", "1023 | \n", "