Vous êtes sur la page 1sur 4

#8.

climatvin <- read.table("http://www.biostatisticien.eu/springeR/climatvin.csv",sep="\t",header=T)

attach(climatvin)

#8.2

X <- as.matrix(climatvin[,-c(1,6)])

#8.3

g <- apply(X,FUN=mean,2)

round(g,2)

#8.4

Xpoint <- scale(X, scale=FALSE)

#8.5

n <- nrow(X)

p <- ncol(X)

inertie <- sum(Xpoint^2)/n

inertie

#8.6

contrinertie <- apply(Xpoint^2,FUN=sum,1)/n/inertie

contrinertie

#8.7
unn <- as.matrix(rep(1,n))

#8.8

g <- t(X)%*%unn/n

#8.9

Xpoint <- X-unn%*%t(g)

#8.10

S <- t(Xpoint)%*%Xpoint/n

S <- cov(X)*(n-1)/n

#8.11

Dunsurs <- diag(1/sqrt(diag(S)))

#8.12

Z <- Xpoint%*%Dunsurs

#8.13

R <- t(Z)%*%Z/n

R <- cor(X)

#8.14

Lambda <- diag(eigen(R)$values)

W <- eigen(R,symmetric=T)$vectors

#8.15

theta <- seq(0,2*pi,.05)

x <- cos(theta)
y <- sin(theta)

plot(x,y,type="l")

abline(h=0,v=0)

A <- W%*%Lambda^(1/2)

text(A[,1:2],colnames(X))

arrows(rep(0,4),rep(0,4),A[,1],A[,2],length=0.1)

#8.16

cumsum(diag(Lambda))/p*100

#8.17

CW <- Z%*%W

#8.18

dev.new()

plot(CW[,c(1,2)],type="p",xlab="Axe 1",ylab="Axe 2")

text(CW[,c(1,2)],labels=ANNEE)

abline(h=0,v=0)

#8.19

plot(CW[,c(1,2)],type="n",xlab="Axe 1",ylab="Axe 2")

bon <- CW[QUALITE==1,c(1,2)]

moyen <- CW[QUALITE==2,c(1,2)]

mediocre <- CW[QUALITE==3,c(1,2)]

text(bon,labels=ANNEE[QUALITE==1],col="red")

text(moyen,labels=ANNEE[QUALITE==2],col="blue")

text(mediocre,labels=ANNEE[QUALITE==3],col="green")

abline(h=0,v=0)
legend("topleft",c("bon","moyen","mediocre"),fill=c("red","blue","green"))

#8.20

QLT <- apply(sweep(CW^2,1,apply(CW^2,FUN=sum,1),FUN="/")[,1:2],FUN=sum,1)

round(QLT,2)

#8.21

require(ade4)

#8.22

rownames(X) <- climatvin[,1]

res <- dudi.pca(X)

scatter(res)

s.class(res$li,as.factor(climatvin[,6]))

Vous aimerez peut-être aussi