R version 2.13.0 (2011-04-13) Copyright (C) 2011 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: x86_64-pc-linux-gnu (64-bit) R est un logiciel libre livré sans AUCUNE GARANTIE. Vous pouvez le redistribuer sous certaines conditions. Tapez 'license()' ou 'licence()' pour plus de détails. R est un projet collaboratif avec de nombreux contributeurs. Tapez 'contributors()' pour plus d'information et 'citation()' pour la façon de le citer dans les publications. Tapez 'demo()' pour des démonstrations, 'help()' pour l'aide en ligne ou 'help.start()' pour obtenir l'aide au format HTML. Tapez 'q()' pour quitter R. > date() [1] "Thu Sep 22 16:14:35 2011" > ################################################### > ### chunk number 2: d1 > ################################################### > #line 181 "/bge/penel/verif_pedadoc/pedadoc/fichestd/tdr28//tdr28.rnw" > casG <- rep(c("poisson_lune", "thon_rouge", "marlin_bleu"), c(3,3,3)) > casG <- as.factor(casG) > casG [1] poisson_lune poisson_lune poisson_lune thon_rouge thon_rouge [6] thon_rouge marlin_bleu marlin_bleu marlin_bleu Levels: marlin_bleu poisson_lune thon_rouge > summary(casG)/length(casG) marlin_bleu poisson_lune thon_rouge 0.3333333 0.3333333 0.3333333 > summary(casG)/length(casG) -> probG > -sum(probG*log(probG)) [1] 1.098612 > > > ################################################### > ### chunk number 3: d2 > ################################################### > #line 192 "/bge/penel/verif_pedadoc/pedadoc/fichestd/tdr28//tdr28.rnw" > casD <- rep(c("poisson_lune", "thon_rouge", "marlin_bleu"), c(6,1,1)) > casD <- as.factor(casD) > casD [1] poisson_lune poisson_lune poisson_lune poisson_lune poisson_lune [6] poisson_lune thon_rouge marlin_bleu Levels: marlin_bleu poisson_lune thon_rouge > summary(casD)/length(casD) marlin_bleu poisson_lune thon_rouge 0.125 0.750 0.125 > summary(casD)/length(casD) -> probD > -sum(probD*log(probD)) [1] 0.7356219 > > > ################################################### > ### chunk number 4: d3 > ################################################### > #line 226 "/bge/penel/verif_pedadoc/pedadoc/fichestd/tdr28//tdr28.rnw" > 1-sum(probG^2) [1] 0.6666667 > > > ################################################### > ### chunk number 5: d4 > ################################################### > #line 232 "/bge/penel/verif_pedadoc/pedadoc/fichestd/tdr28//tdr28.rnw" > 1-sum(probD^2) [1] 0.40625 > > > ################################################### > ### chunk number 6: d5 > ################################################### > #line 302 "/bge/penel/verif_pedadoc/pedadoc/fichestd/tdr28//tdr28.rnw" > x0 <- seq(0.02,1,by=0.02) > plot(0,0,type="n",xlim=c(0,1),ylim=c(0,5),ylab="Rareté",xlab="Proportion") > lines(x0,1/x0-1,lwd=2,col="blue") > lines(x0,1-x0,lwd=2,col="red") > lines(x0,-log(x0),lwd=2,col="darkgreen") > legend(0.5,4.5,legend=c("Richesse","Shannon","Simpson"), + col=c("blue","darkgreen","red"),lwd=c(2,2,2)) > > > ################################################### > ### chunk number 7: d6 > ################################################### > #line 326 "/bge/penel/verif_pedadoc/pedadoc/fichestd/tdr28//tdr28.rnw" > library(ade4) Attachement du package : 'ade4' The following object(s) are masked from 'package:base': within > data(bf88) > names(bf88) [1] "S1" "S2" "S3" "S4" "S5" "S6" > > > ################################################### > ### chunk number 8: d7 > ################################################### > #line 338 "/bge/penel/verif_pedadoc/pedadoc/fichestd/tdr28//tdr28.rnw" > richness <- function(x) { + res <- apply(x, 2, function(i) length(i[i!=0])-1) + return(res) + } > > shannon <- function(x){ + interm <- function(y) { + resi <- sapply(y, function(u) if(u != 0) + (- (u / sum(y)) * log(u / sum(y))) else 0) + return(sum(resi)) + } + res <- apply(x, 2, interm) + return(res) + } > > simpson <- function(x) { + res <- divc(x)[,1] + return(res) + } > > fun <- function(df, met) { + res <- lapply(df, met) + res <- as.data.frame(res) + rownames(res) <- names(df[[1]]) + return(res) + } > > > ################################################### > ### chunk number 9: d8 > ################################################### > #line 366 "/bge/penel/verif_pedadoc/pedadoc/fichestd/tdr28//tdr28.rnw" > resR <- fun(bf88, richness) > resS <- fun(bf88, shannon) > resGS <- fun(bf88, simpson) > > > ################################################### > ### chunk number 10: d9 > ################################################### > #line 373 "/bge/penel/verif_pedadoc/pedadoc/fichestd/tdr28//tdr28.rnw" > par(mfrow=c(2,2), mar=c(5,4,2,2)) > plot(1:6, resR[1,],type="b", ylim = range(resR), xlab = "Vegetation stade", ylab = "Richness") > lines(1:6, resR[2,],type="b", lty=2) > lines(1:6, resR[3,],type="b", lty=3) > lines(1:6, resR[4,],type="b", lty=4) > > plot(1:6, resS[1,],type="b", ylim = range(resS), xlab = "Vegetation stade", ylab = "Shannon index") > lines(1:6, resS[2,],type="b", lty=2) > lines(1:6, resS[3,],type="b", lty=3) > lines(1:6, resS[4,],type="b", lty=4) > > plot(1:6, resGS[1,],type="b", ylim = range(resGS), xlab = "Vegetation stade", ylab = "Simpson index") > lines(1:6, resGS[2,],type="b", lty=2) > lines(1:6, resGS[3,],type="b", lty=3) > lines(1:6, resGS[4,],type="b", lty=4) > > plot(1:8,1:8,type="n",main="Légende",font.main=1,xaxt="n",yaxt="n",xlab="",ylab="") > legend(1,7, c("Pologne","Bourgogne","Provence","Corse"), lty = 1:4, bty="n") > par(mfrow=c(1,1)) > > > ################################################### > ### chunk number 11: d10 > ################################################### > #line 401 "/bge/penel/verif_pedadoc/pedadoc/fichestd/tdr28//tdr28.rnw" > resGS[3] S3 Pol 0.9202537 Bur 0.9176710 Pro 0.7207461 Cor 0.9287534 > resS[3] S3 Pol 2.689902 Bur 2.773388 Pro 1.466502 Cor 2.836802 > apply(resS, 2, rank) S1 S2 S3 S4 S5 S6 Pol 1 1 2 2 4 4 Bur 3 3 3 4 3 3 Pro 2 2 1 1 2 2 Cor 4 4 4 3 1 1 > apply(resGS, 2, rank) S1 S2 S3 S4 S5 S6 Pol 1 1 3 2 4 4 Bur 3 3 2 4 3 3 Pro 2 2 1 1 1 2 Cor 4 4 4 3 2 1 > > > ################################################### > ### chunk number 12: d11 > ################################################### > #line 429 "/bge/penel/verif_pedadoc/pedadoc/fichestd/tdr28//tdr28.rnw" > uniformeS <- function(x) { + cat <- rep(1/x,x) + -sum(cat*log(cat)) + } > uniformeGS <- function(x) { + cat <- rep(1/x,x) + 1-sum(cat^2) + } > unifpreskS <- function(x) { + unif <- rep(1/x,x) + presk <- runif(x,min=-1/(2*x), max=1/(2*x)) + neopresk <- presk - mean(presk) + cat <- unif + neopresk + -sum(cat*log(cat)) + } > unifpreskGS <- function(x) { + unif <- rep(1/x,x) + presk <- runif(x,min=-1/(2*x), max=1/(2*x)) + neopresk <- presk - mean(presk) + cat <- unif + neopresk + 1-sum(cat^2) + } > domineS <- function(x) { + cat <- c((x-1)/x,rep((1-(x-1)/x)/(x-1),x-1)) + -sum(cat*log(cat)) + } > domineGS <- function(x) { + cat <- c((x-1)/x,rep((1-(x-1)/x)/(x-1),x-1)) + 1-sum(cat^2) + } > > > ################################################### > ### chunk number 13: d12 > ################################################### > #line 467 "/bge/penel/verif_pedadoc/pedadoc/fichestd/tdr28//tdr28.rnw" > eff <- 1:20 > resUS <- sapply(eff,uniformeS) > resUPS <- sapply(eff,unifpreskS) > resDS <- sapply(eff,domineS) > plot(eff, resUS, type="l", col="darkgreen",lwd=2, main="Indice de Shannon") > lines(eff, resUPS, col="darkgreen", lty=2, lwd=2) > lines(eff, resDS, col="darkgreen", lty=3, lwd=2) > legend(9,2, c("uniforme","presque uniforme", "une dominante"), lty = 1:3, lwd=2, col="darkgreen") > > > ################################################### > ### chunk number 14: d13 > ################################################### > #line 482 "/bge/penel/verif_pedadoc/pedadoc/fichestd/tdr28//tdr28.rnw" > eff <- 1:20 > resUGS <- sapply(eff,uniformeGS) > resUPGS <- sapply(eff,unifpreskGS) > resDGS <- sapply(eff,domineGS) > plot(eff, resUGS, type="l", col="red",lwd=2, main="Indice de Gini-Simpson") > lines(eff, resUPGS, col="red", lty=2, lwd=2) > lines(eff, resDGS, col="red", lty=3, lwd=2) > legend(8,0.7, c("uniforme", "presque uniforme","une dominante"), lty = 1:3, lwd=2, col="red") > > > ################################################### > ### chunk number 15: d14 > ################################################### > #line 573 "/bge/penel/verif_pedadoc/pedadoc/fichestd/tdr28//tdr28.rnw" > x <- matrix(rnorm(15), nrow=5) > x [,1] [,2] [,3] [1,] 0.0203960 0.21334604 0.4891940 [2,] -0.3089098 -0.09056461 -0.2689220 [3,] 1.1455077 -0.13068227 -0.5108231 [4,] 0.5001981 1.26485900 -1.5059334 [5,] 0.3193236 0.82054876 -0.3182391 > dist(x, diag=T, upper=T) 1 2 3 4 5 1 0.0000000 0.8806497 1.5441069 2.3057370 1.0535659 2 0.8806497 0.0000000 1.4749427 2.0054989 1.1078073 3 1.5441069 1.4749427 0.0000000 1.8314488 1.2745624 4 2.3057370 2.0054989 1.8314488 0.0000000 1.2809157 5 1.0535659 1.1078073 1.2745624 1.2809157 0.0000000 > sqrt(sum((x[1,]-x[2,])^2)) [1] 0.8806497 > > > ################################################### > ### chunk number 16: d15 > ################################################### > #line 614 "/bge/penel/verif_pedadoc/pedadoc/fichestd/tdr28//tdr28.rnw" > data(humDNAm) > names(humDNAm) [1] "distances" "samples" "structures" > > > ################################################### > ### chunk number 17: d16 > ################################################### > #line 625 "/bge/penel/verif_pedadoc/pedadoc/fichestd/tdr28//tdr28.rnw" > divc(humDNAm$samples, sqrt(humDNAm$distances)) -> res1 > > > ################################################### > ### chunk number 18: d17 > ################################################### > #line 630 "/bge/penel/verif_pedadoc/pedadoc/fichestd/tdr28//tdr28.rnw" > shannon(humDNAm$samples) -> res2 > simpson(humDNAm$samples) -> res3 > > > ################################################### > ### chunk number 19: d18 > ################################################### > #line 635 "/bge/penel/verif_pedadoc/pedadoc/fichestd/tdr28//tdr28.rnw" > restot <- cbind(res1,res2,res3) > colnames(restot)=c("Rao","Shannon","Simpson") > restot Rao Shannon Simpson oriental 0.43100189 1.2067368 0.5009452 tharu 0.48255042 1.5118191 0.6518536 wolof 0.65884298 1.7220666 0.7570248 peul 0.55952920 1.4346931 0.7134450 pima 0.06198035 0.3024839 0.1214412 maya 0.17092768 0.6142440 0.3243243 finnish 0.33280992 0.8989400 0.3659504 sicilian 0.61913580 1.6722281 0.6604938 israelij 0.67061144 1.5324659 0.7087442 israelia 0.64036818 1.6086954 0.6495726 > > > ################################################### > ### chunk number 20: d19 > ################################################### > #line 676 "/bge/penel/verif_pedadoc/pedadoc/fichestd/tdr28//tdr28.rnw" > interdist = sqrt(humDNAm$distances) > divcmax(interdist)$value [1] 2.565789 > VS <- divcmax(interdist)$vectors$sim > freqsim <- as.data.frame(VS) > rownames(freqsim) = rownames(humDNAm$samples) > t(freqsim) 1 2 6 7 8 9 VS 0.009860909 0.01754204 0.01422047 0.01380527 0.01484326 0.01920282 10 11 12 13 17 18 21 VS 0.01816483 0.02460037 0.01546606 0.01546606 0.01484326 0.01878763 0.01422047 22 23 27 28 29 31 34 VS 0.01795723 0.01505086 0.02003322 0.01380527 0.02999792 0.0219016 0.0219016 36 37 38 39 40 41 42 VS 0.01961802 0.02356238 0.01546606 0.01484326 0.01546606 0.01546606 0.01546606 43 44 45 46 47 48 49 VS 0.01858003 0.01754204 0.01546606 0.01505086 0.01359767 0.01525846 0.01546606 50 51 52 53 54 56 57 VS 0.01546606 0.01941042 0.01525846 0.01920282 0.02086361 0.01505086 0.02356238 64 65 66 67 68 69 71 VS 0.01920282 0.02252439 0.01484326 0.01858003 0.01546606 0.02314719 0.01941042 72 73 75 76 77 82 83 VS 0.01463567 0.02314719 0.01878763 0.01546606 0.01546606 0.02895993 0.02356238 95 VS 0.01546606 > > > ################################################### > ### chunk number 21: d20 > ################################################### > #line 691 "/bge/penel/verif_pedadoc/pedadoc/fichestd/tdr28//tdr28.rnw" > data(carni70) > names(carni70) [1] "tre" "tab" > > > > proc.time() utilisateur système écoulé 0.676 0.044 0.720