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
# 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
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
# 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
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 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
# 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
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
# Make data with biased train2 set | |
d <- data.frame(x = runif(300, 0, 5)) | |
d$y <- d$x + rnorm(300) | |
d$g <- c('train1', 'train2', 'test') | |
d$y[d$g == 'train2'] <- d$y[d$g == 'train2'] + 5 | |
plot(d$x, d$y, col = factor(d$g)) | |
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) | |
library(dplyr) | |
data(diamonds) | |
train_i <- sample(c(FALSE, TRUE), nrow(diamonds), replace = TRUE, prob = c(0.2, 0.8)) |