Exemples instructifs…

Download Report

Transcript Exemples instructifs…

Exemples instructifs…
Représentations graphiques
Fonctions de répartition
x=1:6
y=rep(1/6,6)
z=cumsum(y)
plot(c(0,x),c(0,z),lwd=3,col="blue")
segments(0,0,1,0,col="green")
segments(x,z, x+1,z)
Utiliser des données de packages
existants
• search()
[1] ".GlobalEnv"
"package:methods" "package:stats"
[4] "package:graphics" "package:grDevices" "package:utils"
[7] "package:datasets" "Autoloads"
"package:base"
• library( )
ash
base
boot
class
cluster
MASS
David Scott's ASH routines
The R Base Package
Bootstrap R (S-Plus) Functions (Canty)
Functions for Classification
Functions for clustering (by Rousseeuw et al.)……
Main Package of Venables and Ripley's MASS……
•
library(MASS);search()
[1] ".GlobalEnv"
"package:MASS" "package:methods"
[4] "package:stats" "package:graphics" "package:grDevices"
[7] "package:utils" "package:datasets" "Autoloads"
[10] "package:base"
•
data(iris); iris
Sepal.Length Sepal.Width Petal.Length Petal.Width
1
5.1
3.5
1.4
0.2
2
4.9
3.0
1.4
0.2
3
4.7
3.2
1.3
0.2
4
4.6
3.1
1.5
0.2
52
6.4
3.2
4.5
1.5
53
6.9
3.1
4.9
1.5
54
5.5
2.3
4.0
1.3
55
6.5
2.8
4.6
1.5
Species
setosa
setosa
setosa
setosa….
versicolor
versicolor
versicolor
versicolor
• plot(iris$Petal.Length,iris$Petal.Width)
data(Animals); Animals
body brain
Mountain beaver
1.350 8.1
Cow
465.000 423.0
Grey wolf
36.330 119.5
Goat
27.660 115.0
Guinea pig
1.040 5.5
Dipliodocus
11700.000 50.0
Asian elephant
2547.000 4603.0
Donkey
187.100 419.0
Horse
521.000 655.0 …….
plot(
Animals[ ,"brain"],Animals[ ,"body"])
plot(Animals$brain ,Animals$body)
plot(Animals[,1],Animals[,2])
attach(Animals)
plot(body,brain)
detach(Animals)
Plusieurs dessins sur la même page
par(mfrow=c(2,2))
data(Animals)
attach(Animals)
plot(body,brain)
plot(sqrt(body),sqrt(brain))
plot(body^0.1,brain^0.1)
plot(log(body), log(brain))
detach(Animals)
par(mfrow=c(1,1))
Les fonctions plot(), points(), lines(),
ablines(),pairs()…
x = rnorm(50)
plot(x, ann = FALSE, type = "n" )
abline(h = 0,col="gray")
lines(x, col = "green4", lty = "dotted")
points(x, bg = "limegreen", pch = 21)
title(main = "Utilisation simple de la couleur
dans un dessin",col.main = "blue",
cex.main = 1.2, font.main = 4)
par(bg = "white")
n = 100
x = c(0, cumsum(rnorm(n)))
y = c(0, cumsum(rnorm(n)))
xx = c(0:n, n:0)
yy = c(x, rev(y))
plot(xx, yy, type = "n", xlab = "Time", ylab =
"Distance")
polygon(xx, yy, col = "gray")
title("Distance entre deux mouvements Browniens")
x = c(0, 0.4, 0.86, 0.85, 0.69, 0.48, 0.54,
1.09, 1.11, 1.73, 2.05, 2.02)
par(bg = "lightgray");
plot(x, type = "n", axes = FALSE, ann = FALSE);
lines(x, col = "blue");
points(x, pch = 21, bg = "lightcyan", cex = 1.25);
axis(2, col.axis = "blue", las = 1);
axis(1, at = 1:12, lab = month.abb, col.axis = "blue");
box();
title(main = "The Level of Interest in R", font.main =
4, col.main = "red")
title(xlab = "1996", col.lab = "red")
x=c(…)
par(bg = "lightgray");
plot(x, type = "n", axes =
FALSE, ann =
FALSE);
lines(x, col = "blue");
points(x, pch = 21, bg =
"lightcyan", cex =
1.25);
axis(2, col.axis = "blue",
las = 1);
axis(1, at = 1:12, lab =
month.abb, col.axis =
"blue");
box();
title(main = "The Level of Interest in R",
font.main = 4, col.main = "red")
title(xlab = "1996", col.lab = "red")
La fonction pairs
• pairs(iris[1:4], main = « donnees sur les Iris
d’Edgar Anderson", font.main = 4, pch =
19)
La fonction pairs()
• pairs(iris[1:4], main = « Données sur les
Iris d’Edgar Anderson", pch = 21, bg =
c("red","green3« ,"blue")
[unclass(iris$Species)])
Résolution de l’ex 1 p40
• t=c(2:12);N=c(55,90,135,245,403,66
5,1100,1810,3000,4450,7350)
• T=data.frame(t,N,y=log(N));T;
> T
t
N
y
1
2
55 4.007333
2
3
90 4.499810
3
4 135 4.905275
4
5 245 5.501258…..
Calcul de moyenne et écart-type
• apply(T,2,mean);
t
N
7.000000 1754.818182
• apply(T,2,sd);
y
6.475094
t
N
3.316625 2326.625317
y
1.640357
plot(T$t,T$N)
plot(T$t,T$y)
droite de regression
• ll=lm(y~t,data=T);ll;
Call:
lm(formula = y ~ t, data = T)
Coefficients:
(Intercept)
3.0142
t
0.4944
abline(ll);
summary(ll)
• Call:
lm(formula = y ~ t, data = T)
• Residuals:
Min
1Q
-0.08656 -0.02117
Median
0.01500
3Q
0.02912
• Coefficients:
Estimate Std. Error t value
(Intercept) 3.014162
0.032947
91.49
t
0.494419
0.004289 115.27
--Signif. codes: 0 `***' 0.001 `**' 0.01
0.1 ` ' 1
Max
0.04802
Pr(>|t|)
1.13e-14 ***
1.41e-15 ***
`*' 0.05 `.'
summary(ll)
suite
Residual standard error: 0.04499 on 9 degrees of
freedom
Multiple R-Squared: 0.9993,
Adjusted Rsquared: 0.9992
F-statistic: 1.329e+04 on 1 and 9 DF, p-value:
1.413e-15