{ "cells": [ { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ], "slideshow": { "slide_type": "-" } }, "source": [ "# Linear Mixed Effects Models\n", "\n", "With linear mixed effects models, we wish to model a linear\n", "relationship for data points with inputs of varying type, categorized\n", "into subgroups, and associated to a real-valued output.\n", "\n", "We demonstrate with an example in Edward. A webpage version is available \n", "[here](http://edwardlib.org/tutorials/linear-mixed-effects-models)." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "autoscroll": "json-false", "collapsed": true, "ein.tags": [ "worksheet-0" ], "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "%matplotlib inline\n", "from __future__ import absolute_import\n", "from __future__ import division\n", "from __future__ import print_function\n", "\n", "import edward as ed\n", "import pandas as pd\n", "import tensorflow as tf\n", "import matplotlib.pyplot as plt\n", "\n", "from edward.models import Normal\n", "from observations import insteval\n", "\n", "plt.style.use('ggplot')\n", "ed.set_seed(42)" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": [ "worksheet-0" ], "slideshow": { "slide_type": "-" } }, "source": [ "## Data\n", "\n", "We use the `InstEval` data set from the popular\n", "[lme4 R package](http://lme4.r-forge.r-project.org) (Bates, Mächler, Bolker, & Walker, 2015).\n", "It is a data set of instructor evaluation ratings, where the inputs\n", "(covariates) include categories such as `students` and\n", "`departments`, and our response variable of interest is the instructor\n", "evaluation rating." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "autoscroll": "json-false", "ein.tags": [ "worksheet-0" ], "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "
\n", " | s | \n", "d | \n", "studage | \n", "lectage | \n", "service | \n", "dept | \n", "y | \n", "dcodes | \n", "deptcodes | \n", "
---|---|---|---|---|---|---|---|---|---|
66702 | \n", "2714 | \n", "474 | \n", "8 | \n", "5 | \n", "1 | \n", "1 | \n", "4.0 | \n", "248 | \n", "0 | \n", "
51671 | \n", "2074 | \n", "102 | \n", "8 | \n", "1 | \n", "1 | \n", "1 | \n", "2.0 | \n", "55 | \n", "0 | \n", "
35762 | \n", "1456 | \n", "139 | \n", "6 | \n", "4 | \n", "0 | \n", "12 | \n", "2.0 | \n", "73 | \n", "11 | \n", "
43777 | \n", "1772 | \n", "2096 | \n", "8 | \n", "3 | \n", "0 | \n", "10 | \n", "4.0 | \n", "1092 | \n", "9 | \n", "
4788 | \n", "178 | \n", "554 | \n", "6 | \n", "6 | \n", "1 | \n", "6 | \n", "5.0 | \n", "290 | \n", "5 | \n", "