===== Torus ===== Função torus de K. Harms, com pequenas modificações de Ale dez de 2008 > torusonesp=function(species,habitat,allabund,plotdim=c(320,320),gridsize=20) { plotdimqx=plotdim[1]/gridsize # Calculates no. of x-axis quadrats of plot. plotdimqy=plotdim[2]/gridsize # Calculates no. of y-axis quadrats of plot. hab=unique(habitat) num.habs=length(hab) # Determines tot. no. of habitat types. habmat=matrix(habitat,plotdimqy,plotdimqx,byrow=F) GrLsEq=matrix(0,1,num.habs*4) # Creates empty matrix for output. rownames(GrLsEq)=species # Names single row of output matrix. for(i in 1:num.habs) # Creates names for columns of output matrix. { if(i==1) cols=c(paste("N.Hab.",hab[i],sep=""), paste("Gr.Hab.",hab[i],sep=""), paste("Ls.Hab.",hab[i],sep=""), paste("Eq.Hab.",hab[i],sep="")) if(i>1) cols=c(cols, paste("N.Hab.",hab[i],sep=""), paste("Gr.Hab.",hab[i],sep=""), paste("Ls.Hab.",hab[i],sep=""), paste("Eq.Hab.",hab[i],sep="")) } colnames(GrLsEq)=cols # Names columns of output matrix. ## CALCULATIONS FOR OBSERVED RELATIVE DENSITIES ON THE TRUE HABITAT MAP spmat=matrix(allabund[species,],plotdimqy,plotdimqx,byrow=F) # Fills a matrix, with no. rows = plotdimqy and no. columns = plotdimqx, with the indiv. counts per quadrat of one species. tot=numeric() # Creates empty vector for tot. no. stems per quadrat. len=length(allabund[1,]) # Determines the tot. no. of quadrats. ###SERÁ QUE PRECISA TUDO ISSO!! ###for(i in 1:len) # Determines the tot. no. of stems, of all spp., in each quadrat. ## { ### tot[i]=sum(allabund[,i]) ## } tot=apply(allabund,2,sum) ## assim fica melhor, sem looping (ale dez 2008) totmat=matrix(tot[],plotdimqy,plotdimqx,byrow=F) # Converts "tot" to a matrix, with no. rows = plotdimqy and no. columns = plotdimqx. spstcnthab=numeric() # Creates empty vector for stem counts per sp. per habitat. totstcnthab=numeric() # Creates empty vector for tot. stem counts per habitat. for(i in 1:num.habs) { totstcnthab[i]=sum(totmat[habmat==unique(habitat)[i]]) # Determines tot. no. stems per habitat of the true map. spstcnthab[i]=sum(spmat[habmat==unique(habitat)[i]]) # Determines tot. no. stems for focal sp. per habitat of the true map. } spprophab=spstcnthab/totstcnthab # Calculates observed relative stem density of focal sp. per habitat of the true map. # CALCULATIONS FOR RELATIVE DENSITIES ON THE TORUS-BASED HABITAT MAPS for(x in 0:(plotdimqx-1)) # Opens "for loop" through all 20-m translations along x-axis. { for(y in 0:(plotdimqy-1)) # Opens "for loop" through all 20-m translations along y-axis. { newhab=matrix(0,plotdimqy,plotdimqx) # Creates empty matrix of quadrats' habitat designations. # The following "if" statements create the x,y torus-translation of the habitat map. if(y==0 & x==0) newhab=habmat if(y==0 & x>0) newhab=habmat[c(1:plotdimqy),c((plotdimqx-x+1):plotdimqx,1:(plotdimqx-x))] if(x==0 & y>0) newhab=habmat[c((plotdimqy-y+1):plotdimqy,1:(plotdimqy-y)),c(1:plotdimqx)] if(x>0 & y>0) newhab=habmat[c((plotdimqy-y+1):plotdimqy,1:(plotdimqy-y)),c((plotdimqx-x+1):plotdimqx,1:(plotdimqx-x))] Torspstcnthab=numeric() # Creates empty vector for stem counts per sp. per habitat in torus-based maps. Tortotstcnthab=numeric() # Creates empty vector for tot. stem counts per habitat in torus-based maps. for(i in 1:num.habs) { Tortotstcnthab[i]=sum(totmat[newhab==unique(habitat)[i]]) # Determines tot. no. stems per habitat of the focal torus-based map. Torspstcnthab[i]=sum(spmat[newhab==unique(habitat)[i]]) # Determines tot. no. stems for focal sp. per habitat of the focal torus-based map. } Torspprophab=Torspstcnthab/Tortotstcnthab # Calculates relative stem density of focal sp. per habitat of the focal torus-based map. for(i in 1:num.habs) { if(spprophab[i]>Torspprophab[i]) # If rel. dens. of focal sp. in focal habitat of true map is greater than rel. dens. of focal sp. in focal habitat of torus-based map, then add one to "greater than" count. GrLsEq[1,(4*i)-2]=GrLsEq[1,(4*i)-2]+1 if(spprophab[i] ** essa função foi usada em dez de 2008 para os resultados a seguir ** > torusonesp("Calobr", solo$soil,allspp)->res > res N.Hab.neo Gr.Hab.neo Ls.Hab.neo Eq.Hab.neo N.Hab.trans Gr.Hab.trans Calobr 135 244 11 1 43 22 Ls.Hab.trans Eq.Hab.trans N.Hab.esp.aren Gr.Hab.esp.aren Ls.Hab.esp.aren Calobr 233 1 226 58 197 Eq.Hab.esp.aren N.Hab.esp.hist Gr.Hab.esp.hist Ls.Hab.esp.hist Calobr 1 25 116 139 Eq.Hab.esp.hist Calobr 1 Interpretação: - N.Hab.neo: primeira coluna, no. de Calophyllum no habitat Neossolo = 135 indivíduos - Gr.Hab.neo: número de simulações onde a densidade relativa observada de Calophyllum no habitat neossolo foi maior que as simulações (Ls.Hab.neo = menor, Eq.Hab neo= igual)... ** Para calcular a significancia deve dividir pelo no. de simulações torus (256), note que o número de indivíduos observados nos habitats ficará sem sentido (N.Hab.*)! ** > res/256 N.Hab.neo Gr.Hab.neo Ls.Hab.neo Eq.Hab.neo N.Hab.trans Gr.Hab.trans Calobr 0.5273438 0.953125 0.04296875 0.00390625 0.1679688 0.0859375 Ls.Hab.trans Eq.Hab.trans N.Hab.esp.aren Gr.Hab.esp.aren Ls.Hab.esp.aren Calobr 0.9101562 0.00390625 0.8828125 0.2265625 0.7695312 Eq.Hab.esp.aren N.Hab.esp.hist Gr.Hab.esp.hist Ls.Hab.esp.hist Calobr 0.00390625 0.09765625 0.453125 0.5429688 Eq.Hab.esp.hist Calobr 0.00390625 Interpretação: - Gr.Hab.neo = 0.953, significa que o valor observado de densidade relativa do Calophyllum no habitat neossolo é em mais de 95% das vezes maior do que a simulação torus! Ou seja sua associação a esse habitat é significativamente positiva **densidade de Calophyllum observada** > tapply(calo, habitat,sum) esp.aren esp.hist neo trans 226 25 135 43 ** porcentagem relativa de Calophullum por habitat** > tapply(calo, habitat,sum)/sum(calo) esp.aren esp.hist neo trans 0.52680653 0.05827506 0.31468531 0.10023310 **densidade de todas as espécies por tipo de solo** > apply(allspp,2,sum)->totalparc > tapply(totalparc, habitat,sum) esp.aren esp.hist neo trans 10409 1128 4608 2345 ** densidade relativa de Calophyllum por habitat** > tapply(calo, habitat,sum)/tapply(totalparc, habitat,sum) esp.aren esp.hist neo trans 0.02171198 0.02216312 0.02929688 0.01833689 *** a densidade relativa de Calophyllum média é de 2,3 % dos indivíduos, mas no Neossolo é quase 3% dos indivíduos** ** ou seja a densidade relativa de Calophyllum é cerca de 30% maior no neossolo em comparacão com a sua média em todos os habitats** ** Vamos ver com o K. Harms e Valencia et al. apresentaram os resultados deles, para tirar alguma idéia de como apresentá-los ** ===== Torus 2 ===== Modifiquei a função para fazer dois ciclos de simulação, o primeiro iniciando com a configuração original do habitat e o segundo com o habitat original transposto (mantem a estrutura espacial, mas invertido) **Nova Função** torusonesp=function(species,habitat,allabund,plotdim=c(320,320),gridsize=20) { contar=0 plotdimqx=plotdim[1]/gridsize # Calculates no. of x-axis quadrats of plot. plotdimqy=plotdim[2]/gridsize # Calculates no. of y-axis quadrats of plot. hab=unique(habitat) num.habs=length(hab) # Determines tot. no. of habitat types. habmat=matrix(habitat,plotdimqy,plotdimqx,byrow=F) GrLsEq=matrix(0,1,num.habs*4) # Creates empty matrix for output. rownames(GrLsEq)=species # Names single row of output matrix. for(i in 1:num.habs) # Creates names for columns of output matrix. { if(i==1) cols=c(paste("N.Hab.",hab[i],sep=""), paste("Gr.Hab.",hab[i],sep=""), paste("Ls.Hab.",hab[i],sep=""), paste("Eq.Hab.",hab[i],sep="")) if(i>1) cols=c(cols, paste("N.Hab.",hab[i],sep=""), paste("Gr.Hab.",hab[i],sep=""), paste("Ls.Hab.",hab[i],sep=""), paste("Eq.Hab.",hab[i],sep="")) } colnames(GrLsEq)=cols # Names columns of output matrix. # CALCULATIONS FOR OBSERVED RELATIVE DENSITIES ON THE TRUE HABITAT MAP spmat=matrix(allabund[species,],plotdimqy,plotdimqx,byrow=F) # Fills a matrix, with no. rows = plotdimqy and no. columns = plotdimqx, with the indiv. counts per quadrat of one species. tot=numeric() # Creates empty vector for tot. no. stems per quadrat. len=length(allabund[1,]) # Determines the tot. no. of quadrats. ###SERÁ QUE PRECISA TUDO ISSO!! ###for(i in 1:len) # Determines the tot. no. of stems, of all spp., in each quadrat. ## { ### tot[i]=sum(allabund[,i]) ## } tot=apply(allabund,2,sum) ## assim fica melhor, sem looping (ale dez 2008) totmat=matrix(tot[],plotdimqy,plotdimqx,byrow=F) # Converts "tot" to a matrix, with no. rows = plotdimqy and no. columns = plotdimqx. spstcnthab=numeric() # Creates empty vector for stem counts per sp. per habitat. totstcnthab=numeric() # Creates empty vector for tot. stem counts per habitat. for(i in 1:num.habs) { totstcnthab[i]=sum(totmat[habmat==unique(habitat)[i]]) # Determines tot. no. stems per habitat of the true map. spstcnthab[i]=sum(spmat[habmat==unique(habitat)[i]]) # Determines tot. no. stems for focal sp. per habitat of the true map. } spprophab=spstcnthab/totstcnthab # Calculates observed relative stem density of focal sp. per habitat of the true map. # CALCULATIONS FOR RELATIVE DENSITIES ON THE TORUS-BASED HABITAT MAPS for (ciclo in 1:2) { if(ciclo==1) habmat=habmat if(ciclo==2) habmat=t(habmat) for(x in 0:(plotdimqx-1)) # Opens "for loop" through all 20-m translations along x-axis. { for(y in 0:(plotdimqy-1)) # Opens "for loop" through all 20-m translations along y-axis. { contar=contar+1 newhab=matrix(0,plotdimqy,plotdimqx) # Creates empty matrix of quadrats' habitat designations. # The following "if" statements create the x,y torus-translation of the habitat map. if(y==0 & x==0) newhab=habmat if(y==0 & x>0) newhab=habmat[c(1:plotdimqy),c((plotdimqx-x+1):plotdimqx,1:(plotdimqx-x))] if(x==0 & y>0) newhab=habmat[c((plotdimqy-y+1):plotdimqy,1:(plotdimqy-y)),c(1:plotdimqx)] if(x>0 & y>0) newhab=habmat[c((plotdimqy-y+1):plotdimqy,1:(plotdimqy-y)),c((plotdimqx-x+1):plotdimqx,1:(plotdimqx-x))] Torspstcnthab=numeric() # Creates empty vector for stem counts per sp. per habitat in torus-based maps. Tortotstcnthab=numeric() # Creates empty vector for tot. stem counts per habitat in torus-based maps. for(i in 1:num.habs) { Tortotstcnthab[i]=sum(totmat[newhab==unique(habitat)[i]]) # Determines tot. no. stems per habitat of the focal torus-based map. Torspstcnthab[i]=sum(spmat[newhab==unique(habitat)[i]]) # Determines tot. no. stems for focal sp. per habitat of the focal torus-based map. } Torspprophab=Torspstcnthab/Tortotstcnthab # Calculates relative stem density of focal sp. per habitat of the focal torus-based map. for(i in 1:num.habs) { if(spprophab[i]>Torspprophab[i]) # If rel. dens. of focal sp. in focal habitat of true map is greater than rel. dens. of focal sp. in focal habitat of torus-based map, then add one to "greater than" count. GrLsEq[1,(4*i)-2]=GrLsEq[1,(4*i)-2]+1 if(spprophab[i] >torusonesp("Calobr",habitat,allspp) ciclo no.= 1 simulações = 256 ciclo no.= 2 simulações = 512 N.Hab.neo Gr.Hab.neo Ls.Hab.neo Eq.Hab.neo N.Hab.trans Gr.Hab.trans Ls.Hab.trans Eq.Hab.trans N.Hab.esp.aren Calobr 135 494 17 1 43 46 465 1 226 Gr.Hab.esp.aren Ls.Hab.esp.aren Eq.Hab.esp.aren N.Hab.esp.hist Gr.Hab.esp.hist Ls.Hab.esp.hist Eq.Hab.esp.hist Calobr 97 414 1 25 236 275 1 **Os resultados permanencem consistentes com a primeira simulação, não houve grande diferença, apenas aumentou um pouco a significancia da associação com o neossolo.**