11.07.2015 Views

Université Claude Bernard Lyon 1 - Kora

Université Claude Bernard Lyon 1 - Kora

Université Claude Bernard Lyon 1 - Kora

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

### Fonction Seuil ###seuil=function(objet, seuil=0.5) {objet$pot = vector(length = length(objet$HS))objet$pot[objet$HS>=seuil]=1return(objet)}### Minimum Area Predicted ###MPA=function(objet, percent=scan(nmax=1)) {cat('\n Quantile de la distribution de présence :\n')print(quantile(objet$HS[objet$pr==1],probs=c(0,0.01,0.05,0.1,0.25,0.5,0.75,1)))objet$MPA=rep(1,length(objet$HS))*(objet$HS>=(quantile(objet$HS[objet$pr==1], probs=percent)))return(objet)}### k-partition d'un tableau ###kpart=function(df, k=5) {sp=sample(1:nrow(df), nrow(df), rep=F)tr=trunc(nrow(df)/k)f1=function(i) {train=df[-sp[((i-1)*tr+1):(i*tr)],]test=df[sp[((i-1)*tr+1):(i*tr)],]return(list(train=train, test=test))}return(lapply(1:k,f1))}### Générique corrélation ###corr=function(x, ...)UseMethod("corr")### Corrélation du modèle de l'ENFA (Boyce et al. 2002) ###corr.ENFA=function(x, presence=ncol(x$df), k=5, nf=x$nf, ...) {par(mfrow=rev(n2mfrow(k)))kdf=kpart(x$df, k)f1=function(i) {hsp=predict(x, newdata=kdf[[i]]$test[,-presence])}quant=quantile(hsp[kdf[[i]]$test[,presence]==1],probs=c(0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1))quant[1]=0quant[11]=1G=hist(hsp, br=quant, plot=F)H=hist(hsp[kdf[[i]]$test[,presence]==1], br=quant, plot=F)ratio=(H$counts/sum(H$counts))/(G$counts/sum(G$counts))plot((1:10)/10,ratio, xlab='HS', ylab='Utilisation relative',type='h')A=cor.test(1:10, ratio, method='spearman')B=cor.test(1:10, ratio, method='kendall')C=cor.test(1:10, ratio)abline(h=1)return(list(A$est, A$p.value, B$est, B$p.value, C$est,C$p.value))M=matrix(unlist(lapply(1:k,f1)), nrow=k, byrow=T,dimnames=list(1:k,c('S.est.cor','S.p.value','K.est.cor','K.p.value','P.est.cor','P.p.value')))par(mfrow=c(1,1))36

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!