YAK — Nov 2, 2012, 2:47 AM
data(iris)
iris=iris[iris$Species!="virginica",]
iris[,5]=(iris$Species == "versicolor")+1
names(iris)[5]="Klasse"
iris[,6]=iris[sample(100),1]
names(iris)[6]="Zufall"
m1=lm(Klasse~ Sepal.Length+Sepal.Width,iris )
tr = function(Sepal.Length) unlist(data.frame(Sepal.Width=((1.5- m1$coefficients['(Intercept)'] -Sepal.Length* m1$coefficients['Sepal.Length'])/m1$coefficients['Sepal.Width']),row.names=NULL))
plot(iris$Sepal.Length,iris$Sepal.Width,pch=iris$Klasse, ylab="Sepal width", xlab="Sepal length", main="Iris versicolor and setosa")
curve(tr(x),from=par('usr')[1],to=par('usr')[2],add=TRUE)
legend("topright",legend=c("versicolor", "setosa"),pch = c(1,2))
m=lm(Klasse~ Sepal.Length+Sepal.Width+Petal.Length+Petal.Width+Zufall,iris )
anova(m) #-> Zufall fliegt raus
Analysis of Variance Table
Response: Klasse
Df Sum Sq Mean Sq F value Pr(>F)
Sepal.Length 1 13.26 13.26 1373.36 <2e-16 ***
Sepal.Width 1 7.63 7.63 790.54 <2e-16 ***
Petal.Length 1 3.09 3.09 319.96 <2e-16 ***
Petal.Width 1 0.10 0.10 10.67 0.0015 **
Zufall 1 0.01 0.01 0.72 0.3974
Residuals 94 0.91 0.01
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1