Re:

From: Pierre BADY (pierre.bady@univ-lyon1.fr)
Date: Tue Jun 01 2004 - 15:51:07 MEST


bonjour,

>Bonjour à tous,
>Je voudrais savoir si quelqu'un a déjà tenté de réaliser une analyse
>STATICO à l'aide de R ?

Oui, mais c'était avec une fonction 'maison' . normalement, elle
fonctionne, mais je ne l'ai pas testée sur beaucoup d'exemple et ça date un
peu. De plus, je ne suis pas tout à fait sûr du calcul des coordonnées,
mais je pense qu'on n'est pas très loin de la solution (c'est un appel aux
vrais stateux du forum).

donc, méfiance !!! ... ;o) )

"statico" <- function(X,Y,scannf=F,nf=2)
{
         if(!inherits(X,"ktab")) stop ("object 'ktab' expected")
         if(!inherits(Y,"ktab")) stop ("object 'ktab' expected")

    kcoi <- ktab.match2ktabs(Y,X)
    res <- pta(kcoi, scan = scannf , nf = nf)
    xblo <- X$blo ; nblo <- length(X$blo)
         nf <- res$nf
         indicablo <- X$TC[,1]

#--------------------------------------
# projections des lignes des deux ktab
#--------------------------------------
     normalise.w <- function(X, w) {
         f2 <- function(v) sqrt(sum(v * v * w)/sum(w))
         norm <- apply(X, 2, f2)
         X <- sweep(X, 2, norm, "/")
         return(X)
     }

     coX <- NULL
     coY <- NULL
     tnames <- tab.names.ktab(X)
     auxinames <- NULL
# la pta est un 'dudi', donc on peut utiliser les
# fonction 'suprow'et 'supcol'
     for(k in 1:nblo){

         w1 <- as.data.frame(suprow.default(res,t(X[[k]]) )$lisup)
         w1 <- normalise.w(w1,w=X$cw[indicablo==k])

         w2 <- as.data.frame(supcol.default(res,Y[[k]])$cosup)
         w2 <- normalise.w(w2,w=Y$cw[indicablo==k])

         coX <- rbind(coX,w1)
         coY <- rbind(coY,w2)
         auxinames <- c(auxinames,rep(tnames[k],ncol(X[[k]])))
         }
     auxinames <- paste(auxinames,X$TC[,2],sep=".")
     row.names(coY) <- row.names(coX) <- auxinames
     coX <- as.data.frame(coX)
     coY <- as.data.frame(coY)
     for(i in 1:nf){
         names(coX)[i] <- paste("Xls",i,sep="")
         names(coY)[i] <- paste("Yls",i,sep="")
         }
     res$Xl1 <- coX
     res$Yl1 <- coY
     res$TL2 <- X$TC
     return(res)
   }

# Xl1 coordonnées des stations pour les k tableaux de X

# Yl1 coordonnées des stations pour les k tableaux de Y

# TL2 facteurs associés à Xl1 et Yl1

>J'ai un petit problème : J'ai 2 séries de ktableaux ( 1 série "peuplement"
>[stations*espèces]*campagnes et une série environnement
>[stations*variables]*campagnes). J'ai réalisé mon couplage des 2 séries de
>ktableaux (par le fonction ktab.match2ktabs), puis j'ai fait une analyse
>triadique partielle sur le nouveau ktableau... mais dans les sorties je
>n'ai pas les coordonnées des lignes-stations communes aux 2 ktableaux...
>comment puis-je les obtenir ?

# p'tit exemple sur le méaudret

     data(meau)
      wit1 <- within.pca(meau$mil, meau$plan$dat, scan = FALSE, scal = "total")
      pcafau <- dudi.pca(meau$fau, scale = FALSE, scan = FALSE, nf = 2)
      wit2 <- within(pcafau, meau$plan$dat, scan = FALSE, nf = 2)
      kta1 <- ktab.within(wit1, colnames =
rep(c("S1","S2","S3","S4","S5","S6"), 4))
      kta2 <- ktab.within(wit2, colnames =
rep(c("S1","S2","S3","S4","S5","S6"), 4))
statico1<- statico(kta1,kta2,nf=4)

# la partie graphique

par(mfrow=c(2,2))
xlim1=c(min(c(statico1$Yl1[,1],statico1$Xl1[,1])),max(c(statico1$Yl1[,1],statico1$Xl1[,1])))
ylim1=c(min(c(statico1$Yl1[,2],statico1$Xl1[,2])),max(c(statico1$Yl1[,2],statico1$Xl1[,2])))
for(k in 1:4){
co1=statico1$Yl1[statico1$TL2[,1]==k,]
co2=statico1$Xl1[statico1$TL2[,1]==k,]
names(co1)=names(co2)
row.names(co1)=row.names(co2)=1:6
s.match(co1,co2,clab=0,sub=tab.names(kta1)[k],xlim=xlim1,ylim=ylim1)
#s.traject(co1,add.p=T,clab=0,csub=0)
#s.traject(co2,add.p=T,clab=0,csub=0)
s.label(co1,add.p=T,csub=0)
}

>merci
>Charline LAURENT

P.BADY

Pierre BADY
Université Claude Bernard Lyon 1
UMR CNRS 5023, LEHF
bat Alphonse Forel
43 boulevard du 11 novembre 1918
F-69622 VILLEURBANNE CEDEX
FRANCE
TEL : +33 (0)4 72 44 62 34
FAX : +33 (0)4 72 43 28 92
MEL : pierre.bady@univ-lyon1.fr
http://limnologie.univ-lyon1.fr
http://badgloup.ifrance.com



This archive was generated by hypermail 2b30 : Tue Sep 07 2004 - 13:30:56 MEST