{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "nbsphinx": "hidden" }, "outputs": [], "source": [ "%matplotlib inline\n", "import warnings\n", "warnings.filterwarnings('ignore')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Running the Regression for a Single Bin\n", "\n", "Import the regression function and some utility libraries" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "%matplotlib inline\n", "from LOTUS_regression.regression import mzm_regression\n", "from LOTUS_regression.predictors import load_data\n", "import LOTUS_regression.tests as tests\n", "import numpy as np\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "import statsmodels as sm" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Load in some example data, first our predictors." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "predictors = load_data('pred_baseline_pwlt.csv')\n", "\n", "predictors.plot()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Load in one latitude bin of SAGE 2/OSIRIS/OMPS merged relative anomalies" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "s2_omps_osiris = tests.load_example_data('S2_OSIRIS_OMPS_alt_nd_sample.csv')\n", "\n", "plt.figure()\n", "s2_omps_osiris['relative_anomaly'].plot()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Convert data to raw arrays" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "predictors, s2_omps_osiris = pd.DataFrame.align(predictors, s2_omps_osiris, axis=0)\n", "\n", "# (nsamples, npredictors) matrix\n", "X = predictors.values\n", "\n", "# (nsamples) array of observations\n", "Y = s2_omps_osiris['relative_anomaly'].values" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And Perform the regression" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "regression_output = mzm_regression(X, Y)\n", "\n", "plt.figure()\n", "plt.plot(s2_omps_osiris.index, Y)\n", "\n", "plt.plot(s2_omps_osiris.index, regression_output['fit_values'])" ] } ], "metadata": { "celltoolbar": "Edit Metadata", "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.1" } }, "nbformat": 4, "nbformat_minor": 1 }