This file contains 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
#' Create a random effect basis with integers rather than factors | |
#' @import mgcv | |
#' @export | |
smooth.construct.re2.smooth.spec <- function (object, data, knots) { | |
if (!is.null(object$id)) | |
stop("random effects don't work with ids.") | |
if(any(sapply(data, is.numeric))) data <- lapply(data, as.factor) ## <-- All I did was this (and below) | |
form <- as.formula(paste("~", paste(object$term, collapse = ":"), | |
"-1")) | |
object$X <- model.matrix(form, data) |
This file contains 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
library(tidyverse) | |
library(gganimate) | |
library(mgcv) | |
library(mvtnorm) | |
# Fit a GAM to the data | |
mod <- gam(hp ~ s(mpg), data=mtcars, method="REML") | |
# Get the linear prediction matrix | |
newdat = data.frame( |
This file contains 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
# NOTE: This was done on RHEL 7.3 with JAGS v4.3.0 and rjags v4-6. It should be fairly portable, but YMMV. | |
# Step 1: create an MKL environment variable for use in the --with-blas option for the JAGS configure script | |
# the below was taken from Martyn Plummer's "Building a portable R binary with Intel tools" | |
# https://martynplummer.files.wordpress.com/2014/10/r-intel-fedora.pdf | |
# I set MKL_LIB_PATH by looking at MKL_LIBS | |
export MKL="-Wl,--start-group ${MKL_LIB_PATH}/libmkl_gf_lp64.a \ | |
> ${MKL_LIB_PATH}/libmkl_gnu_thread.a \ | |
> ${MKL_LIB_PATH}/libmkl_core.a \ |
This file contains 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
library(gridBase) | |
library(grid) | |
library(mgcv) | |
library(statmod) | |
## nicer version of gam.check/rqgam.chack | |
# - deviance residuals for the Q-Q and histogram | |
# - RQR for resids vs linear pred | |
# - response vs fitted | |
# hist.p gives the quantiles of the residuals to show | |
better_check <- function(b, k.sample = 5000, k.rep = 200, rep = 0, level = 0.9, |
This file contains 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
# makes plots (somewhat) like those in ver Hoef and Boveng (2007) | |
# Jay M. Ver Hoef and Peter L. Boveng 2007. QUASI-POISSON VS. NEGATIVE BINOMIAL REGRESSION: HOW SHOULD WE MODEL OVERDISPERSED COUNT DATA? Ecology 88:2766–2772. http://dx.doi.org/10.1890/07-0043.1 | |
# http://www.utstat.utoronto.ca/reid/sta2201s/QUASI-POISSON.pdf | |
# calling with something like: | |
# par(mfrow=c(1,2)) | |
# # define the breaks |
This file contains 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
```{r setup, echo=FALSE, results='hide'} | |
chunkref <- local({ | |
function(chunklabel) { | |
sprintf('[%s](#%s)', chunklabel, chunklabel ) | |
} | |
}) | |
secref <- local({ | |
function(seclabel) { | |
sprintf('[%s](#%s)', seclabel, seclabel ) |
This file contains 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
SankeyR <- function(inputs, losses, unit, labels, format="plot"){ | |
######################## | |
# SankeyR version 1.01 (updated August 10, 2010) | |
# is a function for creating Sankey Diagrams in R. | |
# See http://www.sankey-diagrams.com for excellent examples of Sankey Diagrams. | |
# | |
# OPTIONS: | |
# 'inputs' is a vector of input values | |
# 'losses' is a vector of loss values | |
# 'unit' is a string of the unit |