Üldistatud lineaarne mudel
Üldistatud lineaarse mudeli sobitamine käib funktsiooni glm abil, ent on muidu vägagi sarnane (samad funktsiooninimed mudelist erinevate väärtuste kättesaamisel) eelnevale. Olulise täiendusena tuleb valida andmete jaotus ja seosefunktsioon argumendi family abil. Näiteks tavalisele lineaarsele mudelile vastab valik gaussian(link = "identity"), ent kõigist võimalikest valikutest saab ülevaate funktsiooni family abifaili vaadates.
Näiteks:
> m3=glm(weight~Diet*Time,family=gaussian("log"),data=ChickWeight)
> summary(m3)
Call:
glm(formula = weight ~ Diet * Time, family = gaussian("log"),
data = ChickWeight)
Deviance Residuals:
Min 1Q Median 3Q Max
-150.906 -12.839 -4.749 10.976 125.059
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.844792 0.062450 61.566 < 2e-16 ***
Diet2 0.086906 0.098469 0.883 0.37784
Diet3 0.076215 0.093999 0.811 0.41781
Diet4 0.197107 0.092675 2.127 0.03386 *
Time 0.066094 0.003752 17.618 < 2e-16 ***
Diet2:Time 0.004571 0.005822 0.785 0.43270
Diet3:Time 0.016189 0.005488 2.950 0.00331 **
Diet4:Time 0.004741 0.005516 0.860 0.39038
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for gaussian family taken to be 1167.718)
Null deviance: 2914556 on 577 degrees of freedom
Residual deviance: 665598 on 570 degrees of freedom
AIC: 5732.5
Number of Fisher Scoring iterations: 5
ja
> anova(m3,test="Chisq")
Analysis of Deviance Table
Model: gaussian, link: log
Response: weight
Terms added sequentially (first to last)
Df Deviance Resid. Df Resid. Dev P(>|Chi|)
NULL 577 2914556
Diet 3 155863 574 2758693 < 2e-16 ***
Time 1 2081410 573 677283 < 2e-16 ***
Diet:Time 3 11685 570 665598 0.01851 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1