Download presentation
Presentation is loading. Please wait.
Published byArlene McKenzie Modified over 9 years ago
1
Statistics 2: generalized linear models
2
General linear model: Y ~ a + b 1 * x 1 + … + b n * x n + ε There are many cases when general linear models are no longer valid: Loss of a) normality of errors, b) homogeneity of variance, c) linearity Sometimes these can be fixed by transformations (e.g. log or sqrt of Y) or by including to the model a) Interactions or b) polynomials (e.g. I(x^2) )
3
Generalized linear models These broaden the concept of linear models –Non-normal error distributions Poisson responses (count number) Binomial responses (number of successes in a trial) Also categorical data (multinomial response) Exponential or Weibull responses (waiting time) –Transformation of the response to linear scale with link function
4
New model elements Generalized linear model: f(Y) ~ a + b 1 * x 1 + … + b n * x n + ε Error term: Variance no longer homogeneous but depends on the mean Link function
5
Response is transformed to linear scale f(Y) = a + b 1 x 1 + … + b n x n To obtain a prediction Y = f -1 (a + b 1 x 1 + … + b n x n )
6
Common choices for link and variance function DistributionLinkVariance NormalIdentity: μ~1 BinomialLogit: log(μ /(1- μ))μ(1- μ) PoissonLogarithm: log(μ)μ
7
Generalized linear models in R glm(formula, family, data) For example: family=binomial(link=“logit”) family=poisson(link=“log”)
8
Binomial data: logistic regression Binomial data gives number of successes in n independent trials –Tossing of a coin ten times –Exposing n patients to a treatment and seeing how many survive Expected value to be predicted (p) is the probability of success –Logit link function transforms this from [0,1] to [-Inf,Inf] Two options of coding the response: –A vector of values 0 or 1: failure or success –A matrix with two columns: first gives the number of successes the second the number of failures DEMO 1
9
Count data: Poisson regression Poisson distributed data is count data –Number of fish caught during a fishing trip –Number of species observed in a given area Link function is log and model predicts expected number Variance increases along the expected value Two special features: –Offset variables: ‘observation time’ –Over/under dispersion: Variance in the data can be less or more than that assumed by the variance function -> can be taken care with dispersal parameter This can also occur with binomial data
10
Measures of fit in glm Proportion of deviance explained –Problem: even a perfect model does not explain all deviance Pseudo R 2 –Nagelkerke’s R 2 1-exp(-2/n*(logLik(model)-logLik(NULLModel))) NULL model is a model with intercept only. n = number of observations DOES NOT work for quasi-distributions! DEMO 2 & exercises
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.