Skip to content

Instantly share code, notes, and snippets.

View kosugitti's full-sized avatar
🏯
Working from Office

Koji E. Kosugi kosugitti

🏯
Working from Office
View GitHub Profile
@kosugitti
kosugitti / compileBook.sh
Last active March 5, 2022 06:14
本を作る時に一括コンパイルするためのバッチファイル
#!/usr/bin/bash
#####################################################################text1
## changePath
path="course_materials/tex"
filename="Dkiso1_book"
cd $path
## backup
cp ${filename}.tex ${filename}.old
########### upgrade patch
val=$(sed -n 4p ${filename}.tex )
@kosugitti
kosugitti / 8chool_rstan.R
Last active September 16, 2021 07:23
rstanパッケージの動作確認ー8school
library(rstan)
rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores())
stancode <- "
data {
int<lower=0> J; // number of schools
real y[J]; // estimated treatment effects
real<lower=0> sigma[J]; // s.e. of effect estimates
}
A <- factor(rep(1:2,each=8),labels=LETTERS[1:2])
B <- factor(rep(rep(1:4,each=2),2),labels=letters[1:4])
C <- factor(rep(1:2,8),labels=c("あ","い"))
dat <- data.frame(A,B,C)
dat$val <- rnorm(16,0,1)
library(tidyverse)
dat %>% group_by(A,B) %>% summarise(means=mean(val))
@kosugitti
kosugitti / P_jk_theta.R
Created January 9, 2018 06:44
GPCMの反応確率を求めるコード
a <- 1.5
d <- c(-1.5,0,1)
K <- 3
pjkt <- function(theta,a,d,k,K){
bunbo <- 0.0
for(m in 0:K){
tmp <- 0.0
for(l in 0:m){
if(l!=0){
@kosugitti
kosugitti / HMCvsNUTStest.R
Created December 21, 2016 00:57
NUTSアルゴリズムにバグがあると聞いて
model <- '
parameters {
vector[2] z;
}
model{
matrix[2,2] sigma;
vector[2] mu;
mu[1] <- 0.0;
@kosugitti
kosugitti / BayesFactorTest.R
Created December 12, 2016 22:15
Okada(2004) Bayes Factor model
library(rstan)
rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores())
model <- '
data{
int<lower=0> N1;
int<lower=0> N2;
int<lower=0> N3;
real y1[N1];
real y2[N2];
@kosugitti
kosugitti / furin_span2016.R
Last active October 21, 2016 07:14
不倫報道間隔を予想する
## 2016年度の不倫報道データ
dataset <- as.data.frame(
matrix(c("ベッキー","2016-01-07",
"狩野英孝","2016-02-03",
"宮崎謙介議員","2016-02-10",
"桂文枝","2016-03-16",
"石井竜也","2016-03-17",
"乙武洋匡","2016-03-23",
"とにかく明るい安村","2016-04-01",
"NMB48木下春奈","2016-05-08",
---
title: "心理学統計法レポート課題2016"
output:
bookdown::pdf_book:
toc: false
latex_engine: xelatex
mainfont: Hiragino Kaku Gothic Pro
---
\begin{center}
data{
int N;
vector[N] X;
vector[N] Y;
}
parameters{
real alpha;
real beta;
real<lower=0> sigma;
}
data{
int<lower=0> N1;
int<lower=0> N2;
real X1[N1];
real X2[N2];
}
parameters{
real mu1;
real mu2;
real<lower=0> sigma1;