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
## | |
p_stat_t <- function(v, df = 1, | |
alternative = "two.sided"){ | |
if (!alternative %in% c("two.sided", "less", "greater")) { | |
stop("alternative must be either \"two.sided\", \"less\", or \"greater\".") | |
} | |
if(alternative == "two.sided"){ | |
p0 <- 2*pt(abs(v), df, lower.tail = FALSE) | |
}else if(alternative == "less"){ | |
p0 <- pt(v, df) |
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(reshape2) | |
library(ggplot2) | |
theme_dotdiagram <- function(...){ | |
theme_minimal(...)%+% | |
theme(axis.text.y = element_text(colour="black"), | |
axis.ticks = element_blank(), | |
axis.text.x = element_blank(), | |
axis.title.x = element_blank(), | |
panel.grid.minor = element_blank(), |
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(dplyr) | |
library(ggplot2) | |
x <- c("ward.D","ward.D2", "single","complete", | |
"average","mcquitty","median","centroid") | |
X <- log(as.matrix(iris[,1:2])) | |
df <- data.frame(X) | |
d <- dist(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
library(dplyr) | |
library(ggplot2) | |
x <- c("ward.D","ward.D2", "single","complete", | |
"average","mcquitty","median","centroid") | |
X <- log(as.matrix(iris[,1:4])) | |
d <- dist(X) | |
dm <- as.matrix(d) |
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
\documentclass[tikz,border=14pt]{standalone} | |
\usepackage{tikz} | |
\usetikzlibrary{matrix,shapes,decorations.pathreplacing, backgrounds, positioning} | |
\begin{document} | |
\begin{tikzpicture}[ | |
%Styles | |
Matrix/.style={ | |
matrix of nodes, | |
text height=2.5ex, |
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(pheatmap) | |
library(grid) | |
mid0scale <- function(test, paletteLength=120){ | |
myColor <- colorRampPalette(c("orange", "white", "royalblue"))(paletteLength) | |
myBreaks <- c(seq(min(test), 0, length.out=ceiling(paletteLength/2) + 1), | |
seq(max(test)/paletteLength, max(test), length.out=floor(paletteLength/2))) | |
return(list(color=myColor, breaks=myBreaks)) | |
} | |
set.seed(123) |
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(pheatmap) | |
# length(breaks) == length(paletteLength) + 1 | |
# use floor and ceiling to deal with even/odd length pallettelengths | |
mid0scale <- function(test, paletteLength=120){ | |
myColor <- colorRampPalette(c("orange", "white", "royalblue"))(paletteLength) | |
myBreaks <- c(seq(min(test), 0, length.out=ceiling(paletteLength/2) + 1), | |
seq(max(test)/paletteLength, max(test), length.out=floor(paletteLength/2))) | |
return(list(color=myColor, breaks=myBreaks)) | |
} |
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
\documentclass[tikz,border=14pt]{standalone} | |
\usepackage{tikz} | |
\usetikzlibrary{shapes,positioning} | |
%\usepackage{xcolor} | |
\begin{document} | |
\begin{tikzpicture} | |
\node[draw, rounded corners, fill=gray!10](dna) at (0,0){DNA}; | |
\node[draw, rounded corners, fill=gray!10, right = of dna, xshift = +15pt](rna){RNA}; | |
\node[draw, rounded corners, fill=gray!10, right = of rna, xshift = +15pt](protein) {protein}; | |
\node[draw, rounded corners, fill=gray!10, right = of protein](phenotype) {phenotype}; |
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
# 須山『ベイズ推論による機械学習入門』(講談社)の実装例です | |
softmax <- function(x){ | |
maxx <- max(x) | |
exp(x-maxx)/sum(exp(x-maxx)) | |
} | |
logp_x <-function(x,lambda,loglambda){ | |
x*loglambda-lambda | |
} | |
logsumexp <- 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
library(ggplot2) | |
library(dplyr) | |
Andrews <- function(t, | |
Sepal.Length, Sepal.Width, | |
Petal.Length, Petal.Width,...){ | |
root2 <- sqrt(2) | |
sapply(t, function(t){Sepal.Length/root2 + | |
Sepal.Width*sin(t) + | |
Petal.Length*cos(t) + |