Created
May 24, 2016 15:12
-
-
Save puterleat/4e54cbb6bea559f56a2dedab97c0b8a5 to your computer and use it in GitHub Desktop.
Using WAIC to compare models
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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). | |
library(rethinking) | |
library(ggplot2) | |
library(dplyr) | |
set.seed(123) | |
multix <- data_frame( | |
x=rnorm(50), | |
y = rnorm(50) + x + .15*x^2 | |
) | |
ggplot(multix, aes(y=y,x=x))+geom_point()+geom_smooth() | |
mx.1 <- lm(y~x, data=multix) | |
mx.2 <- lm(y~x+I(x^2), data=multix) | |
anova(mx.2) | |
compare(mx.1, mx.2) | |
plot(compare(mx.1, mx.2)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment