inst/examples/simulation.md

Simulation example

library(earlywarning)
library(snow)
library(methods)
cl <- makeCluster(20, type = "MPI")
##  20 slaves are spawned successfully. 0 failed.
clusterEvalQ(cl, library(earlywarning))
data(ibms)
A <- stability_model(ibm_critical, "OU")
B <- stability_model(ibm_critical, "LSN")
observed <- -2 * (logLik(A) - logLik(B))
clusterExport(cl, ls())
clusterExport(cl, list = c("A", "B"))
reps <- parLapply(cl, 1:500, function(i) compare(A, B))
lr <- lik_ratios(reps)
roc <- roc_data(lr)
save(list = ls(), file = "simulation.rda")
stopCluster(cl)
require(ggplot2)
ggplot(lr) + geom_density(aes(value, fill = simulation), alpha = 0.6) + 
    geom_vline(aes(xintercept = observed))

plot of chunk unnamed-chunk-5

ggplot(roc) + geom_line(aes(False.positives, True.positives))

plot of chunk unnamed-chunk-6



cboettig/earlywarning documentation built on May 13, 2019, 2:07 p.m.