一般化線形 (混合) モデル (2) - ロジスティック回帰と GLMM

Similar documents
kubostat2015e p.2 how to specify Poisson regression model, a GLM GLM how to specify model, a GLM GLM logistic probability distribution Poisson distrib

kubostat2017e p.1 I 2017 (e) GLM logistic regression : : :02 1 N y count data or

kubostat7f p GLM! logistic regression as usual? N? GLM GLM doesn t work! GLM!! probabilit distribution binomial distribution : : β + β x i link functi

講義のーと : データ解析のための統計モデリング. 第3回

kubostat2017c p (c) Poisson regression, a generalized linear model (GLM) : :

k2 ( :35 ) ( k2) (GLM) web web 1 :

60 (W30)? 1. ( ) 2. ( ) web site URL ( :41 ) 1/ 77

講義のーと : データ解析のための統計モデリング. 第5回

/ 60 : 1. GLM? 2. A: (pwer functin) x y?

kubo2017sep16a p.1 ( 1 ) : : :55 kubo ( ( 1 ) / 10

kubostat2017j p.2 CSV CSV (!) d2.csv d2.csv,, 286,0,A 85,0,B 378,1,A 148,1,B ( :27 ) 10/ 51 kubostat2017j (

/ 55 2 : : (GLM) 1. 1/23 ( )? GLM? (GLM ) 2.! 1/25 ( ) ffset (GLM )

k3 ( :07 ) 2 (A) k = 1 (B) k = 7 y x x 1 (k2)?? x y (A) GLM (k

講義のーと : データ解析のための統計モデリング. 第2回

(2/24) : 1. R R R

12/1 ( ) GLM, R MCMC, WinBUGS 12/2 ( ) WinBUGS WinBUGS 12/2 ( ) : 12/3 ( ) :? ( :51 ) 2/ 71

kubostat2018d p.2 :? bod size x and fertilization f change seed number? : a statistical model for this example? i response variable seed number : { i

1 15 R Part : website:

,, Poisson 3 3. t t y,, y n Nµ, σ 2 y i µ + ɛ i ɛ i N0, σ 2 E[y i ] µ * i y i x i y i α + βx i + ɛ i ɛ i N0, σ 2, α, β *3 y i E[y i ] α + βx i

kubostat2017b p.1 agenda I 2017 (b) probability distribution and maximum likelihood estimation :

(lm) lm AIC 2 / 1

y i OLS [0, 1] OLS x i = (1, x 1,i,, x k,i ) β = (β 0, β 1,, β k ) G ( x i β) 1 G i 1 π i π i P {y i = 1 x i } = G (

DAA09

Use R

% 10%, 35%( 1029 ) p (a) 1 p 95% (b) 1 Std. Err. (c) p 40% 5% (d) p 1: STATA (1). prtesti One-sample test of pr

/22 R MCMC R R MCMC? 3. Gibbs sampler : kubo/

1 環境統計学ぷらす 第 5 回 一般 ( 化 ) 線形混合モデル 高木俊 2013/11/21

80 X 1, X 2,, X n ( λ ) λ P(X = x) = f (x; λ) = λx e λ, x = 0, 1, 2, x! l(λ) = n f (x i ; λ) = i=1 i=1 n λ x i e λ i=1 x i! = λ n i=1 x i e nλ n i=1 x

第11回:線形回帰モデルのOLS推定

²¾ÁÛ¾õ¶·É¾²ÁË¡¤Î¤¿¤á¤Î¥Ñ¥Ã¥±¡¼¥¸DCchoice ¡Ê»ÃÄêÈÇ¡Ë

kubo2015ngt6 p.2 ( ( (MLE 8 y i L(q q log L(q q 0 ˆq log L(q / q = 0 q ˆq = = = * ˆq = 0.46 ( 8 y 0.46 y y y i kubo (ht

第13回:交差項を含む回帰・弾力性の推定

: (GLMM) (pseudo replication) ( ) ( ) & Markov Chain Monte Carlo (MCMC)? /30

untitled

1 Stata SEM LightStone 4 SEM 4.. Alan C. Acock, Discovering Structural Equation Modeling Using Stata, Revised Edition, Stata Press 3.

201711grade2.pdf

2 / 39

yamadaiR(cEFA).pdf

卒業論文

「産業上利用することができる発明」の審査の運用指針(案)

H22 BioS t (i) treat1 treat2 data d1; input patno treat1 treat2; cards; ; run; 1 (i) treat = 1 treat =

kubostat1g p. MCMC binomial distribution q MCMC : i N i y i p(y i q = ( Ni y i q y i (1 q N i y i, q {y i } q likelihood q L(q {y i } = i=1 p(y i q 1

AR(1) y t = φy t 1 + ɛ t, ɛ t N(0, σ 2 ) 1. Mean of y t given y t 1, y t 2, E(y t y t 1, y t 2, ) = φy t 1 2. Variance of y t given y t 1, y t

こんにちは由美子です

PackageSoft/R-033U.tex (2018/March) R:

今回 次回の要点 あぶない 時系列データ解析は やめましょう! 統計モデル のあてはめ Danger!! (危 1) 時系列データの GLM あてはめ (危 2) 時系列Yt 時系列 Xt 各時刻の個体数 気温 とか これは次回)

p.1/22

2 と入力すると以下のようになる > x1<-c(1.52,2,3.01,9,2,6.3,5,11.2) > y1<-c(4,0.21,-1.5,8,2,6,9.915,5.2) > cor(x1,y1) [1] > cor.test(x1,y1) Pearson's produ

kubostat2018a p.1 統計モデリング入門 2018 (a) The main language of this class is 生物多様性学特論 Japanese Sorry An overview: Statistical Modeling 観測されたパターンを説明する統計モデル

統計モデリング入門 2018 (a) 生物多様性学特論 An overview: Statistical Modeling 観測されたパターンを説明する統計モデル 久保拓弥 (北海道大 環境科学) 統計モデリング入門 2018a 1

Microsoft PowerPoint - GLMMexample_ver pptx

Stata11 whitepapers mwp-037 regress - regress regress. regress mpg weight foreign Source SS df MS Number of obs = 74 F(

インターネットを活用した経済分析 - フリーソフト Rを使おう

: Bradley-Terry Burczyk

R John Fox R R R Console library(rcmdr) Rcmdr R GUI Windows R R SDI *1 R Console R 1 2 Windows XP Windows * 2 R R Console R ˆ R

H22 BioS (i) I treat1 II treat2 data d1; input group patno treat1 treat2; cards; ; run; I

/ *1 *1 c Mike Gonzalez, October 14, Wikimedia Commons.

J1順位と得点者数の関係分析

最小2乗法


tokei01.dvi

dvi

1 Tokyo Daily Rainfall (mm) Days (mm)

1 Stata SEM LightStone 3 2 SEM. 2., 2,. Alan C. Acock, Discovering Structural Equation Modeling Using Stata, Revised Edition, Stata Press.

GLM PROC GLM y = Xβ + ε y X β ε ε σ 2 E[ε] = 0 var[ε] = σ 2 I σ 2 0 σ 2 =... 0 σ 2 σ 2 I ε σ 2 y E[y] =Xβ var[y] =σ 2 I PROC GLM

udc-2.dvi

Rによる計量分析:データ解析と可視化 - 第3回 Rの基礎とデータ操作・管理

2.1 R, ( ), Download R for Windows base. R ( ) R win.exe, 2.,.,.,. R > 3*5 # [1] 15 > c(19,76)+c(11,13)

1. 2 Blank and Winnick (1953) 1 Smith (1974) Shilling et al. (1987) Shilling et al. (1987) Frew and Jud (1988) James Shilling Voith (1992) (Shilling e

untitled

28

> usdata01 と打ち込んでエンター キーを押すと V1 V2 V : : : : のように表示され 読み込まれていることがわかる ここで V1, V2, V3 は R が列のデータに自 動的につけた変数名である ( variable

10:30 12:00 P.G. vs vs vs 2

untitled

2016.

第121回関東連合産科婦人科学会総会・学術集会 プログラム・抄録

N Express5800/R320a-E4 N Express5800/R320a-M4 ユーザーズガイド

Express5800/R320a-E4, Express5800/R320b-M4ユーザーズガイド

こんにちは由美子です

と入力する すると最初の 25 行が表示される 1 行目は変数の名前であり 2 列目は企業番号 (1,,10),3 列目は西暦 (1935,,1954) を表している ( 他のパネルデータを分析する際もデ ータをこのように並べておかなくてはならない つまりまず i=1 を固定し i=1 の t に関


201711grade1ouyou.pdf

1 kawaguchi p.1/81

Stata 11 Stata ts (ARMA) ARCH/GARCH whitepaper mwp 3 mwp-083 arch ARCH 11 mwp-051 arch postestimation 27 mwp-056 arima ARMA 35 mwp-003 arima postestim

JMP V4 による生存時間分析

2/50 Auction: Theory and Practice 3 / 50 (WTO) 10 SDR ,600 Auction: Theory and Practice 4 / 50 2

Presentation Title Goes Here

Excess Capacity and Effectiveness of Policy Interventions: Evidence from the Cement Industry SMU

untitled

DAA01

Microsoft Word - 計量研修テキスト_第5版).doc

Microsoft Word - D JP.docx

untitled

ECCS. ECCS,. ( 2. Mac Do-file Editor. Mac Do-file Editor Windows Do-file Editor Top Do-file e

2 H23 BioS (i) data d1; input group patno t sex censor; cards;

BMIdata.txt DT DT <- read.table("bmidata.txt") DT head(dt) names(dt) str(dt)

s = 1.15 (s = 1.07), R = 0.786, R = 0.679, DW =.03 5 Y = 0.3 (0.095) (.708) X, R = 0.786, R = 0.679, s = 1.07, DW =.03, t û Y = 0.3 (3.163) + 0

Stata User Group Meeting in Kyoto / ( / ) Stata User Group Meeting in Kyoto / 21

1 (1) (2)

- 2 -

Transcription:

.. ( ) (2) GLMM kubo@ees.hokudai.ac.jp I http://goo.gl/rrhzey 2013 08 27 : 2013 08 27 08:29 kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 1 / 74

I.1 N k.2 binomial distribution logit link function.3.4! offset.5 GLM!.6.7 kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 2 / 74

II.8 r i.9 GLMM (A) f i =C (B) f i =T yi 0 2 4 6 8 0 2 4 6 8 8 9 10 11 12 x i 8 9 10 11 12 x i kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 3 / 74

6 7 : : 2012 05 18 http://goo.gl/ufq2 kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 4 / 74

kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 5 / 74

? (GLM) (Poisson regression) (logistic regression) (linear regression) kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 6 / 74

(GLM)??? kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 7 / 74

GLM : : e.g., β 1 + β 2 x i : -2 0 2 4 6 0.5 1.0 1.5 2.0 kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 8 / 74

GLM logistic : : e.g., β 1 + β 2 x i : logit yi 0 2 4 6 8 8 9 10 11 12 x i kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 9 / 74

N k 1. N k y i {0, 1, 2,, 8} kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 10 / 74

N k? 8 y! f i C: T: i N i = 8 y i = 3 (alive) (dead) x i kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 11 / 74

N k data4a.csv CSV (comma separated value) format file R : > d <- read.csv("data4a.csv") or > d <- read.csv( + "http://hosho.ees.hokudai.ac.jp/~kubo/stat/2013/fig/binomial/data4a.csv") d data frame ( ) kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 12 / 74

N k data frame d > summary(d) N y x f Min. :8 Min. :0.00 Min. : 7.660 C:50 1st Qu.:8 1st Qu.:3.00 1st Qu.: 9.338 T:50 Median :8 Median :6.00 Median : 9.965 Mean :8 Mean :5.08 Mean : 9.967 3rd Qu.:8 3rd Qu.:8.00 3rd Qu.:10.770 Max. :8 Max. :8.00 Max. :12.440 kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 13 / 74

N k > plot(d$x, d$y, pch = c(21, 19)[d$f]) > legend("topleft", legend = c("c", "T"), pch = c(21, 19)) yi 0 2 4 6 8 C T 8 9 10 11 12 x i? kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 14 / 74

binomial distribution logit link function 2. binomial distribution logit link function kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 15 / 74

binomial distribution logit link function : N y ( N y p(y N, q) = ( ) N q y (1 q) N y y ) N y p(y i 8, q) 0.0 0.1 0.2 0.3 0.4 q = 0.1 q = 0.8 q = 0.3 0 2 4 6 8 y i kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 16 / 74

binomial distribution logit link function (z i : e.g. z i = β 1 + β 2 x i ) 1 q i = logistic(z i ) = 1 + exp( z i ) > logistic <- function(z) 1 / (1 + exp(-z)) # > z <- seq(-6, 6, 0.1) > plot(z, logistic(z), type = "l") q 0.0 0.2 0.4 0.6 0.8 1.0 q = -6-4 -2 0 2 4 6 z 1 1+exp( z) kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 17 / 74

binomial distribution logit link function {β 1, β 2 } = {0, 2} (A) β 2 = 2 β 1 (B) β 1 = 0 β 2 q 0.0 0.2 0.4 0.6 0.8 1.0 (A) β 2 = 2 β 1 = 2 β 1 = 0-3 -2-1 0 1 2 3 x β 1 = 3 0.0 0.2 0.4 0.6 0.8 1.0 (B) β 1 = 0 β 2 = 4 β 2 = 2-3 -2-1 0 1 2 3 x β 2 = 1 {β 1, β 2 } x q 0 q 1 kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 18 / 74

binomial distribution logit link function logit link function logistic 1 q = 1 + exp( (β 1 + β 2 x)) = logistic(β 1 + β 2 x) logit logit(q) = log q 1 q = β 1 + β 2 x logit logistic logistic logit logit is the inverse function of logistic function, vice versa kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 19 / 74

binomial distribution logit link function R β 1 β 2 (A) f i =C (B) y 0 2 4 6 8 x 7 8 9 10 11 12 0 2 4 6 8 x 7 8 9 10 11 12 > glm(cbind(y, N - y) ~ x + f, data = d, family = binomial)... Coefficients: (Intercept) x ft -19.536 1.952 2.022 kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 20 / 74

binomial distribution logit link function : (A) f i =C (B) f i =T yi 0 2 4 6 8 0 2 4 6 8 8 9 10 11 12 x i 8 9 10 11 12 x i kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 21 / 74

3. kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 22 / 74

? logit(q) = log q 1 q = β 1 + β 2 x + β 3 f + β 4 xf... in case that β 4 < 0, sometimes it predicts... y 0 2 4 6 8 T C 8 9 10 11 12 x kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 23 / 74

glm(y ~ x + f,...) glm(y ~ x + f + x:f,...) (A) (B) y 0 2 4 6 8 T C 0 2 4 6 8 T C 8 9 10 11 12 x 8 9 10 11 12 x kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 24 / 74

! offset 4.! offset kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 25 / 74

! offset? / : 10 3 200 60 3? ( ) kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 26 / 74

! offset : N k : : specific leaf area (SLA) : offset! kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 27 / 74

! offset kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 28 / 74

! offset offset : x {0.1, 0.2,, 1.0} 10 glm(..., family = poisson) kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 29 / 74

! offset?! x A = /! glm() offset kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 30 / 74

! offset R data.frame: Area, x, y > load("d2.rdata") > head(d, 8) # 8 Area x y 1 0.017249 0.5 0 2 1.217732 0.3 1 3 0.208422 0.4 0 4 2.256265 0.1 0 5 0.794061 0.7 1 6 0.396763 0.1 1 7 1.428059 0.6 1 8 0.791420 0.3 1 kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 31 / 74

! offset vs > plot(d$x, d$y / d$area) d$y/d$area 0 5 10 15 0.2 0.4 0.6 0.8 1.0 d$x kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 32 / 74

! offset A vs y > plot(d$area, d$y) d$y 0 5 10 15 0.0 1.0 2.0 3.0 d$area A y kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 33 / 74

! offset x ( ) > plot(d$area, d$y, cex = d$x * 2) d$y 0 5 10 15 0.0 1.0 2.0 3.0 d$area? kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 34 / 74

! offset x y x kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 35 / 74

! offset = 1. i y i λ i : y i Pois(λ i ) 2. λ i A i x i λ i = A i exp(β 1 + β 2 x i ) λ i = exp(β 1 + β 2 x i + log(a i )) log(λ i ) = β 1 + β 2 x i + log(a i ) log(a i ) offset ( β ) kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 36 / 74

! offset GLM! family: poisson, link : "log" : y ~ x offset : log(area) z = β 1 + β 2 x + log(area) a, b λ log(λ) = z λ = exp(z) = exp(β 1 + β 2 x + log(area)) λ : kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 37 / 74

! offset glm() kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 38 / 74

! offset R glm() > fit <- glm(y ~ x, family = poisson(link = "log"), data = d, offset = log(area)) > print(summary(fit)) Call: glm(formula = y ~ x, family = poisson(link = "log"), data = d, offset = log(area)) (......) Coefficients: Estimate Std. Error z value Pr(> z ) (Intercept) 0.321 0.160 2.01 0.044 x 1.090 0.227 4.80 1.6e-06 kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 39 / 74

! offset d$y 0 5 10 15 x = 0.9 light environment x = 0.1 dark environment 0.0 1.0 2.0 3.0 d$area glm() kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 40 / 74

! offset : glm() offset offset = exp( ) 0.0 1.0 2.0 3.0 d$y 0 5 10 15 d$area kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 41 / 74

! offset : N k : : specific leaf area (SLA) : offset! kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 42 / 74

GLM! 5. GLM! (overdispersion)? kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 43 / 74

GLM! :?! (A) i N i = 8 (B) 100 x i y i y i = 3 x i {2, 3, 4, 5, 6} yi 0 2 4 6 8 2 3 4 5 6 x i kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 44 / 74

GLM! N y? number of alive seeds y i : : β 1 + β 2 x i : logit 0 2 4 6 8 2 3 4 5 6 number of leaves x i kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 45 / 74

GLM! GLM! yi 0 2 4 6 8 (A) β 2 (B)! x i = 4 y i 0 1 2 3 4 5 6 2 3 4 5 6 x i 0 2 4 6 8 y i kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 46 / 74

6.? kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 47 / 74

(overdispersion)? (A) Not or less overdispersed 0 5 10 15 (B) Overdispersed!! 0 2 4 6 8 0 2 4 6 8 y i y i kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 48 / 74 0 5 10 15

GLM GLM does not take into account individual differences kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 49 / 74

Almost all real data are overdispersed! kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 50 / 74

7. kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 51 / 74

number of alive seeds y i : : β 1 + β 2 x i + r i : logit 0 2 4 6 8 2 3 4 5 6 number of leaves x i kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 52 / 74

i r i qi 0.0 0.2 0.4 0.6 0.8 1.0 r i > 0 r i = 0 r i < 0 2 3 4 5 6 x i kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 53 / 74

{r i } s = 1.0 s = 1.5-6 -4-2 0 2 4 6 r i s = 3.0 p(r i s) = 1 2πs 2 exp ( r2 i 2s 2 p(r i s) r i r i r i kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 54 / 74 )

r i (A) (B) p(r i s) s = 0.5 50 {r i } s = 3.0 I III I II I I -6-4 -2 0 2 4 6 r i II I II I II I I I III I II I I I I I -6-4 -2 0 2 4 6 r i 1 q i = 1+exp( r i ) 0 5 10 15 0 2 4 6 8 y i 2.9 9.9 p(y i q i ) 0 5 10 15 0 2 4 6 8 y i kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 55 / 74

> # defining logistic function > logistic <- function(z) { 1 / (1 + exp(-z)) } > # random numbers following binomial distribution > rbinom(100, 8, prob = logistic(0)) > # random numbers following Gausssian distribution > rnorm(100, mu = 0, sd = 0.5) > r <- rnorm(100, mu = 0, sd = 0.5) > # random numbers following...? > rbinom(100, 8, prob = logistic(0 + r)) kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 56 / 74

Generalized Linear Mixed Model (GLMM) Mixed : β 1 + β 2 x i + r i fixed effects: β 1 + β 2 x i random effects: +r i fixed? random?? kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 57 / 74

: fixed effects random effects kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 58 / 74

: (linear mixed model, LMM) random effects : : kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 59 / 74

global parameter, local parameter? Generalized Linear Mixed Model (GLMM) : β 1 + β 2 x i + r i fixed effects: β 1 + β 2 x i global parameter s global parameter random effects: +r i local parameter i ( ) global/local parameter kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 60 / 74

全データ 個体個体 3 3 のデータのデータ個体 1 のデータ個体個体 3 3 のデータのデータ個体 2 のデータ {r 1, r 2, r 3,..., r 100 } β 1 β 2 local parameter global parameter? kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 61 / 74 s

r i 8. r i kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 62 / 74

r i r i local parameters: {r 1, r 2,, r 100 } 100 r i > d <- read.csv("data.csv") > head(d) N y x id 1 8 0 2 1 2 8 1 2 2 3 8 2 2 3 4 8 4 2 4 5 8 1 2 5 6 8 0 2 6 kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 63 / 74

r i r i y i ( ) 8 p(y i β 1, β 2 ) = q yi i (1 q i) 8 y i r i i r i L i = p(r i s) = β 1, β 2, s y i ) 1 ( exp r2 i 2πs 2 2s 2 p(y i β 1, β 2, r i ) p(r i s)dr i L(β 1, β 2, s) = i L i kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 64 / 74

r i global parameter local parameter Generalized Linear Mixed Model (GLMM) Mixed : β 1 + β 2 x i + r i global parameter fixed effects: β 1, β 2 : s local parameter random effects: {r 1, r 2,, r 100 } kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 65 / 74

r i r i kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 66 / 74

r i r r = 2.20 q = 0.10 y 0 2 4 6 8 r = 0.60 q = 0.35 y 0 2 4 6 8 r = 1.00 q = 0.73 y 0 2 4 6 8 r = 2.60 q = 0.93 y 0 2 4 6 8..... r p(r s) p(r) = 0.10 r -5 0 5 p(r) = 0.13 r -5 0 5 p(r) = 0.13 r -5 0 5 p(r) = 0.09 r -5 0 5 0 2 4 6 8 y kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 67 / 74

r i r r = 1.10 λ = 0.55 y 0 2 4 6 8 10 r = 0.30 λ = 1.22 y 0 2 4 6 8 10 r = 0.50 λ = 2.72 y 0 2 4 6 8 10 r = 1.30 λ = 6.05 y 0 2 4 6 8 10..... r p(r s) p(r) = 0.22 r -2-1 0 1 2 p(r) = 0.38 r -2-1 0 1 2 p(r) = 0.35 r -2-1 0 1 2 p(r) = 0.17 r -2-1 0 1 2 0 2 4 6 8 10 y kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 68 / 74

r i glmmml package GLMM > install.packages("glmmml") # if you don t have glmmml > library(glmmml) > glmmml(cbind(y, N - y) ~ x, data = d, family = binomial, + cluster = id) > d <- read.csv("data.csv") > head(d) N y x id 1 8 0 2 1 2 8 1 2 2 3 8 2 2 3 4 8 4 2 4 5 8 1 2 5 6 8 0 2 6 kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 69 / 74

r i GLMM : ˆβ1, ˆβ 2, ŝ > glmmml(cbind(y, N - y) ~ x, data = d, family = binomial, + cluster = id)...(snip)... coef se(coef) z Pr(> z ) (Intercept) -4.13 0.906-4.56 5.1e-06 x 0.99 0.214 4.62 3.8e-06 Scale parameter in mixing distribution: 2.49 gaussian Std. Error: 0.309 Residual deviance: 264 on 97 degrees of freedom AIC: 270 ˆβ 1 = 4.13, ˆβ 2 = 0.99, ŝ = 2.49 kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 70 / 74

r i GLMM (A) (B) x = 4 yi 0 2 4 6 8 0 1 2 3 4 5 6 2 3 4 5 6 0 2 4 6 8 x i y kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 71 / 74

GLMM 9. GLMM kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 72 / 74

GLMM + GLMM I (A) pot A pot A pot B pot B (B) logitq i = β 1 + β 2 x i (GLM) q i : logitq i = β 1 + β 2 x i + r i (A) (B) kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 73 / 74

GLMM + GLMM II (C) pot A pot B logitq i = β 1 + β 2 x i + r j (D) pot A pot B logitq i = β 1 + β 2 x i + r i + r j kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 74 / 74

GLMM GLMM random effects global parameter local parameter GLMM global parameter local parameter local parameter (e.g. + ) kubostat2013ou2 (http://goo.gl/rrhzey) ( ) (2) 2013 08 27 75 / 74