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("ggplot2") # Must be dev version, use: devtools::install_github("hadley/ggplot2") | |
library("gridExtra") | |
library("extrafont") # Need to follow steps here: http://zevross.com/blog/2014/07/30/tired-of-using-helvetica-in-your-r-graphics-heres-how-to-use-the-fonts-you-like-2/ | |
# create data frame | |
year <- c(1760, 1790, 1797, 1850, 1860, 1889, 1900, 1910, 1950) | |
sites <- c("Isleta", "Acoma", "Laguna", "Zuni", "Sandia", "San Felipe", | |
"Santa Ana", "Zia", "Santo Domingo", "Jemez", "Cochiti", | |
"Tesuque", "Nambe", "San Ildefonso", "Pojoaque", "Santa Clara", | |
"San Juan", "Picuris", "Toas") |
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("ggplot2") # Must use Dev version as of 03/18/16 | |
library("gridExtra") | |
library("extrafont") # for font selection | |
library("dplyr") # for data preperation | |
library("cowplot") # for combining plots | |
# Prepare data for plotting | |
# data from Zubrow, E.B.W. (1974), Population, Contact,and Climate in the New Mexican Pueblos | |
# prepared as a long format to facilitate plotting | |
year <- c(1760, 1790, 1797, 1850, 1860, 1889, 1900, 1910, 1950) |
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("data.table") | |
library("rowr") | |
library("dplyr") | |
library("ggplot2") | |
library("Information") | |
library("knitr") | |
library("ggrepel") | |
library("ggthemes") | |
library("ggalt") | |
library("xtable") |
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
### FUNCTIONS | |
# a quick function that plots the lowess response curve for binary data | |
plot.logreg <- function(dat){ | |
dat$obs <- as.numeric(as.character(dat$obs)) # convert y factor to {0,1} digits | |
clr <- ifelse(dat$obs == 1, "orange", "blue") | |
pp <- ggplot(dat, aes(x = pred, y = obs)) + | |
geom_point(color = "gray30", alpha = 0.3) + | |
geom_jitter(width = 0.1, height = 0.11, color = clr) + | |
geom_rug(color = clr) + | |
geom_smooth(formula = y ~ x, se = FALSE, color = "gray25") + |
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
############### FUNCTIONS #################### | |
## Simulate GP based on fixed sigma, rho, and eta | |
## calls gp-predict.stan | |
## this sims over same data (Y,X), but uses infered hyperparameters | |
sim_GP_y <- function(y1, x1, sigma_sq, rho_sq, eta_sq, iter = iter, chains = chains){ | |
sim_fit <- stan(file="gp-predict_SE.stan", data=list(x1=x1, y1=y1, N1=length(x1), | |
x2=x, N2=length(x), eta_sq=eta_sq, | |
rho_sq=rho_sq, sigma_sq=sigma_sq), | |
iter=iter, chains=chains) |
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
// Sample from Gaussian process | |
// All data parameters must be passed as a list to the Stan call | |
// Based on original file from https://code.google.com/p/stan/source/browse/src/models/misc/gaussian-process/ | |
data { | |
int<lower=1> N; | |
real x[N]; | |
real eta_sq; | |
real rho_sq; | |
real sigma_sq; |
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
// Predict from Gaussian Process | |
// All data parameters must be passed as a list to the Stan call | |
// Based on original file from https://code.google.com/p/stan/source/browse/src/models/misc/gaussian-process/ | |
data { | |
int<lower=1> N1; | |
vector[N1] x1; | |
vector[N1] y1; | |
int<lower=1> N2; | |
vector[N2] x2; |
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
// Predict from Gaussian Process | |
// estimate sigma_sq and rho_sq | |
// All data parameters must be passed as a list to the Stan call | |
// Based on original file from https://code.google.com/p/stan/source/browse/src/models/misc/gaussian-process/ | |
data { | |
int<lower=1> N1; | |
vector[N1] x1; | |
vector[N1] y1; | |
int<lower=1> N2; |
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("data.table") | |
library("rowr") | |
library("inTrees") | |
library("dplyr") | |
library("randomForest") | |
library("xtable") | |
library("caret") | |
library("gbm") | |
library("rpart") | |
library("reshape2") |
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("ggplot2") | |
library("ggalt") | |
library("dplyr") | |
color_function <- colorRampPalette(c("cadetblue3", "darkolivegreen3")) | |
num_books = 35 | |
books <- paste0("book",1:num_books) | |
dogcat <- runif(length(books), -2.5, 2.5) | |
dat <- data.frame(books = books, dogcat = dogcat) |