Skip to content

Instantly share code, notes, and snippets.

@abikoushi
abikoushi / Chung2017.R
Created November 21, 2024 22:12
Comparison plots for parallel coordinate vs. UMAP
library(Matrix)
library(readr)
library(tidyr)
library(dplyr)
library(ggplot2)
library(umap)
library(patchwork)
#https://www.weizmann.ac.il/sites/3CA/breast
cells <- read_csv("./data/Data_Chung2017_Breast/Cells.csv")
@abikoushi
abikoushi / pcp_jitter.R
Created November 17, 2024 05:29
Parallel coordinate plot with jitter
library(dplyr)
library(tidyr)
library(ggplot2)
df1 <- mutate(iris, id=1:n()) %>%
pivot_longer(1:4)
ggplot(df1,aes(x=name,y=value,group=id, colour = Species))+
geom_line(alpha=0.5)+
guides(colour=guide_legend(override.aes = list(alpha=1, linewidth=1)))+
@abikoushi
abikoushi / parcoord_dia.r
Created November 7, 2024 10:15
`parcoord` chart in R
library(dplyr)
library(MASS)
data("diamonds", package = "ggplot2")
diamonds2 <- dplyr::select(diamonds, carat, depth:price,x:z)
a01 <- rgb(0,0,0,0.1)
png("pairs.png")
plot(diamonds2, col=a01)
dev.off()
@abikoushi
abikoushi / stepline.R
Created November 3, 2024 01:08
parallel coordinate plot with step-line
library(dplyr)
library(tidyr)
library(ggplot2)
library(patchwork)
df1 <- mutate(iris,id=1:n()) %>%
pivot_longer(1:4)
df2 <-reframe(df1, x=c(as.integer(factor(name))-0.25,as.integer(factor(name))+0.25),
@abikoushi
abikoushi / dataloader_mtx.r
Created October 31, 2024 02:25
read specific rows on text file
scan1_mtx <- function(con, skip = 0){
base::scan(con, nmax = 1, quiet=TRUE,
what = list(i=integer(), j=integer(), v=numeric()),
skip = skip)
}
dataloader_mtx2 <- function(file_path, bag){
con <- file(file_path, open = "r") #Open for reading in text mode
#get matrix size
@abikoushi
abikoushi / sumouterprod2.cpp
Created October 11, 2024 03:57
Sum of the all of the outer product (for Rcpp)
#include "RcppArmadillo.h"
// [[Rcpp::depends(RcppArmadillo)]]
using namespace Rcpp;
using namespace arma;
// [[Rcpp::export]]
double sumouterprod(const arma::field<arma::vec> & V){
int K = V.n_rows;
arma::vec tout = V(0);
for(int j=1; j<K; j++){
@abikoushi
abikoushi / sumouterprod.cpp
Created October 10, 2024 05:35
Sum of the all of the outer product (for Rcpp)
#include "RcppArmadillo.h"
// [[Rcpp::depends(RcppArmadillo)]]
using namespace Rcpp;
using namespace arma;
// [[Rcpp::export]]
double sumouterprod(const arma::field<arma::vec> & V){
int K = V.n_rows;
arma::vec tout = V(0);
for(int j=1; j<K; j++){
@abikoushi
abikoushi / plot_tweedie.R
Created September 28, 2024 21:38
Plot tweedie distribution
library(tweedie)
library(dplyr)
library(ggplot2)
library(ggh4x)
pow <- c(1.01,1.05,1.3,1.9)
phi <- c(0.2,0.5,1,3)
mu <- c(0.1,0.3,2)
dens <- expand.grid(y=y,power=pow,mu=mu,phi=phi) %>%
@abikoushi
abikoushi / geom.tex
Created September 5, 2024 06:39
Tikz example: relationship between binomial and geometric distribution
\documentclass{beamer}
\usepackage{tikz}
\setbeamertemplate{navigation symbols}{}
\usetikzlibrary{positioning}
\makeatletter
\usefonttheme{serif}
\usepackage{xcolor}
\def\mathunderline#1#2{\color{#1}\underline{{\color{black}#2}}\color{black}}
@abikoushi
abikoushi / Fishertest.r
Created August 31, 2024 05:44
p-value function vs. posterior probability
library(BiasedUrn)
library(exact2x2)
library(animation)
#MCMCpack::dnoncenhypergeom(x = NA, cs[1],cs[2],rs[1], 1)
saveGIF({
for(i in c(0:17,17:0)){
rs <- c(18,17)
cs <- c(17,18)
X <-matrix(c(i,cs[1]-i,rs[1]-i,cs[2]-(rs[1]-i)), nrow=2)