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
imp <- list() | |
for(i in 1:50){ | |
r <- randomForest::randomForest(mpg ~ ., data = mtcars, importance = TRUE) | |
m <- lm(mpg ~ ., data = mtcars) | |
m %>% summary | |
imp[[i]] <- r$importance[,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
# sandbox | |
library(caret) | |
library(tictoc) | |
g1 <- data.frame(mtry = c(2, 5)) | |
tic() |
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
# Assume just the first 16 parameters vary, but can do the same thing. | |
df <- | |
data.frame( | |
ad.surv.intercept=rep(0.0002516054, 16 * 2), | |
ad.surv.temp=0.1702, | |
ad.surv.pack=-0.1654, | |
disp.intercept=0.0064262, | |
disp.pack.size=0.10594, |
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
ad.surv.intercept.vec <- c(0.99 * ad.surv.intercept, 1.01 * ad.surv.intercept) | |
ad.surv.temp.vec <- c(0.99 * ad.surv.temp, 1.01 * ad.surv.temp) | |
# Going to end up being... | |
# 5 runs. 1 with everything at the mean, 2 new ad.surv.intercept and 2 new ad.surv.tmep | |
N <- 5 | |
df <- data.frame(rep(ad.surv.intercept, N), rep(ad.surv.temp.vec, 5)) | |
df[1:2, 1] <- ad.surv.intercept.vec | |
df[3:4, 2] <- ad.surv.temp.vec |
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
# Assume just the first few parameters vary, but can do the same thing. | |
ad.surv.intercept.vec <- c(0.0002516054 , 0.0001) | |
ad.surv.temp.vec <- c(0.1702, 0.2) | |
tic() | |
results <- | |
lapply(1:2, function(x) |
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(caret) | |
m <- train(mpg ~ ., | |
data = mtcars, | |
method = 'glmnet', | |
tuneLength = 10) | |
plot(m) |
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
# 1 covariate and intercept | |
d <- as.matrix(data.frame(intercept = 1, x1 = rnorm(100))) | |
# Many responses | |
many_ys <- matrix(d[, 'x1'] * rep(0:10, each = 100) + rnorm(11 * 100, sd = 0.1), ncol = 11) | |
# Empty list to save our models into. | |
models <- list() |
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
#load packages | |
require(raster) | |
require(colorplaner) | |
require(ggplot2) | |
#here's some dummy data | |
r1<- raster(ncol=10, nrow=10) | |
set.seed(0) | |
values(r1) <- runif(ncell(r1)) |
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 |
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) |