## Annette Dobson (1990) "An Introduction to Generalized Linear Models".
## Page 9: Plant Weight Data.
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
weight <- c(ctl, trt)
group.factor <- gl(2,10,20, labels=c("Ctl","Trt"))
group.logical <- group.factor == "Trt"
group.numeric <- as.numeric(group.logical)
lm.factor <- lm(weight ~ group.factor)
lm.logical <- lm(weight ~ group.logical)
lm.numeric <- lm(weight ~ group.numeric)
list(summary(lm.factor),
summary(lm.logical),
summary(lm.numeric))
[[1]]
Call:
lm(formula = weight ~ group.factor)
Residuals:
Min 1Q Median 3Q Max
-1.0710 -0.4938 0.0685 0.2462 1.3690
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 5.032 0.220 22.85 9.5e-15 ***
group.factorTrt -0.371 0.311 -1.19 0.25
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.696 on 18 degrees of freedom
Multiple R-squared: 0.0731, Adjusted R-squared: 0.0216
F-statistic: 1.42 on 1 and 18 DF, p-value: 0.249
[[2]]
Call:
lm(formula = weight ~ group.logical)
Residuals:
Min 1Q Median 3Q Max
-1.0710 -0.4938 0.0685 0.2462 1.3690
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 5.032 0.220 22.85 9.5e-15 ***
group.logicalTRUE -0.371 0.311 -1.19 0.25
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.696 on 18 degrees of freedom
Multiple R-squared: 0.0731, Adjusted R-squared: 0.0216
F-statistic: 1.42 on 1 and 18 DF, p-value: 0.249
[[3]]
Call:
lm(formula = weight ~ group.numeric)
Residuals:
Min 1Q Median 3Q Max
-1.0710 -0.4938 0.0685 0.2462 1.3690
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 5.032 0.220 22.85 9.5e-15 ***
group.numeric -0.371 0.311 -1.19 0.25
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.696 on 18 degrees of freedom
Multiple R-squared: 0.0731, Adjusted R-squared: 0.0216
F-statistic: 1.42 on 1 and 18 DF, p-value: 0.249
library(effects)
plot(allEffects(lm.factor))
plot(allEffects(lm.logical))
Error: error in evaluating the argument 'x' in selecting a method for function 'plot': Error in mod.matrix %*%
mod$coefficients : non-conformable arguments Calls: allEffects -> allEffects.default -> lapply -> FUN -> effect.lm
plot(allEffects(lm.numeric))