Skip to content

Instantly share code, notes, and snippets.

@puterleat
Last active May 24, 2016 15:07
Show Gist options
  • Save puterleat/df779cffc7f7bf0cb3d5646f7030606f to your computer and use it in GitHub Desktop.
Save puterleat/df779cffc7f7bf0cb3d5646f7030606f to your computer and use it in GitHub Desktop.
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The example below shows why WAIC could be useful when studies are underpowered. Here we simulate data with a weak polynomial relationship between x an y, with only a small sample. Although the effect of the polynomial term does not reach conventional standards for statistical significance, comparing WAIC (an estimate of how effective each model will be at predicting new, out-of-sample data) indicates we should assign a higher probability that `m2` is 'correct', when compared with `m1` (more than twice as likely)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%R\n",
"set.seed(123)\n",
"multix <- data_frame(\n",
" x=rnorm(50),\n",
" y = rnorm(50) + x + .15*x^2\n",
")\n",
"\n",
"ggplot(multix, aes(y=y,x=x))+geom_point()+geom_smooth()\n",
"\n",
"mx.1 <- lm(y~x, data=multix)\n",
"mx.2 <- lm(y~x+I(x^2), data=multix)\n",
"\n",
"anova(mx.2)\n",
"compare(mx.1, mx.2)\n",
"\n",
"plot(compare(mx.1, mx.2))"
]
}
],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment