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
# Edit: whoops, radians | |
library(raster) | |
direction <- raster(nrows=100, ncols=100, xmn=0, xmx=10, , ymn=0, ymx=10) | |
values(direction) <- seq(0, 2 * pi, length.out = 100^2) + rnorm(100^2) | |
velocity <- raster(nrows=100, ncols=100, xmn=0, xmx=10, , ymn=0, ymx=10) | |
values(velocity) <- runif(100^2, 0, 0.1) |
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
x <- c(NA, 5:1) | |
y <- c(5:1, NA) | |
psum <- function(x, y){ | |
x[is.na(x)] <- 0 | |
y[is.na(y)] <- 0 | |
x + y | |
} |
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
# Code by Dave Redding | |
library(raster) | |
zzz=100 | |
colsX<-raster(nrow=zzz,ncol=zzz) | |
values(colsX)<-1:ncell(colsX) | |
extent(colsX)<-c(-100,100,-100,100) | |
cols<-c("#00FF00","#FFFFFF") |
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
library(ggplot2) | |
library(igraph) | |
set.seed(1) | |
# Make some data | |
x <- data.frame(y = c(rnorm(200), rnorm(200, 3), rnorm(200, 6)), | |
x = rep(letters[1:20], each = 30)) |
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
d <- data.frame(year = rep(2012:2016, each = 30), | |
y = rnorm(5 * 30)) | |
ggplot(d, aes(y = y)) + | |
geom_boxplot(aes(x = factor(year))) + | |
geom_smooth(aes(x = as.numeric(factor(year)))) |
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
df1 <- data.frame(y = rnorm(100), x = letters[1:2]) | |
df2 <- data.frame(aggregate(. ~ x, df1, mean), | |
upperCI = aggregate(. ~ x, df1, function(x) quantile(x, 0.025))[, 2], | |
lowerCI = aggregate(. ~ x, df1, function(x) quantile(x, 0.975))[, 2]) | |
ggplot() + | |
geom_violin(data = df1, aes(x = x, y = y)) + | |
geom_errorbar(data = df2, aes(x = x, ymax = upperCI, ymin = lowerCI), width = 0.5) + | |
geom_point(data = df2, aes(x, y)) |
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
library(dplyr) | |
library(ggplot2) | |
d <- data.frame(x = rep(c('a', 'b'), 50), y = rbinom(100, 1, 0.4)) | |
summary <- d %>% | |
group_by(x) %>% | |
summarise(prop = mean(y), CI = 0.95 * sqrt((sum(y)/50 * (50 - sum(y))/50) / 50)) |
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
library(dplyr) | |
library(glmnet) | |
library(splines) | |
library(tidyr) | |
library(ggplot2) | |
library(magrittr) | |
d <- data_frame(cov1 = rnorm(100), | |
cov2 = rnorm(100), |
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
# Run a workflow, specifying one module of each type. | |
work1 <- workflow(occurrence = UKAnophelesPlumbeus, | |
covariate = UKAir, | |
process = OneHundredBackground, | |
model = LogisticRegression, | |
output = PrintMap) | |
# Current form | |
work1 <- ChangeWorkflow(work1, model = RandomForest) |
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
x <- 1:100 | |
n <- sapply(x, function(x) rpois(1, x)) | |
pos <- sapply(1:length(n), function(i) rbinom(1, n[i], plogis(x[i] - 50))) | |
p <- pos / n | |
d <- data.frame(p = p, x = x) | |
m <- glm(p ~ x, data = d, weights = n, family = binomial) | |
m |