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
# BiocManager::install("edgeR") | |
library(edgeR) | |
library(readr) | |
library(janitor) | |
library(dplyr) | |
data <- read_delim( | |
"~/Downloads/270324_DRIX082_pg.matrix.tsv", | |
name_repair = make_clean_names, |
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(rater) | |
# We have 'Unsure' ratings for the first three patients. | |
# We encode 'Unsure' = category 5. | |
anesthesia_w_unsure <- anesthesia | |
anesthesia_w_unsure[anesthesia$item %in% 1:3, "rating"] <- 5 | |
# Taken from the rater() function's code. | |
J <- 5 | |
K <- 4 + 1 |
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
alias gst='git status' | |
alias gc='git commit -v' | |
alias gp='git push' | |
alias glo='git log --oneline --decorate' |
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
# From rater | |
softmax <- function(x) { | |
exp(x - logsumexp(x)) | |
} | |
logsumexp <- function(x) { | |
y <- max(x) | |
y + log(sum(exp(x - y))) | |
} |
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) | |
set.seed(42) | |
x <- 1:20 | |
y1 <- 2 * x + 3 | |
y2 <- rep(y1,2) + rnorm(40,0,4) | |
y3 <- rep(y1,2) + rnorm(40,0,10) | |
y <- c(y2, y3) | |
type <- factor(rep(c("clyde","irving"), each = 40)) | |
facet <- factor(rep(c("a","b"), each = 20)) |
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(purrr) | |
# Check if an object is an S3 generic. | |
is_S3_generic <- function(obj) { | |
if (!is.function(obj)) { | |
return(FALSE) | |
} | |
# I assume that primitive functions cannot be generic. |
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
# My version | |
tf <- reticulate::import("tensorflow") # Overides the tf in the package | |
tfp <- reticulate::import("tensorflow_probability") | |
py_version <- reticulate::py_config()$version | |
cat("The version of python is:", py_version, "\n") | |
cat("The version of tensorflow is:", tf$"__version__", "\n") | |
cat("The verion of tensorflow-proability is:", tfp$"__version__", "\n") | |
cat("Extra python information: \n") |
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") | |
test_plot <- qplot(1:10, 1:10 + rnorm(10) | |
ggplot_build(test_plot)$layout$panel_params[[1]]$y.range | |
ggplot_build(test_plot)$layout$panel_params[[1]]$x.range |
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(ruv) | |
library(rsvd) | |
fastRUVIII = function(Y, M, ctl, k=NULL, eta=NULL, average=FALSE, fullalpha=NULL){ | |
# Assumes good input | |
Y = RUV1(Y,eta,ctl) | |
m = nrow(Y) | |
Y0 = fast_residop(Y, M) | |
fullalpha = diag(rsvd(Y0)$d) %*% t(rsvd(Y0)$v) | |
alpha = fullalpha[1:k,,drop=FALSE] |