R glm Function


glm() function fits linear models to the dataset.

glm(formula, family = gaussian, data, weights, subset,
na.action, start = NULL, etastart, mustart, offset,
control = list(...), model = TRUE, method = "glm.fit",
x = FALSE, y = TRUE, contrasts = NULL, ...)


>Orange #R growth of orange trees dataset

Tree age circumference
1 1 118 30
2 1 484 58
3 1 664 87
4 1 1004 115
5 1 1231 120
6 1 1372 142
7 1 1582 145
8 2 118 33
9 2 484 69
10 2 664 111
11 2 1004 156
12 2 1231 172
13 2 1372 203
14 2 1582 203
15 3 118 30
16 3 484 51
17 3 664 75
18 3 1004 108
19 3 1231 115
20 3 1372 139
21 3 1582 140
22 4 118 32
23 4 484 62
24 4 664 112
25 4 1004 167
26 4 1231 179
27 4 1372 209
28 4 1582 214
29 5 118 30
30 5 484 49
31 5 664 81
32 5 1004 125
33 5 1231 142
34 5 1372 174
35 5 1582 177


> attach(Orange) #put age, Tree, circumference into R search path
> g <- glm(circumference ~ age + Tree)
> g

Call: glm(formula = circumference ~ age + Tree)
Coefficients:
(Intercept) age Tree.L Tree.Q Tree.C Tree^4
17.3997 0.1068 39.9350 2.5199 -8.2671 -4.6955
Degrees of Freedom: 34 Total (i.e. Null); 29 Residual
Null Deviance: 112400
Residual Deviance: 6754 AIC: 297.5


>summary(g)

Call:
glm(formula = circumference ~ age + Tree)
Deviance Residuals:
Min 1Q Median 3Q Max
-30.505 -8.790 3.737 7.650 21.859
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 17.399650 5.543461 3.139 0.00388 **
age 0.106770 0.005321 20.066 < 2e-16 ***
Tree.L 39.935049 5.768048 6.923 1.31e-07 ***
Tree.Q 2.519892 5.768048 0.437 0.66544
Tree.C -8.267097 5.768048 -1.433 0.16248
Tree^4 -4.695541 5.768048 -0.814 0.42224
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for gaussian family taken to be 232.8927)
Null deviance: 112366.3 on 34 degrees of freedom
Residual deviance: 6753.9 on 29 degrees of freedom
AIC: 297.51
Number of Fisher Scoring iterations: 2