Created
July 18, 2016 12:55
-
-
Save benwhalley/cf4e1f1a004523d352cb30521dbf7e0f to your computer and use it in GitHub Desktop.
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
extract_sims <- function(modelInterval){ | |
# Grabs simulation draws from a predictInterval object. | |
attr(modelInterval, "sim.results") | |
} | |
bind_sims <- function(sims, newdata){ | |
# Where you have simulated predictions based the model or new dataset, it can | |
# be helpful to combine these with the dataset. | |
# There may also be multiple draws from the simulation, stored in separate | |
# columns. These are melted into long form. | |
b <- bind_cols(as.data.frame(sims), newdata) | |
melt(b, id.vars=names(newdata)) %>% rename(fitted = value, sim=variable) %>% | |
mutate(sim=as.numeric(factor(sim))) | |
} | |
preds <- predictInterval(model, | |
newdata=newdata, | |
n.sims=NSIMS, | |
returnSims=T, | |
include.resid.var=F) | |
preds.long <- bind_sims(extract_sims(rf2.pred.withresid), newdata) | |
# then you can plot or whatever... | |
ggplot(preds.long, aes(x,y)) ... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment