Skip to content

Instantly share code, notes, and snippets.

View jeffreypullin's full-sized avatar

Jeffrey Pullin jeffreypullin

View GitHub Profile
# 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,
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
alias gst='git status'
alias gc='git commit -v'
alias gp='git push'
alias glo='git log --oneline --decorate'
@jeffreypullin
jeffreypullin / hierarchical-ds-model-prior-analysis.R
Created November 16, 2022 06:30
Analysis of the Gamma prior parameter in the Hierarchical Dawid-Skene model
# From rater
softmax <- function(x) {
exp(x - logsumexp(x))
}
logsumexp <- function(x) {
y <- max(x)
y + log(sum(exp(x - y)))
}
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))
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.
# 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")
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
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]