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
# Design recipe | |
myRec <- recipe(Y ~ ., data = trainSet) %>% | |
step_YeoJohnson(all_predictors(), -binVars) %>% | |
step_center(all_predictors(), -binVars) %>% | |
step_scale(all_predictors(), -binVars) %>% | |
step_meanimpute(missingVars) |
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
# binary vars | |
binVars <- which(sapply(X, function(x){all(x %in% 0:1)})) | |
missingVars <- which(apply(X, 2, function(k){any(is.na(k))})) |
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
# binary vars | |
binVars <- which(sapply(X, function(x){all(x %in% 0:1)})) | |
missingVars <- which(apply(X, 2, function(k){any(is.na(k))})) |
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
# Split train/test with rsample | |
set.seed(100) | |
initSplit <- initial_split(X, prop = .9, | |
strata = "Y") | |
trainSet <- training(initSplit) | |
testSet <- testing(initSplit) | |
# Create 5-fold cross-validation, convert to caret class | |
set.seed(100) | |
myFolds <- vfold_cv(trainSet, v = 5, repeats = 5, |
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
# Filter nzv | |
X <- X[,-nearZeroVar(X, freqCut = 4)] # == 80/20 |
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
# Determine intersection of compounds in features and responses | |
commonMols <- intersect(responses$CID, | |
molFeats$CID) | |
# Subset features and responses accordingly | |
responses %<>% filter(CID %in% commonMols) | |
molFeats %<>% filter(CID %in% commonMols) | |
# Compute median pleasantness across the population | |
medianPlsnt <- responses %>% | |
group_by(CID) %>% |
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
# Mon Oct 29 13:17:55 2018 ------------------------------ | |
## DREAM olfaction prediction challenge | |
library(caret) | |
library(rsample) | |
library(tidyverse) | |
library(recipes) | |
library(magrittr) | |
library(doMC) | |
# Create directory and download files |
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
# Simulation with average eggs laid, egg size and group size, w/ and w/o parasitism | |
seqX <- seq(-3, 3, length.out = 100) | |
probsNoPar <- sapply(seqX, function(x){ | |
scenario <- ilogit(a + x*bA) | |
probs <- calculate(scenario, draws) | |
return(unlist(probs)) | |
}) | |
probsPar <- sapply(seqX, function(x){ | |
scenario <- ilogit(a + x*bA + bP + x*bPA) | |
probs <- calculate(scenario, draws) |
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
# Define model effects | |
sigmaML <- cauchy(0, 1, truncation = c(0, Inf), dim = 3) | |
a_fem <- normal(0, sigmaML[1], dim = max(female_id)) | |
a_year <- normal(0, sigmaML[2], dim = max(year)) | |
a_group <- normal(0, sigmaML[3], dim = max(group_id)) | |
a <- normal(0, 5) | |
bA <- normal(0, 3) | |
bEL <- normal(0, 3) | |
bES <- normal(0, 3) |
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(tensorflow) | |
use_condaenv("greta") | |
library(greta) | |
library(tidyverse) | |
library(bayesplot) | |
library(readxl) | |
# Read female reproductive output and discard records w/ NAs | |
fro <- read_xlsx("data.xlsx", sheet = allTabs[2]) | |
fro <- fro[complete.cases(fro),] |