Togaware DATA MINING
Desktop Survival Guide
by Graham Williams
Google

Linear Model

Compare two linear models

> wine = read.csv("wine.csv")
> lm1 = lm(Type ~ ., data=wine)
> lm1

Call:
lm(formula = Type ~ ., data = wine)

Coefficients:
    (Intercept)          Alcohol            Malic              Ash  
      4.4732853       -0.1170038        0.0301710       -0.1485522  
     Alcalinity        Magnesium          Phenols       Flavanoids  
      0.0398543       -0.0004898        0.1443201       -0.3723914  
  Nonflavanoids  Proanthocyanins            Color              Hue  
     -0.3034743        0.0393565        0.0756239       -0.1492451  
       Dilution          Proline  
     -0.2700542       -0.0007011  

> lm2 = lm(Type ~ Alcalinity + Magnesium, data=wine)
> lm2

Call:
lm(formula = Type ~ Alcalinity + Magnesium, data = wine)

Coefficients:
(Intercept)   Alcalinity    Magnesium  
   0.563157     0.116950    -0.009072  

> anova(lm1, lm2)
Analysis of Variance Table

Model 1: Type ~ Alcohol + Malic + Ash + Alcalinity + Magnesium + Phenols + 
    Flavanoids + Nonflavanoids + Proanthocyanins + Color + Hue + 
    Dilution + Proline
Model 2: Type ~ Alcalinity + Magnesium
  Res.Df     RSS  Df Sum of Sq      F    Pr(>F)    
1    164  10.623                                   
2    175  74.856 -11   -64.234 90.154 < 2.2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1



Copyright © 2004-2006 Graham.Williams@togaware.com
Support further development through the purchase of the PDF version of the book.
Brought to you by Togaware.