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
data{ | |
int<lower=0> N; | |
vector[2] X[N]; | |
} | |
parameters{ | |
vector[2] mu; | |
vector<lower=0>[2] sigma; | |
real<lower=-1,upper=1> rho; | |
} | |
transformed parameters{ |
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
data{ | |
int<lower=0> N; | |
vector[3] X[N]; | |
} | |
parameters{ | |
vector[3] mu; | |
real<lower=0> sig[3]; | |
real<lower=-1,upper=1> rho; | |
} | |
transformed parameters{ |
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
data{ | |
int<lower=0> N; | |
real X1[N]; | |
real X2[N]; | |
real X3[N]; | |
} | |
parameters{ | |
real mu1; | |
real mu2; | |
real mu3; |
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
data{ | |
int<lower=0> N; | |
vector[2] X1[N]; | |
vector[2] X2[N]; | |
} | |
parameters{ | |
real mu; | |
real<lower=0> sig[2]; | |
real<lower=-1,upper=1> rho; | |
real effectA; //between |
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(rvest) | |
p.data <- read_html("http://baseball-data.com/ranking-salary/all/p.html") #ピッチャーの年俸など | |
h.data <- read_html("http://baseball-data.com/ranking-salary/all/h.html") #野手のそれ | |
avg5 <- read_html("http://baseball-data.com/stats/hitter2-all/avg-5.html") #規定打数1/3以上の打者基本成績 | |
era5 <- read_html("http://baseball-data.com/stats/pitcher2-all/era-5.html") #規定投球回1/3以上の投手基本成績 | |
p.df <- as.data.frame(html_table(p.data,head=T)) | |
head(p.df) | |
library(stringr) # 文字列操作パッケージ | |
p.df$順位 <- NULL |
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(rstan) | |
library(ggplot2) | |
rstan_options(auto_write = TRUE) | |
options(mc.cores = parallel::detectCores()) | |
N <- 10000 | |
mu <- 10 | |
sigma <- 20 | |
X <- rnorm(N,mu,sigma) | |
modelcode <- ' |
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
# 囚人のジレンマ関数をつくる | |
PDG.rule <- function(A,B){ | |
if(A ==1 && B == 1){ payA <- 8; payB <- 8 } | |
if(A ==0 && B == 1){ payA <- 12; payB <- 0 } | |
if(A ==1 && B == 0){ payA <- 0; payB <- 12 } | |
if(A ==0 && B == 0){ payA <- 4; payB <- 4 } | |
return(list(A=payA,B=payB)) | |
} | |
PDG.rule(0,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
# 初期設定 | |
sizeX <- 20 | |
sizeY <- 20 | |
timeMax <- 60 | |
# dat <- matrix(c(0,0,0,0,0,0, | |
# 0,0,1,0,0,0, | |
# 0,0,0,1,0,0, | |
# 0,1,1,1,0,0, | |
# 0,0,0,0,0,0, | |
# 0,0,0,0,0,0),nrow=6,ncol=6,byrow=T) |
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
cellsize <- 160 | |
trace <- 50 | |
cell <- matrix(ncol=cellsize,nrow=trace) | |
# 初期化 | |
cell[1,] <- rbinom(cellsize,1,0.5) | |
### into 2bit | |
dec2bin <- function(num,digit=8){ | |
if(num <= 0 && digit <= 0){ |
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
require(mvtnorm) | |
imKmeans <- function(dat,cl){ | |
# step 1 | |
dat.km <- kmeans(dat,cl,algorithm = "MacQueen") | |
# step 2 | |
conv <- 3 | |
clust <- dat.km$cluster | |
while(conv>0){ |