Skip to content

Instantly share code, notes, and snippets.

@mbjoseph
Last active November 14, 2016 17:13
Show Gist options
  • Save mbjoseph/356be5ddb671ecb29e6a7528a73b0197 to your computer and use it in GitHub Desktop.
Save mbjoseph/356be5ddb671ecb29e6a7528a73b0197 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Generative simulations: spatiotemporal process models\n",
"\n",
"*Space-Time Analytics — Lab for spatiotemporal process models*\n",
"\n",
"2016-11-14\n",
"\n",
"Your name: \n",
"\n",
"Date: \n",
"\n",
"## Description\n",
"\n",
"For this week's lab, you will be simulating from a variety of models of increasing complexity to better understand how spatiotemporal process models work. \n",
"\n",
"For each model below, simulate one realization of the parameters and the data (conditional on the parameters). Then, visualize the data in a way that makes sense given the spatial and temporal structure of the data. \n",
"\n",
"## Model 1: Model of the mean\n",
"\n",
"*Specification*\n",
"\n",
"We have observations $y_1, y_2, y_{N_t}$, each of which is independent and identically distributed as:\n",
"\n",
"$$y_t \\sim \\text{Normal}(\\mu = 0, \\sigma_y)$$\n",
"\n",
"$$\\sigma_y \\sim \\text{Normal}_+(0, 1)$$"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# your code here"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Model 2: Varying-intercept model\n",
"\n",
"*Specification*\n",
"\n",
"At $N_s = 100$ spatial locations we observe the response $y(s, t)$ at each of $N_t = 10$ time steps:\n",
"\n",
"**Likelihood**\n",
"\n",
"$$y(s, t) \\sim \\text{Normal}(\\beta_t, \\sigma_y)$$\n",
"\n",
"**Priors**\n",
"\n",
"$$\\beta_t \\sim \\text{Normal}(0, \\sigma_\\beta)$$\n",
"\n",
"$$\\sigma_\\beta \\sim \\text{Normal}_+(0, 1)$$\n",
"\n",
"$$\\sigma_y \\sim \\text{Normal}_+(0, 1)$$"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# your code here"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Model 3: AR(1) model\n",
"\n",
"*Specification*\n",
"\n",
"At $N_s = 100$ spatial locations we observe the response $y(s, t)$ at each of $N_t = 10$ time steps:\n",
"\n",
"**Likelihood**\n",
"\n",
"$$y(s, t) \\sim \\text{Normal}(\\beta_t, \\sigma_y)$$\n",
"\n",
"**Priors**\n",
"\n",
"$$\\beta_t = \\beta_{t - 1} + \\eta_t$$\n",
"\n",
"$$\\eta_t \\sim \\text{Normal}(0, \\sigma_\\eta)$$\n",
"\n",
"$$\\beta_{t = 0} \\sim \\text{Normal}(0, 1)$$\n",
"\n",
"$$\\sigma_\\eta \\sim \\text{Normal}_+(0, 1)$$\n",
"\n",
"$$\\sigma_y \\sim \\text{Normal}_+(0, 1)$$"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# your code here"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Model 4: AR(1) model + spatially-varying intercept\n",
"\n",
"\n",
"At $N_s = 100$ spatial locations with locations $x_1, x_2, ..., x_{N_s}$ we observe the response $y(s, t)$ at each of $N_t = 10$ time steps:\n",
"\n",
"**Likelihood**\n",
"\n",
"$$y(s, t) \\sim \\text{Normal}(\\alpha_s + \\beta_t, \\sigma_y)$$\n",
"\n",
"**Priors**\n",
"\n",
"$$\\alpha_s \\sim \\text{GP}(0, [\\gamma^2 \\text{exp}(-\\phi d_{ij})])$$\n",
"\n",
"$$\\beta_t = \\beta_{t - 1} + \\eta_t$$\n",
"\n",
"$$\\eta_t \\sim \\text{Normal}(0, \\sigma_\\eta)$$\n",
"\n",
"$$\\beta_{t = 0} \\sim \\text{Normal}(0, 1)$$\n",
"\n",
"$$\\sigma_\\eta \\sim \\text{Normal}_+(0, 1)$$\n",
"\n",
"$$\\sigma_y \\sim \\text{Normal}_+(0, 1)$$\n",
"\n",
"$$\\gamma \\sim \\text{Normal}_+(0, 1)$$\n",
"\n",
"$$\\phi \\sim \\text{Normal}_+(0, 1)$$\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# your code here"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Model 5: Spatiotemporal process model\n",
"\n",
"At $N_s = 100$ spatial locations with locations $x_1, x_2, ..., x_{N_s}$ we observe the response $y(s, t)$ at each of $N_t = 10$ time steps:\n",
"\n",
"**Likelihood**\n",
"\n",
"$$y(s, t) \\sim \\text{Normal}(\\alpha_{st}+ \\beta_{t}, \\sigma_y)$$\n",
"\n",
"**Priors**\n",
"\n",
"$$\\alpha_{st} = \\alpha_{s, t - 1} + \\omega_{st}$$\n",
"\n",
"$$\\omega_{s, t} \\sim \\text{GP}(0, [\\gamma^2 \\text{exp}(-\\phi d_{ij})])$$\n",
"\n",
"$$\\alpha_{s, t = 0} \\sim \\text{GP}(0, [\\gamma^2 \\text{exp}(-\\phi d_{ij})])$$\n",
"\n",
"$$\\beta_t = \\beta_{t - 1} + \\eta_t$$\n",
"\n",
"$$\\eta_t \\sim \\text{Normal}(0, \\sigma_\\eta)$$\n",
"\n",
"$$\\beta_{t = 0} \\sim \\text{Normal}(0, 1)$$\n",
"\n",
"$$\\sigma_\\eta \\sim \\text{Normal}_+(0, 1)$$\n",
"\n",
"$$\\sigma_y \\sim \\text{Normal}_+(0, 1)$$\n",
"\n",
"$$\\gamma \\sim \\text{Normal}_+(0, 1)$$\n",
"\n",
"$$\\phi \\sim \\text{Normal}_+(0, 1)$$"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# your code here"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Check your understanding\n",
"\n",
"Explain how you would modify your spatiotemporal process model to accomplish the following (e.g., which parameters would you change, and how would you change them?): \n",
"\n",
"### Reduce spatial variation\n",
"\n",
"Your text here\n",
"\n",
"### Increase the differences among years in the response $y$\n",
"\n",
"Your text here\n",
"\n",
"### Increase the spatial range for the spatiotemporal effect, so that distant sites behave more similarly\n",
"\n",
"Your text here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"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.5.1"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment