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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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 (

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

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

1 15 R Part : website:

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

,, 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

(2/24) : 1. R R R

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

DAA09

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 (

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

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

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

Use R

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

(lm) lm AIC 2 / 1

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

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

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

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

yamadaiR(cEFA).pdf

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

untitled

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

こんにちは由美子です

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

Presentation Title Goes Here

2 / 39

浜松医科大学紀要


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

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

最小2乗法

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

¥¤¥ó¥¿¡¼¥Í¥Ã¥È·×¬¤È¥Ç¡¼¥¿²òÀÏ Âè2²ó

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

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

Fig. 3 Flow diagram of image processing. Black rectangle in the photo indicates the processing area (128 x 32 pixels).


JOURNAL OF THE JAPANESE ASSOCIATION FOR PETROLEUM TECHNOLOGY VOL. 66, NO. 6 (Nov., 2001) (Received August 10, 2001; accepted November 9, 2001) Alterna

わが国企業による資金調達方法の選択問題

Studies of Foot Form for Footwear Design (Part 9) : Characteristics of the Foot Form of Young and Elder Women Based on their Sizes of Ball Joint Girth

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

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

X X X Y R Y R Y R MCAR MAR MNAR Figure 1: MCAR, MAR, MNAR Y R X 1.2 Missing At Random (MAR) MAR MCAR MCAR Y X X Y MCAR 2 1 R X Y Table 1 3 IQ MCAR Y I

駒田朋子.indd

udc-2.dvi

山形大学紀要

dvi

p.1/22

149 (Newell [5]) Newell [5], [1], [1], [11] Li,Ryu, and Song [2], [11] Li,Ryu, and Song [2], [1] 1) 2) ( ) ( ) 3) T : 2 a : 3 a 1 :

untitled

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

Isogai, T., Building a dynamic correlation network for fat-tailed financial asset returns, Applied Network Science (7):-24, 206,

自由集会時系列part2web.key

1 kawaguchi p.1/81

: (EQS) /EQUATIONS V1 = 30*V F1 + E1; V2 = 25*V *F1 + E2; V3 = 16*V *F1 + E3; V4 = 10*V F2 + E4; V5 = 19*V99

A B C B C ICT ICT ITC ICT

Kyushu Communication Studies 第2号

: Bradley-Terry Burczyk

分布


ohpmain.dvi

2

情報処理学会研究報告 IPSJ SIG Technical Report Vol.2017-CG-166 No /3/ HUNTEXHUNTER1 NARUTO44 Dr.SLUMP1,,, Jito Hiroki Satoru MORITA The

RTM RTM Risk terrain terrain RTM RTM 48

untitled

5 Armitage x 1,, x n y i = 10x i + 3 y i = log x i {x i } {y i } 1.2 n i i x ij i j y ij, z ij i j 2 1 y = a x + b ( cm) x ij (i j )

1 Tokyo Daily Rainfall (mm) Days (mm)

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

tokei01.dvi

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

Vol. 36, Special Issue, S 3 S 18 (2015) PK Phase I Introduction to Pharmacokinetic Analysis Focus on Phase I Study 1 2 Kazuro Ikawa 1 and Jun Tanaka 2

untitled

塗装深み感の要因解析

dvi

International Classification of Diseases (ICD) について :[3][4] Standard diagnostic tool for epidemiology, health management and clinical purposes. This i

,.,.,,.,,.,,,,,.,,,.,.,,,.,,.,,,,,,,.,,.,,.,,,,.,,,,,,.,,.,,.,.,,,,,,.,,,,.

A5 PDF.pwd

PC_14ZY6_BFT150A_US_ indd

AtCoder Regular Contest 073 Editorial Kohei Morita(yosupo) A: Shiritori if python3 a, b, c = input().split() if a[len(a)-1] == b[0] and b[len(

untitled

fx-9860G Manager PLUS_J

大規模データベースを用いた信用リスク計測の問題点と対策(変数選択とデータ量の関係)

kiyo5_1-masuzawa.indd

Transcription:

kubostat2015e p.1 I 2015 (e) GLM kubo@ees.hokudai.ac.jp http://goo.gl/76c4i 2015 07 22 2015 07 21 16:26 kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 1 / 42 1 N k 2 binomial distribution logit link function 3 4 kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 2 / 42 statistaical models appeared in the class 6 GLM : 2012 05 18 http://goo.gl/ufq2 The development of linear models Hierarchical Bayesian Model Be more flexible Generalized Linear Mixed Model (GLMM) Incoporating random effects such as individuality parameter estimation MCMC MLE Generalized Linear Model (GLM) Always normal distribution? That's non-sense! MSE Linear model Kubo Doctrine: Learn the evolution of linear-model family, firstly! kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 3 / 42 kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 4 / 42? how to specify GLM Generalized Linear Model (GLM) (Poisson regression) (logistic regression) (linear regression) Generalized Linear Model (GLM) probability distribution?? link function? kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 5 / 42 kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 6 / 42

kubostat2015e p.2 how to specify Poisson regression model, a GLM GLM how to specify model, a GLM GLM logistic probability distribution Poisson distribution : e.g., β 1 + β 2 x i link function log link function -2 0 2 4 6 0.5 1.0 1.5 2.0 probability distribution binomial distribution : e.g., β 1 + β 2 x i link function logit yi x i kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 7 / 42 kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 8 / 42 N k N k? 1. N k seeds alive 8 y! y i {0, 1, 2,, 8} f i C: T: i N i = 8 y i = 3 (alive) (dead) x i kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 9 / 42 kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 10 / 42 N k Reading data file N k data frame d 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/2015/fig/binomial/data4a.csv") d data frame ( ) > 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 kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 11 / 42 kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 12 / 42

kubostat2015e p.3 N k binomial distribution logit link function > plot(d$x,, pch = c(21, 19)[d$f]) > legend("topleft", legend = c("c", "T"), pch = c(21, 19)) yi C T 2. binomial distribution logit link function x i fertilization effective? kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 13 / 42 kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 14 / 42 binomial distribution logit link function binomial distribution : N y p(y N, q) = ( ) N q y (1 q) N y y ( N ) y N y p(y i 8, q) 0.0 0.1 0.2 0.3 0.4 q = 0.1 q = 0.3 q = 0.8 y i kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 15 / 42 binomial distribution logit link function logistic curve (z i: q i = logistic(z i ) = e.g. z i = β 1 + β 2x i) 1 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 1 q = 1+exp( z) -6-4 -2 0 2 4 6 z kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 16 / 42 binomial distribution logit link function β 1 and β 2 change logistic curve logit link function 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 kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 17 / 42 logistic 1 q = 1 + exp( (β 1 + β 2 x)) = logistic(β 1 + β 2 x) logit q logit(q) = log 1 q = β 1 + β 2 x logit logistic logistic logit logit is the inverse function of logistic function, vice versa kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 18 / 42

kubostat2015e p.4 binomial distribution logit link function MLE for β 1 and β 2 R β 1 β 2 binomial distribution logit link function (A) f i =C (B) y 7 x 7 > glm(cbind(y, N - y) ~ x + f, data = d, family = binomial)... Coefficients: (Intercept) x ft -19.536 1.952 2.022 x yi (A) f i =C x i (B) f i =T x i kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 19 / 42 kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 20 / 42? 3. q logit(q) = log 1 q = β 1 + β 2 x + β 3 f + β 4 xf... in case that β 4 < 0, sometimes it predicts... y T C x kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 21 / 42 kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 22 / 42 in today s example no interaction effect glm(y ~ x + f,...) glm(y ~ x + f + x:f,...) (A) (B) 4. y T C T C x x little difference kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 23 / 42 kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 24 / 42

kubostat2015e p.5? How to avoid data/data? / : 10 3 200 60 3? ( ) avoidable data/data values probability : N k indices such as densities use statistical model with binomial distribution : specific leaf area (SLA) use offset term! described later offset! kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 25 / 42 kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 26 / 42 unfortunately, sometimes fractions appear... example population densities in research plots offset : hard to avoid... outputs from some measuring machines light intensity index x light index {0.1, 0.2,, 1.0} 10 sometimes we have no choice but plot data/data values... glm(..., family = poisson) kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 27 / 42 kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 28 / 42 What? Differences in plot size?!?! R data.frame: Area, light index number of plants x, y x A = / glm() offset > 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 kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 29 / 42 kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 30 / 42

kubostat2015e p.6 vs A vs y > plot(d$x, / ) > plot(, ) / 0.2 0.4 0.6 0.8 1.0 d$x kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 31 / 42 A y kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 32 / 42 x () x > plot(,, cex = d$x * 2)? kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 33 / 42 y x kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 34 / 42 = GLM! 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 ( β ) 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)) λ : kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 35 / 42 kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 36 / 42

kubostat2015e p.7 glm() 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 kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 37 / 42 kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 38 / 42 Plotting the model prediction based on estimation : glm() offset x = 0.9 light environment x = 0.1 dark environment offset = exp( ) solid lines prediction glm() dotted lines true model kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 39 / 42 kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 40 / 42 Improve your statisitcal model and remove data/data values! avoidable data/data values probability : N k indices such as densities use statistical model with binomial distribution : specific leaf area (SLA) use offset term! Improve your statistical model! offset kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 41 / 42 yi (A) The next topic 0 1 2 3 4 5 6 (B) x i = 4 2 3 4 5 6 x i y i Generalized Linear Mixed Model (GLMM) kubostat2015e (http://goo.gl/76c4i) 2015 (e) 2015 07 22 42 / 42