CC BY-NC-ND 3.0
iris
iris
iris
"Sepal.Length"
et "Sepal.Width"
).iris
iris
iris
iris
##
## Call:
## lm(formula = iris$Sepal.Width ~ iris$Sepal.Length)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.1095 -0.2454 -0.0167 0.2763 1.3338
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.41895 0.25356 13.48 <2e-16 ***
## iris$Sepal.Length -0.06188 0.04297 -1.44 0.152
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.4343 on 148 degrees of freedom
## Multiple R-squared: 0.01382, Adjusted R-squared: 0.007159
## F-statistic: 2.074 on 1 and 148 DF, p-value: 0.1519
iris
spp <- unique(iris$Species)
lapply(spp, function(mySpp){
lmX <- lm(iris$Sepal.Width[iris$Species == mySpp] ~
iris$Sepal.Length[iris$Species == mySpp])
summary(lmX)
})
## [[1]]
##
## Call:
## lm(formula = iris$Sepal.Width[iris$Species == mySpp] ~ iris$Sepal.Length[iris$Species ==
## mySpp])
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.72394 -0.18273 -0.00306 0.15738 0.51709
##
## Coefficients:
## Estimate Std. Error t value
## (Intercept) -0.5694 0.5217 -1.091
## iris$Sepal.Length[iris$Species == mySpp] 0.7985 0.1040 7.681
## Pr(>|t|)
## (Intercept) 0.281
## iris$Sepal.Length[iris$Species == mySpp] 6.71e-10 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.2565 on 48 degrees of freedom
## Multiple R-squared: 0.5514, Adjusted R-squared: 0.542
## F-statistic: 58.99 on 1 and 48 DF, p-value: 6.71e-10
##
##
## [[2]]
##
## Call:
## lm(formula = iris$Sepal.Width[iris$Species == mySpp] ~ iris$Sepal.Length[iris$Species ==
## mySpp])
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.65441 -0.12958 -0.00849 0.15137 0.60954
##
## Coefficients:
## Estimate Std. Error t value
## (Intercept) 0.87215 0.44466 1.961
## iris$Sepal.Length[iris$Species == mySpp] 0.31972 0.07463 4.284
## Pr(>|t|)
## (Intercept) 0.0556 .
## iris$Sepal.Length[iris$Species == mySpp] 8.77e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.2697 on 48 degrees of freedom
## Multiple R-squared: 0.2766, Adjusted R-squared: 0.2615
## F-statistic: 18.35 on 1 and 48 DF, p-value: 8.772e-05
##
##
## [[3]]
##
## Call:
## lm(formula = iris$Sepal.Width[iris$Species == mySpp] ~ iris$Sepal.Length[iris$Species ==
## mySpp])
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.63765 -0.18801 0.00438 0.16778 0.56814
##
## Coefficients:
## Estimate Std. Error t value
## (Intercept) 1.4463 0.4309 3.357
## iris$Sepal.Length[iris$Species == mySpp] 0.2319 0.0651 3.562
## Pr(>|t|)
## (Intercept) 0.001549 **
## iris$Sepal.Length[iris$Species == mySpp] 0.000843 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.2898 on 48 degrees of freedom
## Multiple R-squared: 0.2091, Adjusted R-squared: 0.1926
## F-statistic: 12.69 on 1 and 48 DF, p-value: 0.0008435
iris
plot(x = iris$Sepal.Length, y = iris$Sepal.Width,
col = iris$Species, pch = 16)
spp <- unique(iris$Species)
lapply(spp, function(mySpp){
lmX <- lm(iris$Sepal.Width[iris$Species == mySpp] ~
iris$Sepal.Length[iris$Species == mySpp])
points(x = iris$Sepal.Length[iris$Species == mySpp],
y = predict(lmX), type = 'l', lwd = 2, col = mySpp)
})
iris
iris
plot(x = iris$Sepal.Length, y = iris$Sepal.Width,
type = 'n', axes = FALSE, panel.first = {
grid()
axis(1)
axis(2)
})
my3col <- c("#3b86ff", "#e653c8", "#ffd82b")
spp <- unique(iris$Species)
trash <- lapply(spp, function(mySpp){
lmX <- lm(iris$Sepal.Width[iris$Species == mySpp] ~
iris$Sepal.Length[iris$Species == mySpp])
points(x = iris$Sepal.Length[iris$Species == mySpp],
y = predict(lmX), type = 'l', lwd = 2, col = my3col[mySpp])
myCol <- colorRampPalette(c(my3col[mySpp], "darkred"))(101)
colRank <- (iris$Sepal.Width[iris$Species == mySpp] -
predict(lmX))^2
colRank <- round((colRank - min(colRank)) /
(max(colRank) - min(colRank)) * 100) + 1
points(
x = iris$Sepal.Length[iris$Species == mySpp],
y = iris$Sepal.Width[iris$Species == mySpp],
bg = my3col[mySpp], col = myCol[colRank], pch = 21,
cex = 1 + colRank/100)
})
iris
iris
plot(x = iris$Sepal.Length, y = iris$Sepal.Width,
type = 'n', axes = FALSE,
ylim = c(2, 4.5), xlim = c(4, 8),
panel.first = {
grid()
axis(1)
axis(2)
})
my3col <- c("#3b86ff", "#e653c8", "#ffd82b")
spp <- unique(iris$Species)
trash <- lapply(spp, function(mySpp){
lmX <- lm(iris$Sepal.Width[iris$Species == mySpp] ~
iris$Sepal.Length[iris$Species == mySpp])
points(x = iris$Sepal.Length[iris$Species == mySpp],
y = predict(lmX), type = 'l', lwd = 2, col = my3col[mySpp])
myCol <- colorRampPalette(c(my3col[mySpp], "darkred"))(101)
colRank <- (iris$Sepal.Width[iris$Species == mySpp] -
predict(lmX))^2
colRank <- round((colRank - min(colRank)) /
(max(colRank) - min(colRank)) * 100) + 1
segments(
x0 = iris$Sepal.Length[iris$Species == mySpp],
y0 = predict(lmX),
x1 = iris$Sepal.Length[iris$Species == mySpp],
y1 = iris$Sepal.Width[iris$Species == mySpp],
col = my3col[mySpp], lwd = 1 + colRank/50
)
points(
x = iris$Sepal.Length[iris$Species == mySpp],
y = iris$Sepal.Width[iris$Species == mySpp],
bg = my3col[mySpp], col = myCol[colRank], pch = 21,
cex = 1 + colRank/100)
})
iris
iris
plot(x = iris$Sepal.Length, y = iris$Sepal.Width,
type = 'n', axes = FALSE,
ylim = c(2, 4.5), xlim = c(4, 8),
panel.first = {
grid()
axis(1)
axis(2)
})
my3col <- c("#3b86ff", "#e653c8", "#ffd82b")
spp <- unique(iris$Species)
trash <- lapply(spp, function(mySpp){
lmX <- lm(iris$Sepal.Width[iris$Species == mySpp] ~
iris$Sepal.Length[iris$Species == mySpp])
points(x = iris$Sepal.Length[iris$Species == mySpp],
y = predict(lmX), type = 'l', lwd = 2, col = my3col[mySpp])
myCol <- colorRampPalette(c(my3col[mySpp], "darkred"))(101)
colRank <- (iris$Sepal.Width[iris$Species == mySpp] -
predict(lmX))^2
colRank <- round((colRank - min(colRank)) /
(max(colRank) - min(colRank)) * 100) + 1
segments(
x0 = iris$Sepal.Length[iris$Species == mySpp],
y0 = predict(lmX),
x1 = iris$Sepal.Length[iris$Species == mySpp],
y1 = iris$Sepal.Width[iris$Species == mySpp],
col = my3col[mySpp], lwd = 1 + colRank/50
)
points(
x = iris$Sepal.Length[iris$Species == mySpp],
y = iris$Sepal.Width[iris$Species == mySpp],
bg = my3col[mySpp], col = myCol[colRank], pch = 21,
cex = 1 + colRank/100)
})
legend("topright", fill = my3col,
legend = levels(iris$Species), bty = "n")
iris