[171cba]: / talk / GrahamGroup.ipynb

Download this file

1647 lines (1647 with data), 58.0 kB

{
 "metadata": {
  "celltoolbar": "Slideshow",
  "name": "",
  "signature": "sha256:683ceb13e563077b8da74ca91d75c910b368c1da6290dcded253f1373c1c887b"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "Robust Extraction of Quantitative Information from Histology Images"
     ]
    },
    {
     "cell_type": "heading",
     "level": 4,
     "metadata": {},
     "source": [
      "Quentin Caudron\n",
      "<br /><br />\n",
      "\n",
      "Romain Garnier\n",
      "<br /><br />\n",
      "\n",
      "*with Bryan Grenfell and Andrea Graham*"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "Outline"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "- Image processing\n",
      "- Extracted measures\n",
      "- Preliminary analysis\n",
      "- Future directions"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "skip"
      }
     },
     "source": [
      "4. Age as random effect <---\n",
      "\n",
      "[\"interface_hepatitis\", \"confluent_necrosis\", \"portal_inflammation\", \"ln_ap_ri\"]"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "def normalise(df, skip = []) :\n",
      "\tfor i in df.columns :\n",
      "\t\tif i not in skip :\n",
      "\t\t\tdf[i] -= df[i].mean()\n",
      "\t\t\tdf[i] /= df[i].std()\n",
      "\treturn df\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "def rescale(df, skip = []) :\n",
      "    for i in df.columns :\n",
      "        if i not in skip :\n",
      "            df[i] -= df[i].min()\n",
      "            df[i] /= df[i].max()\n",
      "    return df\n",
      "\n",
      "\n",
      "\n",
      "# Remove a layer from a list\n",
      "def delayer(m) :\n",
      "\tout = []\n",
      "\tfor i in m :\n",
      "\t\tif isinstance(i, list) :\n",
      "\t\t\tfor j in i :\n",
      "\t\t\t\tout.append(j)\n",
      "\t\telse :\n",
      "\t\t\tout.append(i)\n",
      "\treturn out\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "# Remove all layers from a list\n",
      "def flatten(m) :\n",
      "\tout = m[:]\n",
      "\n",
      "\twhile out != delayer(out) :\n",
      "\t\tout = delayer(out)\n",
      "\n",
      "\treturn out\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "# Generate all combinations of objects in a list\n",
      "def combinatorial(l) :\n",
      "\tout = []\n",
      "\n",
      "\tfor numel in range(len(l)) :\n",
      "\t\tfor i in itertools.combinations(l, numel+1) :\n",
      "\t\t\tout.append(list(i))\n",
      "\n",
      "\treturn out\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "def pcaplot(df) :\n",
      "\n",
      "\t# PCA\n",
      "\tpca = decomposition.PCA(whiten = True)\n",
      "\tpca.fit(df)\n",
      "\tp1 = pca.components_[0] / np.abs(pca.components_[0]).max() * np.sqrt(2)/2\n",
      "\tp2 = pca.components_[1] / np.abs(pca.components_[1]).max() * np.sqrt(2)/2\n",
      "\n",
      "\t# Normalise\n",
      "\tnorms = np.max([np.sqrt((np.array(zip(p1, p2)[i])**2).sum()) for i in range(len(p1))])\n",
      "\tc = plt.Circle( (0, 0), radius = 1, alpha = 0.2)\n",
      "\tplt.axes(aspect = 1)\n",
      "\tplt.gca().add_artist(c)\n",
      "\n",
      "\tplt.scatter(p1 / norms, p2 / norms)\n",
      "\tplt.xlim([-1, 1])\n",
      "\tplt.ylim([-1, 1])\n",
      "\n",
      "\tfor i, text in enumerate(df.columns) :\n",
      "\t\tplt.annotate(text, xy = [p1[i], p2[i]])\n",
      "\n",
      "\tplt.tight_layout()\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "def test_all_linear(df, y, x, return_significant = False, group = None) :\n",
      "\n",
      "    # All possible combinations of independent variables\n",
      "\tindependent = combinatorial(x)\n",
      "\n",
      "\tfits = {}\n",
      "\tpval = {}\n",
      "\tlinmodels = {}\n",
      "\tqsum = {}\n",
      "\taic = {}\n",
      "\n",
      "\t# For all dependent variables, one at a time\n",
      "\tfor dependent in y :\n",
      "\n",
      "\t\tprint \"Fitting for %s.\" % dependent\n",
      "\n",
      "\t\t# For all combinations of independent variables\n",
      "\t\tfor covariate in independent :\n",
      "\n",
      "\t\t\t# Standard mixed model\n",
      "\t\t\tif group is None :\n",
      "\n",
      "\t\t\t\t# Fit a linear model\n",
      "\t\t\t\tsubset = delayer([covariate, dependent])\n",
      "\t\t\t\tdf2 = df[delayer(subset)].dropna()\n",
      "\t\t\t\tdf2[\"Intercept\"] = np.ones(len(df2))\n",
      "                \n",
      "\t\t\t\tols = sm.GLS(endog = df2[dependent], exog = df2[delayer([covariate, \"Intercept\"])]).fit()\n",
      "\n",
      "\t\t\t\t# Save the results\n",
      "\t\t\t\tif (return_significant and ols.f_pvalue < 0.05) or (not return_significant) :\n",
      "\t\t\t\t\tlinmodels.setdefault(dependent, []).append(ols)\n",
      "\t\t\t\t\tfits.setdefault(dependent, []).append(ols.rsquared)\n",
      "\t\t\t\t\tpval.setdefault(dependent, []).append(ols.f_pvalue)\n",
      "\t\t\t\t\taic.setdefault(dependent, []).append(ols.aic)\n",
      "\n",
      "\n",
      "\t\t\t# Mixed effects model\n",
      "\t\t\telse :\n",
      "\t\t\t\tsubset = delayer([covariate, dependent, group])\n",
      "\t\t\t\tdf2 = df[delayer(subset)].dropna()\n",
      "\n",
      "\t\t\t\t# Fit a mixed effects model\n",
      "\t\t\t\tols = MixedLM(endog = df2[dependent], exog = df2[covariate], groups = df2[group]).fit()\n",
      "\n",
      "\t\t\t\t# Calculate AIC\n",
      "\t\t\t\tlinmodels.setdefault(dependent, []).append(ols)\n",
      "\t\t\t\tfits.setdefault(dependent, []).append(2 * (ols.k_fe + 1) - 2 * ols.llf)\n",
      "\t\t\t\tpval.setdefault(dependent, []).append(ols.pvalues)\n",
      "\n",
      "\tif group is not None :\n",
      "\t\tfor i in y :\n",
      "\t\t\tf = np.array(fits[i])\n",
      "\t\t\tmodels = np.array(linmodels[i])\n",
      "\t\t\tidx = np.where(f - f.min() <= 2)[0]\n",
      "\t\t\tbestmodelDoF = [j.k_fe for j in np.array(linmodels[i])[idx]]\n",
      "\t\t\tbestmodels = [idx[j] for j in np.where(bestmodelDoF == np.min(bestmodelDoF))[0]]\n",
      "\t\t\tqsum[i] = models[idx[np.where(f[bestmodels] == np.min(f[bestmodels]))]]\n",
      "\n",
      "\n",
      "\t\treturn linmodels, fits, pval, qsum\n",
      "\n",
      "\treturn linmodels, fits, pval, aic\n",
      "\n",
      "\t\n",
      "\t\t\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "def summary(models) :\n",
      "\n",
      "\t# Generate list of everything\n",
      "\tr2 = np.array([m.r2 for dependent in models.keys() for m in models[dependent]])\n",
      "\tp = np.array([m.f_stat[\"p-value\"] for dependent in models.keys() for m in models[dependent]])\n",
      "\tmod = np.array([m for dependent in models.keys() for m in models[dependent]])\n",
      "\tdependent = np.array([dependent for dependent in models.keys() for m in models[dependent]])\n",
      "\n",
      "\t# Sort by R2\n",
      "\tidx = np.argsort(r2)[::-1]\n",
      "\n",
      "\t# Output string\n",
      "\ts = \"%d significant regressions.\\n\\n\" % len(r2)\n",
      "\ts += \"Ten most correlated :\\n\\n\"\n",
      "\n",
      "\t# Print a summary of the top ten correlations\n",
      "\tfor i in idx[:10] :\n",
      "\t\ts += (\"%s ~ %s\\n\" % (dependent[i], \" + \".join(mod[i].x.columns[:-1])))\n",
      "\t\ts += (\"R^2 = %f\\tp = %f\\n\\n\" % (r2[i], p[i]))\n",
      "\n",
      "\tprint s\n",
      "    \n",
      "    \n",
      "    \n",
      "    \n",
      "    \n",
      "    \n",
      "    \n",
      "def rstr(y, x) :\n",
      "    formatstr = \"%s ~ \" % y\n",
      "    for i in x[:-1] :\n",
      "        formatstr += str(i)\n",
      "        formatstr += \" + \"\n",
      "    formatstr += str(x[-1])\n",
      "    return formatstr\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {
      "slideshow": {
       "slide_type": "skip"
      }
     },
     "outputs": [],
     "prompt_number": 3
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import numpy as np\n",
      "from sklearn.neighbors import KernelDensity\n",
      "from matplotlib import rcParams\n",
      "import matplotlib.pyplot as plt\n",
      "import seaborn\n",
      "import pandas as pd\n",
      "import itertools\n",
      "from sklearn import linear_model, ensemble, decomposition, cross_validation, preprocessing\n",
      "from statsmodels.regression.mixed_linear_model import MixedLM\n",
      "import statsmodels.api as sm\n",
      "from statsmodels.regression.linear_model import OLSResults\n",
      "from statsmodels.tools.tools import add_constant\n",
      "\n",
      "\n",
      "%matplotlib inline\n",
      "rcParams[\"figure.figsize\"] = (14, 8)\n",
      "\n",
      "\n",
      "# RAW DATA\n",
      "\n",
      "raw_physical = pd.read_csv(\"../data/physical.csv\")\n",
      "raw_histo = pd.read_csv(\"../data/tawfik.csv\")\n",
      "ent = pd.read_csv(\"../4x/results/entropy.csv\").drop([\"Unnamed: 0\"], 1)\n",
      "foci = pd.read_csv(\"../4x/results/foci.csv\").drop([\"Unnamed: 0\"], 1)\n",
      "lac = pd.read_csv(\"../4x/results/normalised_lacunarity.csv\").drop([\"Unnamed: 0\"], 1)\n",
      "gabor = pd.read_csv(\"../4x/results/gabor_filters.csv\").drop([\"Unnamed: 0\"], 1)\n",
      "ts = pd.read_csv(\"../4x/results/tissue_sinusoid_ratio.csv\").drop([\"Unnamed: 0\"], 1)\n",
      "\n",
      "raw_image = pd.merge(lac, ent,\n",
      "\ton=[\"Sheep\", \"Image\"]).merge(foci, \n",
      "\ton=[\"Sheep\", \"Image\"]).merge(gabor,\n",
      "\ton=[\"Sheep\", \"Image\"]).merge(ts, \n",
      "    on=[\"Sheep\", \"Image\"])\n",
      "raw_image.rename(columns = {\t\"meanSize\" : \"FociSize\", \n",
      "\t\t\t\t\t\t\t\t\"TSRatio\" : \"TissueToSinusoid\",\n",
      "\t\t\t\t\t\t\t\t\"Count\" : \"FociCount\" }, inplace=True)\n",
      "\n",
      "\n",
      "\n",
      "# CLEAN DATA\n",
      "\n",
      "physcols = [\"Weight\", \"Sex\", \"AgeAtDeath\", \"Foreleg\", \"Hindleg\"]\n",
      "imagecols = [\"Entropy\", \"Lacunarity\", \"Inflammation\", \"Scale\", \"Directionality\", \"FociCount\", \"FociSize\", \"TissueToSinusoid\"]\n",
      "histcols = [\"Lobular_collapse\", \"Interface_hepatitis\", \"Confluent_necrosis\", \"Ln_ap_ri\", \"Portal_inflammation\", \"BD_hyperplasia\", \"Fibrosis\", \"TawfikTotal\", \"Mean_hep_size\", \"Min_hep_size\", \"Max_hep_size\"]\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "# IMAGE\n",
      "\n",
      "# Set FociSize to zero if FociCount is zero\n",
      "# Drop stdSize\n",
      "image = raw_image\n",
      "image = image.drop(\"stdSize\", 1)\n",
      "image.FociSize[raw_image.FociCount == 0] = 0\n",
      "\n",
      "\n",
      "\n",
      "# HISTO\n",
      "\n",
      "histo = raw_histo\n",
      "histo = histo.drop([\"Vessels\", \"Vacuol\", \"Pigment\", \"Std_hep_size\"], 1)\n",
      "\n",
      "\n",
      "\n",
      "# PHYSICAL\n",
      "\n",
      "physical = raw_physical\n",
      "physical = physical.drop([\"CurrTag\", \"DeathDate\", \"Category\"], 1)\n",
      "physical\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "# COMPLETE DATASET\n",
      "\n",
      "raw_data = pd.merge(pd.merge(image, histo, on=\"Sheep\", how=\"outer\"), physical, on=\"Sheep\", how=\"outer\")\n",
      "raw_data.to_csv(\"../data/tentative_complete.csv\")\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "# AVERAGED BY SHEEP\n",
      "data = raw_data\n",
      "data[\"Inflammation\"] = data.FociCount * data.FociSize\n",
      "\n",
      "sheep = rescale(data.groupby(\"Sheep\").mean())\n",
      "age = rescale(data.groupby(\"AgeAtDeath\").mean())\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "# REGRESSIONS : fixed effects, grouped by sheep\n",
      "\n",
      "df = sheep[[\"Portal_inflammation\", \"FociSize\"]].dropna()\n",
      "df[\"Intercept\"] = np.ones(len(df))\n",
      "portal_inflammation = sm.GLS(endog = df.Portal_inflammation, exog = df[[\"FociSize\", \"Intercept\"]]).fit().summary()\n",
      "#portal_inflammation = portal_inflammation.summary()\n",
      "del portal_inflammation.tables[2]\n",
      "\n",
      "\n",
      "\n",
      "df = sheep[[\"BD_hyperplasia\", \"Scale\", \"Directionality\", \"FociSize\"]].dropna()\n",
      "df[\"Intercept\"] = np.ones(len(df))\n",
      "hyperplasia = sm.GLS(endog = df.BD_hyperplasia, exog = df[[\"FociSize\", \"Scale\", \"Directionality\", \"Intercept\"]]).fit().summary()\n",
      "#hyperplasia.summary()\n",
      "del hyperplasia.tables[2]\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "# REGRESSIONS : fixed effects, grouped by age\n",
      "\n",
      "df = age[[\"Max_hep_size\", \"Entropy\", \"Directionality\"]].dropna()\n",
      "df[\"Intercept\"] = np.ones(len(df))\n",
      "maxhepsize = sm.GLS(endog = df.Max_hep_size, exog = df[[\"Entropy\", \"Directionality\", \"Intercept\"]]).fit().summary()\n",
      "del maxhepsize.tables[2]\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "df = age[[\"Lobular_collapse\", \"FociSize\"]].dropna()\n",
      "df[\"Intercept\"] = np.ones(len(df))\n",
      "lobular_collapse = sm.GLS(endog = df.Lobular_collapse, exog = df[[\"FociSize\", \"Intercept\"]]).fit().summary()\n",
      "del lobular_collapse.tables[2]\n",
      "\n",
      "\n",
      "df = age[[\"Interface_hepatitis\", \"Lacunarity\"]].dropna()\n",
      "df[\"Intercept\"] = np.ones(len(df))\n",
      "interface_hepatitis = sm.GLS(endog = df.Interface_hepatitis, exog = df[[\"Lacunarity\", \"Intercept\"]]).fit().summary()\n",
      "del interface_hepatitis.tables[2]\n",
      "\n",
      "\n",
      "df = age[[\"Fibrosis\", \"Inflammation\"]].dropna()\n",
      "df[\"Intercept\"] = np.ones(len(df))\n",
      "fibrosis = sm.GLS(endog = df.Fibrosis, exog = df[[\"Inflammation\", \"Intercept\"]]).fit().summary()\n",
      "del fibrosis.tables[2]\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "# PCA\n",
      "\n",
      "s = sheep.dropna(subset=delayer([imagecols, histcols]))\n",
      "pca = decomposition.PCA(n_components=1)\n",
      "pcax = pca.fit_transform(s[imagecols])\n",
      "pcay = pca.fit_transform(s[histcols])\n",
      "pca = sm.GLS(endog = pcay[:, 0][:, np.newaxis], exog = add_constant(pcax)).fit().summary()\n",
      "del pca.tables[2]\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "# REGRESSIONS : mixed effects, intercept on age at death\n",
      "\n",
      "df = age[[\"Fibrosis\", \"Inflammation\"]].dropna()\n",
      "df[\"Intercept\"] = np.ones(len(df))\n",
      "fibrosis = sm.GLS(endog = df.Fibrosis, exog = df[[\"Inflammation\", \"Intercept\"]]).fit().summary()\n",
      "del fibrosis.tables[2]"
     ],
     "language": "python",
     "metadata": {
      "slideshow": {
       "slide_type": "skip"
      }
     },
     "outputs": [],
     "prompt_number": 14
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "a = portal_inflammation.summary()\n",
      "del a.tables[2]\n",
      "a"
     ],
     "language": "python",
     "metadata": {
      "slideshow": {
       "slide_type": "skip"
      }
     },
     "outputs": [
      {
       "html": [
        "<table class=\"simpletable\">\n",
        "<caption>GLS Regression Results</caption>\n",
        "<tr>\n",
        "  <th>Dep. Variable:</th>    <td>Portal_inflammation</td> <th>  R-squared:         </th> <td>   0.280</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Model:</th>                    <td>GLS</td>         <th>  Adj. R-squared:    </th> <td>   0.273</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Method:</th>              <td>Least Squares</td>    <th>  F-statistic:       </th> <td>   37.34</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Date:</th>              <td>Tue, 28 Oct 2014</td>   <th>  Prob (F-statistic):</th> <td>2.12e-08</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Time:</th>                  <td>23:35:30</td>       <th>  Log-Likelihood:    </th> <td>  14.996</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>No. Observations:</th>       <td>    98</td>        <th>  AIC:               </th> <td>  -25.99</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Df Residuals:</th>           <td>    96</td>        <th>  BIC:               </th> <td>  -20.82</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Df Model:</th>               <td>     1</td>        <th>                     </th>     <td> </td>   \n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Covariance Type:</th>       <td>nonrobust</td>      <th>                     </th>     <td> </td>   \n",
        "</tr>\n",
        "</table>\n",
        "<table class=\"simpletable\">\n",
        "<tr>\n",
        "      <td></td>         <th>coef</th>     <th>std err</th>      <th>t</th>      <th>P>|t|</th> <th>[95.0% Conf. Int.]</th> \n",
        "</tr>\n",
        "<tr>\n",
        "  <th>FociSize</th>  <td>    0.5627</td> <td>    0.092</td> <td>    6.111</td> <td> 0.000</td> <td>    0.380     0.746</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Intercept</th> <td>    0.3368</td> <td>    0.043</td> <td>    7.855</td> <td> 0.000</td> <td>    0.252     0.422</td>\n",
        "</tr>\n",
        "</table>"
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 19,
       "text": [
        "<class 'statsmodels.iolib.summary.Summary'>\n",
        "\"\"\"\n",
        "                             GLS Regression Results                            \n",
        "===============================================================================\n",
        "Dep. Variable:     Portal_inflammation   R-squared:                       0.280\n",
        "Model:                             GLS   Adj. R-squared:                  0.273\n",
        "Method:                  Least Squares   F-statistic:                     37.34\n",
        "Date:                 Tue, 28 Oct 2014   Prob (F-statistic):           2.12e-08\n",
        "Time:                         23:35:30   Log-Likelihood:                 14.996\n",
        "No. Observations:                   98   AIC:                            -25.99\n",
        "Df Residuals:                       96   BIC:                            -20.82\n",
        "Df Model:                            1                                         \n",
        "Covariance Type:             nonrobust                                         \n",
        "==============================================================================\n",
        "                 coef    std err          t      P>|t|      [95.0% Conf. Int.]\n",
        "------------------------------------------------------------------------------\n",
        "FociSize       0.5627      0.092      6.111      0.000         0.380     0.746\n",
        "Intercept      0.3368      0.043      7.855      0.000         0.252     0.422\n",
        "==============================================================================\n",
        "\n",
        "Warnings:\n",
        "[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.\n",
        "\"\"\""
       ]
      }
     ],
     "prompt_number": 19
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "Image Processing"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "source": [
      "<img src=\"figures/sheep.jpg\"></img>"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "source": [
      "<img src=\"figures/processed.jpg\"></img>"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "source": [
      "Extraction"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "-"
      }
     },
     "source": [
      "- Automagical\n",
      "- Reasonably quick"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "source": [
      "Robust"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "-"
      }
     },
     "source": [
      "- Invariant to staining, slicing, field-related variation\n",
      "- Capture intersample variation"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "source": [
      "![image](figures/robust3.jpg)"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "source": [
      "![image](figures/robust4.jpg)"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "source": [
      "![image](figures/robust1.jpg)"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "source": [
      "![image](figures/robust2.jpg)"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "Structural and Textural Measures"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "source": [
      "- characteristic **scale** of sinusoid widths\n",
      "- **directional** amplitude of preferred sinusoid alignment\n",
      "- **tissue to sinusoid** ratio\n",
      "- **count** of inflammatory foci per image\n",
      "- **mean size** of inflammatory foci per image\n",
      "- information **entropy** of sinusoid distribution\n",
      "- **lacunarity** ( clustering ) of sinusoids"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "source": [
      "<img src=\"figures/gif.gif\"></img>"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "source": [
      "![image](figures/intra.png)"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "source": [
      "![image](figures/inter2.png)"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "Exploratory Analysis"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "by individual"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "portal_inflammation"
     ],
     "language": "python",
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "outputs": [
      {
       "html": [
        "<table class=\"simpletable\">\n",
        "<caption>GLS Regression Results</caption>\n",
        "<tr>\n",
        "  <th>Dep. Variable:</th>    <td>Portal_inflammation</td> <th>  R-squared:         </th> <td>   0.280</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Model:</th>                    <td>GLS</td>         <th>  Adj. R-squared:    </th> <td>   0.273</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Method:</th>              <td>Least Squares</td>    <th>  F-statistic:       </th> <td>   37.34</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Date:</th>              <td>Tue, 28 Oct 2014</td>   <th>  Prob (F-statistic):</th> <td>2.12e-08</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Time:</th>                  <td>23:40:10</td>       <th>  Log-Likelihood:    </th> <td>  14.996</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>No. Observations:</th>       <td>    98</td>        <th>  AIC:               </th> <td>  -25.99</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Df Residuals:</th>           <td>    96</td>        <th>  BIC:               </th> <td>  -20.82</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Df Model:</th>               <td>     1</td>        <th>                     </th>     <td> </td>   \n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Covariance Type:</th>       <td>nonrobust</td>      <th>                     </th>     <td> </td>   \n",
        "</tr>\n",
        "</table>\n",
        "<table class=\"simpletable\">\n",
        "<tr>\n",
        "      <td></td>         <th>coef</th>     <th>std err</th>      <th>t</th>      <th>P>|t|</th> <th>[95.0% Conf. Int.]</th> \n",
        "</tr>\n",
        "<tr>\n",
        "  <th>FociSize</th>  <td>    0.5627</td> <td>    0.092</td> <td>    6.111</td> <td> 0.000</td> <td>    0.380     0.746</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Intercept</th> <td>    0.3368</td> <td>    0.043</td> <td>    7.855</td> <td> 0.000</td> <td>    0.252     0.422</td>\n",
        "</tr>\n",
        "</table>"
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 29,
       "text": [
        "<class 'statsmodels.iolib.summary.Summary'>\n",
        "\"\"\"\n",
        "                             GLS Regression Results                            \n",
        "===============================================================================\n",
        "Dep. Variable:     Portal_inflammation   R-squared:                       0.280\n",
        "Model:                             GLS   Adj. R-squared:                  0.273\n",
        "Method:                  Least Squares   F-statistic:                     37.34\n",
        "Date:                 Tue, 28 Oct 2014   Prob (F-statistic):           2.12e-08\n",
        "Time:                         23:40:10   Log-Likelihood:                 14.996\n",
        "No. Observations:                   98   AIC:                            -25.99\n",
        "Df Residuals:                       96   BIC:                            -20.82\n",
        "Df Model:                            1                                         \n",
        "Covariance Type:             nonrobust                                         \n",
        "==============================================================================\n",
        "                 coef    std err          t      P>|t|      [95.0% Conf. Int.]\n",
        "------------------------------------------------------------------------------\n",
        "FociSize       0.5627      0.092      6.111      0.000         0.380     0.746\n",
        "Intercept      0.3368      0.043      7.855      0.000         0.252     0.422\n",
        "==============================================================================\n",
        "\n",
        "Warnings:\n",
        "[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.\n",
        "\"\"\""
       ]
      }
     ],
     "prompt_number": 29
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "source": [
      "![image](figures/portal_inflammation.png)"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "hyperplasia"
     ],
     "language": "python",
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "outputs": [
      {
       "html": [
        "<table class=\"simpletable\">\n",
        "<caption>GLS Regression Results</caption>\n",
        "<tr>\n",
        "  <th>Dep. Variable:</th>     <td>BD_hyperplasia</td>  <th>  R-squared:         </th> <td>   0.306</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Model:</th>                   <td>GLS</td>       <th>  Adj. R-squared:    </th> <td>   0.284</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Method:</th>             <td>Least Squares</td>  <th>  F-statistic:       </th> <td>   13.83</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Date:</th>             <td>Tue, 28 Oct 2014</td> <th>  Prob (F-statistic):</th> <td>1.52e-07</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Time:</th>                 <td>23:40:10</td>     <th>  Log-Likelihood:    </th> <td> -3.9632</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>No. Observations:</th>      <td>    98</td>      <th>  AIC:               </th> <td>   15.93</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Df Residuals:</th>          <td>    94</td>      <th>  BIC:               </th> <td>   26.27</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Df Model:</th>              <td>     3</td>      <th>                     </th>     <td> </td>   \n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Covariance Type:</th>      <td>nonrobust</td>    <th>                     </th>     <td> </td>   \n",
        "</tr>\n",
        "</table>\n",
        "<table class=\"simpletable\">\n",
        "<tr>\n",
        "         <td></td>           <th>coef</th>     <th>std err</th>      <th>t</th>      <th>P>|t|</th> <th>[95.0% Conf. Int.]</th> \n",
        "</tr>\n",
        "<tr>\n",
        "  <th>FociSize</th>       <td>    0.6698</td> <td>    0.113</td> <td>    5.902</td> <td> 0.000</td> <td>    0.444     0.895</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Scale</th>          <td>    0.5811</td> <td>    0.243</td> <td>    2.394</td> <td> 0.019</td> <td>    0.099     1.063</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Directionality</th> <td>   -0.4419</td> <td>    0.190</td> <td>   -2.330</td> <td> 0.022</td> <td>   -0.819    -0.065</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Intercept</th>      <td>   -0.0504</td> <td>    0.079</td> <td>   -0.642</td> <td> 0.523</td> <td>   -0.206     0.105</td>\n",
        "</tr>\n",
        "</table>"
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 31,
       "text": [
        "<class 'statsmodels.iolib.summary.Summary'>\n",
        "\"\"\"\n",
        "                            GLS Regression Results                            \n",
        "==============================================================================\n",
        "Dep. Variable:         BD_hyperplasia   R-squared:                       0.306\n",
        "Model:                            GLS   Adj. R-squared:                  0.284\n",
        "Method:                 Least Squares   F-statistic:                     13.83\n",
        "Date:                Tue, 28 Oct 2014   Prob (F-statistic):           1.52e-07\n",
        "Time:                        23:40:10   Log-Likelihood:                -3.9632\n",
        "No. Observations:                  98   AIC:                             15.93\n",
        "Df Residuals:                      94   BIC:                             26.27\n",
        "Df Model:                           3                                         \n",
        "Covariance Type:            nonrobust                                         \n",
        "==================================================================================\n",
        "                     coef    std err          t      P>|t|      [95.0% Conf. Int.]\n",
        "----------------------------------------------------------------------------------\n",
        "FociSize           0.6698      0.113      5.902      0.000         0.444     0.895\n",
        "Scale              0.5811      0.243      2.394      0.019         0.099     1.063\n",
        "Directionality    -0.4419      0.190     -2.330      0.022        -0.819    -0.065\n",
        "Intercept         -0.0504      0.079     -0.642      0.523        -0.206     0.105\n",
        "==================================================================================\n",
        "\n",
        "Warnings:\n",
        "[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.\n",
        "\"\"\""
       ]
      }
     ],
     "prompt_number": 31
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "source": [
      "![image](figures/hyperplasia.png)"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "pca"
     ],
     "language": "python",
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "outputs": [
      {
       "html": [
        "<table class=\"simpletable\">\n",
        "<caption>GLS Regression Results</caption>\n",
        "<tr>\n",
        "  <th>Dep. Variable:</th>            <td>y</td>        <th>  R-squared:         </th> <td>   0.075</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Model:</th>                   <td>GLS</td>       <th>  Adj. R-squared:    </th> <td>   0.065</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Method:</th>             <td>Least Squares</td>  <th>  F-statistic:       </th> <td>   7.723</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Date:</th>             <td>Wed, 29 Oct 2014</td> <th>  Prob (F-statistic):</th>  <td>0.00657</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Time:</th>                 <td>14:38:47</td>     <th>  Log-Likelihood:    </th> <td> -70.082</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>No. Observations:</th>      <td>    97</td>      <th>  AIC:               </th> <td>   144.2</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Df Residuals:</th>          <td>    95</td>      <th>  BIC:               </th> <td>   149.3</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Df Model:</th>              <td>     1</td>      <th>                     </th>     <td> </td>   \n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Covariance Type:</th>      <td>nonrobust</td>    <th>                     </th>     <td> </td>   \n",
        "</tr>\n",
        "</table>\n",
        "<table class=\"simpletable\">\n",
        "<tr>\n",
        "    <td></td>       <th>coef</th>     <th>std err</th>      <th>t</th>      <th>P>|t|</th> <th>[95.0% Conf. Int.]</th> \n",
        "</tr>\n",
        "<tr>\n",
        "  <th>const</th> <td>-2.949e-17</td> <td>    0.051</td> <td>-5.77e-16</td> <td> 1.000</td> <td>   -0.102     0.102</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>x1</th>    <td>    0.3865</td> <td>    0.139</td> <td>    2.779</td> <td> 0.007</td> <td>    0.110     0.663</td>\n",
        "</tr>\n",
        "</table>"
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 15,
       "text": [
        "<class 'statsmodels.iolib.summary.Summary'>\n",
        "\"\"\"\n",
        "                            GLS Regression Results                            \n",
        "==============================================================================\n",
        "Dep. Variable:                      y   R-squared:                       0.075\n",
        "Model:                            GLS   Adj. R-squared:                  0.065\n",
        "Method:                 Least Squares   F-statistic:                     7.723\n",
        "Date:                Wed, 29 Oct 2014   Prob (F-statistic):            0.00657\n",
        "Time:                        14:38:47   Log-Likelihood:                -70.082\n",
        "No. Observations:                  97   AIC:                             144.2\n",
        "Df Residuals:                      95   BIC:                             149.3\n",
        "Df Model:                           1                                         \n",
        "Covariance Type:            nonrobust                                         \n",
        "==============================================================================\n",
        "                 coef    std err          t      P>|t|      [95.0% Conf. Int.]\n",
        "------------------------------------------------------------------------------\n",
        "const      -2.949e-17      0.051  -5.77e-16      1.000        -0.102     0.102\n",
        "x1             0.3865      0.139      2.779      0.007         0.110     0.663\n",
        "==============================================================================\n",
        "\n",
        "Warnings:\n",
        "[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.\n",
        "\"\"\""
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "source": [
      "![image](figures/pca.png)"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "Exploratory Analysis"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "by age class"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "fibrosis"
     ],
     "language": "python",
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "outputs": [
      {
       "html": [
        "<table class=\"simpletable\">\n",
        "<caption>GLS Regression Results</caption>\n",
        "<tr>\n",
        "  <th>Dep. Variable:</th>        <td>Fibrosis</td>     <th>  R-squared:         </th> <td>   0.800</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Model:</th>                   <td>GLS</td>       <th>  Adj. R-squared:    </th> <td>   0.778</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Method:</th>             <td>Least Squares</td>  <th>  F-statistic:       </th> <td>   36.07</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Date:</th>             <td>Wed, 29 Oct 2014</td> <th>  Prob (F-statistic):</th> <td>0.000201</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Time:</th>                 <td>11:13:48</td>     <th>  Log-Likelihood:    </th> <td>  7.8003</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>No. Observations:</th>      <td>    11</td>      <th>  AIC:               </th> <td>  -11.60</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Df Residuals:</th>          <td>     9</td>      <th>  BIC:               </th> <td>  -10.80</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Df Model:</th>              <td>     1</td>      <th>                     </th>     <td> </td>   \n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Covariance Type:</th>      <td>nonrobust</td>    <th>                     </th>     <td> </td>   \n",
        "</tr>\n",
        "</table>\n",
        "<table class=\"simpletable\">\n",
        "<tr>\n",
        "        <td></td>          <th>coef</th>     <th>std err</th>      <th>t</th>      <th>P>|t|</th> <th>[95.0% Conf. Int.]</th> \n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Inflammation</th> <td>    1.0159</td> <td>    0.169</td> <td>    6.006</td> <td> 0.000</td> <td>    0.633     1.399</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Intercept</th>    <td>   -0.0105</td> <td>    0.083</td> <td>   -0.126</td> <td> 0.902</td> <td>   -0.198     0.177</td>\n",
        "</tr>\n",
        "</table>"
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 6,
       "text": [
        "<class 'statsmodels.iolib.summary.Summary'>\n",
        "\"\"\"\n",
        "                            GLS Regression Results                            \n",
        "==============================================================================\n",
        "Dep. Variable:               Fibrosis   R-squared:                       0.800\n",
        "Model:                            GLS   Adj. R-squared:                  0.778\n",
        "Method:                 Least Squares   F-statistic:                     36.07\n",
        "Date:                Wed, 29 Oct 2014   Prob (F-statistic):           0.000201\n",
        "Time:                        11:13:48   Log-Likelihood:                 7.8003\n",
        "No. Observations:                  11   AIC:                            -11.60\n",
        "Df Residuals:                       9   BIC:                            -10.80\n",
        "Df Model:                           1                                         \n",
        "Covariance Type:            nonrobust                                         \n",
        "================================================================================\n",
        "                   coef    std err          t      P>|t|      [95.0% Conf. Int.]\n",
        "--------------------------------------------------------------------------------\n",
        "Inflammation     1.0159      0.169      6.006      0.000         0.633     1.399\n",
        "Intercept       -0.0105      0.083     -0.126      0.902        -0.198     0.177\n",
        "================================================================================\n",
        "\n",
        "Warnings:\n",
        "[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.\n",
        "\"\"\""
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "source": [
      "![image](figures/fibrosis.png)"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "lobular_collapse"
     ],
     "language": "python",
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "outputs": [
      {
       "html": [
        "<table class=\"simpletable\">\n",
        "<caption>GLS Regression Results</caption>\n",
        "<tr>\n",
        "  <th>Dep. Variable:</th>    <td>Lobular_collapse</td> <th>  R-squared:         </th> <td>   0.586</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Model:</th>                   <td>GLS</td>       <th>  Adj. R-squared:    </th> <td>   0.540</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Method:</th>             <td>Least Squares</td>  <th>  F-statistic:       </th> <td>   12.73</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Date:</th>             <td>Wed, 29 Oct 2014</td> <th>  Prob (F-statistic):</th>  <td>0.00605</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Time:</th>                 <td>11:13:48</td>     <th>  Log-Likelihood:    </th> <td>  2.2626</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>No. Observations:</th>      <td>    11</td>      <th>  AIC:               </th> <td> -0.5252</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Df Residuals:</th>          <td>     9</td>      <th>  BIC:               </th> <td>  0.2706</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Df Model:</th>              <td>     1</td>      <th>                     </th>     <td> </td>   \n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Covariance Type:</th>      <td>nonrobust</td>    <th>                     </th>     <td> </td>   \n",
        "</tr>\n",
        "</table>\n",
        "<table class=\"simpletable\">\n",
        "<tr>\n",
        "      <td></td>         <th>coef</th>     <th>std err</th>      <th>t</th>      <th>P>|t|</th> <th>[95.0% Conf. Int.]</th> \n",
        "</tr>\n",
        "<tr>\n",
        "  <th>FociSize</th>  <td>    1.1379</td> <td>    0.319</td> <td>    3.567</td> <td> 0.006</td> <td>    0.416     1.860</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Intercept</th> <td>    0.0460</td> <td>    0.159</td> <td>    0.289</td> <td> 0.779</td> <td>   -0.314     0.406</td>\n",
        "</tr>\n",
        "</table>"
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 7,
       "text": [
        "<class 'statsmodels.iolib.summary.Summary'>\n",
        "\"\"\"\n",
        "                            GLS Regression Results                            \n",
        "==============================================================================\n",
        "Dep. Variable:       Lobular_collapse   R-squared:                       0.586\n",
        "Model:                            GLS   Adj. R-squared:                  0.540\n",
        "Method:                 Least Squares   F-statistic:                     12.73\n",
        "Date:                Wed, 29 Oct 2014   Prob (F-statistic):            0.00605\n",
        "Time:                        11:13:48   Log-Likelihood:                 2.2626\n",
        "No. Observations:                  11   AIC:                           -0.5252\n",
        "Df Residuals:                       9   BIC:                            0.2706\n",
        "Df Model:                           1                                         \n",
        "Covariance Type:            nonrobust                                         \n",
        "==============================================================================\n",
        "                 coef    std err          t      P>|t|      [95.0% Conf. Int.]\n",
        "------------------------------------------------------------------------------\n",
        "FociSize       1.1379      0.319      3.567      0.006         0.416     1.860\n",
        "Intercept      0.0460      0.159      0.289      0.779        -0.314     0.406\n",
        "==============================================================================\n",
        "\n",
        "Warnings:\n",
        "[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.\n",
        "\"\"\""
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "source": [
      "![image](figures/lobular_collapse.png)"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "interface_hepatitis"
     ],
     "language": "python",
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "outputs": [
      {
       "html": [
        "<table class=\"simpletable\">\n",
        "<caption>GLS Regression Results</caption>\n",
        "<tr>\n",
        "  <th>Dep. Variable:</th>    <td>Interface_hepatitis</td> <th>  R-squared:         </th> <td>   0.659</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Model:</th>                    <td>GLS</td>         <th>  Adj. R-squared:    </th> <td>   0.621</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Method:</th>              <td>Least Squares</td>    <th>  F-statistic:       </th> <td>   17.38</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Date:</th>              <td>Wed, 29 Oct 2014</td>   <th>  Prob (F-statistic):</th>  <td>0.00242</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Time:</th>                  <td>11:13:48</td>       <th>  Log-Likelihood:    </th> <td>  2.3063</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>No. Observations:</th>       <td>    11</td>        <th>  AIC:               </th> <td> -0.6126</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Df Residuals:</th>           <td>     9</td>        <th>  BIC:               </th> <td>  0.1832</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Df Model:</th>               <td>     1</td>        <th>                     </th>     <td> </td>   \n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Covariance Type:</th>       <td>nonrobust</td>      <th>                     </th>     <td> </td>   \n",
        "</tr>\n",
        "</table>\n",
        "<table class=\"simpletable\">\n",
        "<tr>\n",
        "       <td></td>         <th>coef</th>     <th>std err</th>      <th>t</th>      <th>P>|t|</th> <th>[95.0% Conf. Int.]</th> \n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Lacunarity</th> <td>   -1.0224</td> <td>    0.245</td> <td>   -4.168</td> <td> 0.002</td> <td>   -1.577    -0.468</td>\n",
        "</tr>\n",
        "<tr>\n",
        "  <th>Intercept</th>  <td>    0.9504</td> <td>    0.143</td> <td>    6.669</td> <td> 0.000</td> <td>    0.628     1.273</td>\n",
        "</tr>\n",
        "</table>"
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 8,
       "text": [
        "<class 'statsmodels.iolib.summary.Summary'>\n",
        "\"\"\"\n",
        "                             GLS Regression Results                            \n",
        "===============================================================================\n",
        "Dep. Variable:     Interface_hepatitis   R-squared:                       0.659\n",
        "Model:                             GLS   Adj. R-squared:                  0.621\n",
        "Method:                  Least Squares   F-statistic:                     17.38\n",
        "Date:                 Wed, 29 Oct 2014   Prob (F-statistic):            0.00242\n",
        "Time:                         11:13:48   Log-Likelihood:                 2.3063\n",
        "No. Observations:                   11   AIC:                           -0.6126\n",
        "Df Residuals:                        9   BIC:                            0.1832\n",
        "Df Model:                            1                                         \n",
        "Covariance Type:             nonrobust                                         \n",
        "==============================================================================\n",
        "                 coef    std err          t      P>|t|      [95.0% Conf. Int.]\n",
        "------------------------------------------------------------------------------\n",
        "Lacunarity    -1.0224      0.245     -4.168      0.002        -1.577    -0.468\n",
        "Intercept      0.9504      0.143      6.669      0.000         0.628     1.273\n",
        "==============================================================================\n",
        "\n",
        "Warnings:\n",
        "[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.\n",
        "\"\"\""
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "source": [
      "![image](figures/interface_hepatitis.png)"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "Exploratory analysis"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "with a random effect on age at death"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "source": [
      "| Dependent variable                       | Models<br />AIC < 2 + AIC<sub>min</sub> | Primary explanatory variables                           |\n",
      "|------------------------------------------|:----------------------------------:|---------------------------------------------------------------------|\n",
      "| Ishak score                              |                  7                 | entropy, tissue-to-sinusoid, focus count, focus size                |\n",
      "| Lobular collapse                         |                  5                 | entropy, lacunarity, tissue-to-sinusoid, focus count                |\n",
      "| Confluent necrosis                       |                  1                 | entropy                                                             |\n",
      "| Interface hepatitis                      |                  2                 | entropy, tissue-to-sinusoid                                         |\n",
      "| Portal inflammation                      |                  4                 | entropy, focus size, lacunarity, focus count, scale, directionality |\n",
      "| Fibrosis                                 |                  2                 | entropy, lacunarity, tissue-to-sinusoid                             |\n",
      "| Biliary hyperplasia                      |                  1                 | focus size                                                          |\n",
      "| Necrosis, apoptosis, random inflammation |    <font color=\"white\">This_is_bla</font>2<font color=\"white\">This_is_bla</font>           | entropy, lacunarity                                                 |"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "source": [
      "- entropy consistently explains histological measures when controlled for age\n",
      "- also important : tissue to sinusoid ratio, focus count and size, lacunarity"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "fragment"
      }
     },
     "source": [
      "- biological / historical reasoning for this potential cohort effect\n",
      "- interpretation of these models\n",
      "- quality of fit"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "Conclusions"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "- our **semi-educated guess** measures may capture relevant information\n",
      "- underlying **structure** in the data needs thought\n",
      "- still no **map** from image or histological measures to condition of individual\n"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {
      "slideshow": {
       "slide_type": "slide"
      }
     },
     "source": [
      "Future directions"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "source": [
      "Further exploration of the dataset"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "-"
      }
     },
     "source": [
      "- 145 sheep ( 89 females )\n",
      "- 11 age classes\n",
      "- potential redundancy in various measures"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "fragment"
      }
     },
     "source": [
      "- 4460 entries across 27 variables\n",
      "- 3330 with full image and histological information\n",
      "- 1196 for which **complete** information is available"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "source": [
      "More data"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "- nutritional information\n",
      "- immunity data"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "source": [
      "Narrow-field images"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "- 12536 images\n",
      "- spatial distribution of nuclei"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "source": [
      "![image](figures/10.jpg)"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "source": [
      "![image](figures/Processed2.jpg)"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "source": [
      "![image](figures/Segmented.jpg)"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {
      "slideshow": {
       "slide_type": "subslide"
      }
     },
     "source": [
      "<img src=\"figures/10x.png\" width=100%></src>"
     ]
    }
   ],
   "metadata": {}
  }
 ]
}