1 Pré-Análises
1.0.1 Organização básica
dev.off()
rm(list=ls(all=TRUE))
cat("\014")
#limpa a memoria, o console e apaga os graficos, se houver algumInstalando os pacotes necessários
install.packages("openxlsx") #importa arquivos do excel
install.packages("moments") #calcula assimetria e curtose dos dados
install.packages("matrixStats") #fornece funções rápidas para a estatística de matrizes
install.packages("gt") #ferramenta para criação de tabelas bonitas e personalizáveis
install.packages("dplyer")
install.packages("plyr")Definindo o diretório de trabalho
getwd()
setwd("C:/Seu/Diretório/De/Trabalho")
dir <- (getwd())Carregado bases de dados dos pontos fixos de amostragem (fixos.xlsx) e dos pontos ao entorno da ReBio (entorno.xlsx)
library(openxlsx)
fixos <- read.xlsx("D:/Elvio/OneDrive/MSS/_Zoo-Rebio/fixos.xlsx",
rowNames = T,
colNames = T,
sheet = "ponto_l")
entorno <- read.xlsx("D:/Elvio/OneDrive/MSS/_Zoo-Rebio/entorno.xlsx",
rowNames = T,
colNames = T,
sheet = "ponto_l")Aqui são duas bases de dados (pontos fixos 1 e pontos ao entorno 2 da ReBio) que precisam ser importadas e mescladas (Tabela 1.1. Os dados são densidade em no. de indivídos por litro (no.ind/L) (ver Gouveia et al. (2017), Gouveia (2014) e Lima (2022)).
1.1 Particionando a matriz
Deletando colunas e linhas, e excluindo all-zeros e valores N/A e o ponto 20. *Lecane mono* e o Site 20 foram deixados errados de propósito para usar os códigos de deletar uma coluna ou linha, por nome.
entorno <- subset(entorno, select = -Lec.mono) #escolhendo uma coluna pelo nome
#Deletando linhas específicas
del_rows <- c("ST20") #site fake
del_rows
m_part <- entorno[!(row.names(entorno) %in% c(del_rows)),]
m_part
sum <- colSums(m_part)
sum
zero_sum_cols <- names(which(colSums(m_part) == 0))
zero_sum_cols #nomes das espécies zeradas
m_part2 <- m_part[(colSums(m_part) != 0)] #em != a exclamação inverte o sentido
zero_sum_cols2 <- names(which(colSums(m_part2) == 0))
zero_sum_cols2 #nomes das espécies zeradas
sum<-colSums(m_part2)
sum
entorno <- m_part2
#Separando a matriz em partes
fixos_ca <- fixos[1:18,]
names(which(colSums(fixos_ca) == 0)) #all-zero columns
fixos_ca <- fixos_ca[, colSums(fixos_ca != 0) > 0]
fixos_bb <- fixos[19:36,]
names(which(colSums(fixos_bb) == 0)) #all-zero columns
fixos_bb <- fixos_bb[, colSums(fixos_bb != 0) > 0]
library(dplyr)
entorno_re <- filter(entorno, grepl("RE", row.names(entorno)))
names(which(colSums(entorno_re) == 0)) #all-zero columns
entorno_re <- entorno_re[, colSums(entorno_re != 0) > 0]
entorno_en <- filter(entorno, grepl("EN", row.names(entorno)))
names(which(colSums(entorno_en) == 0)) #all-zero columns
entorno_en <- entorno_en[, colSums(entorno_en != 0) > 0]## [1] "ST20"
## Rotaria.sp Rot.neptunia Dis.aculeata Lep.ovalis Lec.quadridentata Lec.cornuta Lec.luna Lec.lunaris Lec.bulla
## EN08 1.0666667 1.0666667 0.5333333 0.5333333 0.0000000 0.5333333 0.000000 0.5333333 0.0000000
## EN09 0.5333333 0.0000000 1.6000000 0.5333333 0.0000000 0.0000000 0.000000 0.0000000 2.1333333
## EN10 1.0666667 0.0000000 2.6666667 0.0000000 0.0000000 0.0000000 0.000000 0.5333333 1.0666667
## RE19 2.1333333 0.0000000 1.0666667 0.0000000 0.0000000 0.0000000 0.000000 0.0000000 1.0666667
## EN11 0.5333333 0.5333333 0.0000000 0.0000000 0.0000000 0.0000000 0.000000 0.0000000 72.0000000
## EN12 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.5333333 0.000000 0.0000000 0.5333333
## EN13 0.0000000 0.0000000 0.0000000 0.5333333 0.0000000 0.0000000 0.000000 0.0000000 1.0666667
## EN15 2.6666667 0.0000000 0.0000000 0.0000000 0.0000000 2.6666667 0.000000 0.0000000 12.8000000
## EN16 10.1333333 0.0000000 0.0000000 0.0000000 0.0000000 0.5333333 0.000000 1.6000000 0.0000000
## EN14 9.0666667 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 2.666667 0.5333333 0.0000000
## EN17 10.1333333 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.000000 0.0000000 0.0000000
## RE18 3.7333333 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.000000 0.0000000 2.1333333
## RE07 24.5333333 0.0000000 0.0000000 0.0000000 0.5333333 0.0000000 0.000000 2.6666667 0.0000000
## Euc.dilatata Nauplii Copepodite Lec.curvicornis Bea.eudactylota Lec.leontina Lec.monostyla Chy.sphaericus
## EN08 0.0000000 0.0000000 0.0000000 0.0 0.0000000 0.000000 0.0000000 0.0000000
## EN09 0.5333333 0.5333333 0.5333333 0.0 0.0000000 0.000000 0.0000000 0.0000000
## EN10 0.5333333 0.0000000 0.0000000 1.6 0.0000000 1.066667 0.5333333 0.5333333
## RE19 0.0000000 0.5333333 0.5333333 0.0 0.0000000 0.000000 0.0000000 0.0000000
## EN11 0.0000000 0.0000000 0.0000000 1.6 0.0000000 0.000000 0.0000000 0.0000000
## EN12 0.0000000 38.9333333 3.7333333 0.0 0.0000000 0.000000 0.0000000 1.0666667
## EN13 0.0000000 0.5333333 0.0000000 0.0 0.0000000 0.000000 0.0000000 0.0000000
## EN15 0.0000000 70.9333333 2.1333333 0.0 0.5333333 1.600000 0.5333333 2.1333333
## EN16 0.0000000 49.6000000 2.6666667 0.0 0.0000000 0.000000 0.0000000 0.0000000
## EN14 0.0000000 8.0000000 1.6000000 0.0 0.0000000 0.000000 0.0000000 0.0000000
## EN17 0.0000000 1.6000000 1.0666667 0.0 0.0000000 0.000000 0.0000000 0.0000000
## RE18 0.0000000 0.0000000 1.6000000 0.0 0.0000000 0.000000 0.0000000 0.0000000
## RE07 0.0000000 5.8666667 0.0000000 0.0 0.0000000 0.000000 0.0000000 0.0000000
## Pla.quadricornis Bra.falcatus Lec.furcata Lep.patella Lec.hornemanni Dia.birgei Lec.hastata Mac.subquadratus
## EN08 0.0000000 0.0 0.0000000 0.0000000 0.000000 0.0000000 0.0 0.0000000
## EN09 0.0000000 0.0 0.0000000 0.0000000 0.000000 0.0000000 0.0 0.0000000
## EN10 0.5333333 0.0 0.0000000 0.0000000 0.000000 0.0000000 0.0 0.0000000
## RE19 0.0000000 1.6 0.5333333 0.5333333 0.000000 0.0000000 0.0 0.0000000
## EN11 0.0000000 0.0 10.6666667 53.8666667 3.733333 1.6000000 1.6 0.5333333
## EN12 0.0000000 24.0 0.0000000 0.0000000 0.000000 0.0000000 0.0 0.0000000
## EN13 0.0000000 0.0 0.0000000 1.0666667 0.000000 0.0000000 0.0 0.0000000
## EN15 0.0000000 0.0 1.6000000 0.5333333 0.000000 0.0000000 0.0 0.0000000
## EN16 0.0000000 0.0 0.0000000 0.0000000 0.000000 0.0000000 0.0 0.0000000
## EN14 0.0000000 0.0 0.0000000 0.0000000 0.000000 0.5333333 0.0 0.0000000
## EN17 0.0000000 0.0 0.0000000 2.6666667 0.000000 0.0000000 0.0 0.0000000
## RE18 0.0000000 0.0 0.0000000 1.6000000 0.000000 0.0000000 0.0 0.0000000
## RE07 0.0000000 0.0 0.0000000 3.7333333 0.000000 0.0000000 0.0 0.0000000
## Alonella.sp Bra.quadridentatus Pol.vulgaris Pol.bicerca Dicranop.sp Cyclopoida Asc.saltans Moi.minuta Alo.hamulata
## EN08 0.0 0.00000 0.0 0.00000 0.0 0.0000000 0.000000 0.0000000 0.0000000
## EN09 0.0 0.00000 0.0 0.00000 0.0 0.0000000 0.000000 0.0000000 0.0000000
## EN10 0.0 0.00000 0.0 0.00000 0.0 0.0000000 0.000000 0.0000000 0.0000000
## RE19 0.0 0.00000 0.0 0.00000 0.0 0.0000000 0.000000 0.0000000 0.0000000
## EN11 0.0 0.00000 0.0 0.00000 0.0 0.0000000 0.000000 0.0000000 0.0000000
## EN12 1.6 10.13333 19.2 31.46667 68.8 1.0666667 1.066667 0.5333333 0.5333333
## EN13 1.6 0.00000 0.0 0.00000 0.0 0.5333333 0.000000 0.0000000 0.0000000
## EN15 0.0 0.00000 0.0 0.00000 0.0 0.0000000 0.000000 0.0000000 0.0000000
## EN16 0.0 0.00000 0.0 26.66667 0.0 1.6000000 0.000000 2.1333333 0.0000000
## EN14 0.0 0.00000 0.0 0.00000 0.0 1.0666667 0.000000 0.0000000 0.5333333
## EN17 0.0 0.00000 0.0 0.00000 0.0 0.0000000 0.000000 0.0000000 0.0000000
## RE18 0.0 0.00000 0.0 0.00000 0.0 0.0000000 0.000000 0.0000000 0.0000000
## RE07 0.0 0.00000 0.0 0.00000 0.0 0.0000000 0.000000 0.0000000 0.0000000
## Mac.laticornis Lec.crepida Mac.mira Pro.similis Tri.tetractis Alo.pulchella Dia.spinulosum Macrothrix.sp
## EN08 0.000000 0.0000000 0.000000 0.0000000 0.0 0.000000 0.0 0.0
## EN09 0.000000 0.0000000 0.000000 0.0000000 0.0 0.000000 0.0 0.0
## EN10 0.000000 0.0000000 0.000000 0.0000000 0.0 0.000000 0.0 0.0
## RE19 0.000000 0.0000000 0.000000 0.0000000 0.0 0.000000 0.0 0.0
## EN11 0.000000 0.0000000 0.000000 0.0000000 0.0 0.000000 0.0 0.0
## EN12 1.066667 0.0000000 0.000000 0.0000000 0.0 0.000000 0.0 0.0
## EN13 0.000000 0.5333333 0.000000 0.0000000 0.0 0.000000 0.0 0.0
## EN15 1.600000 0.0000000 2.133333 0.5333333 1.6 3.733333 1.6 1.6
## EN16 0.000000 0.0000000 0.000000 0.0000000 0.0 0.000000 0.0 0.0
## EN14 0.000000 0.0000000 0.000000 0.0000000 0.0 0.000000 0.0 0.0
## EN17 0.000000 0.0000000 0.000000 0.0000000 0.0 0.000000 0.0 0.0
## RE18 0.000000 0.0000000 0.000000 0.0000000 0.0 0.000000 0.0 0.0
## RE07 0.000000 0.0000000 0.000000 0.0000000 0.0 0.000000 0.0 0.0
## Chydorus.sp Pla.patulus Ily.spinifer Dun.odontoplax Trichocerca.sp
## EN08 0.000000 0.000000 0.000000 0.0000000 0.0
## EN09 0.000000 0.000000 0.000000 0.0000000 0.0
## EN10 0.000000 0.000000 0.000000 0.0000000 0.0
## RE19 0.000000 0.000000 0.000000 0.0000000 0.0
## EN11 0.000000 0.000000 0.000000 0.0000000 0.0
## EN12 0.000000 0.000000 0.000000 0.0000000 0.0
## EN13 0.000000 0.000000 0.000000 0.0000000 0.0
## EN15 1.066667 0.000000 0.000000 0.0000000 0.0
## EN16 0.000000 4.266667 0.000000 0.0000000 0.0
## EN14 0.000000 0.000000 3.733333 0.0000000 0.0
## EN17 0.000000 0.000000 0.000000 0.5333333 0.0
## RE18 0.000000 0.000000 0.000000 0.0000000 0.0
## RE07 0.000000 0.000000 0.000000 0.0000000 1.6
## Rotaria.sp Rot.neptunia Dis.aculeata Lep.ovalis Lec.quadridentata Lec.cornuta
## 65.6000000 1.6000000 5.8666667 1.6000000 0.5333333 4.2666667
## Lec.luna Lec.lunaris Lec.bulla Euc.dilatata Nauplii Copepodite
## 2.6666667 5.8666667 92.8000000 1.0666667 176.5333333 13.8666667
## Lec.curvicornis Bea.eudactylota Lec.leontina Lec.monostyla Chy.sphaericus Pla.quadricornis
## 3.2000000 0.5333333 2.6666667 1.0666667 3.7333333 0.5333333
## Bra.falcatus Lec.furcata Lep.patella Lec.hornemanni Dia.birgei Lec.hastata
## 25.6000000 12.8000000 64.0000000 3.7333333 2.1333333 1.6000000
## Mac.subquadratus Alonella.sp Bra.quadridentatus Pol.vulgaris Pol.bicerca Dicranop.sp
## 0.5333333 3.2000000 10.1333333 19.2000000 58.1333333 68.8000000
## Cyclopoida Asc.saltans Moi.minuta Alo.hamulata Mac.laticornis Lec.crepida
## 4.2666667 1.0666667 2.6666667 1.0666667 2.6666667 0.5333333
## Mac.mira Pro.similis Tri.tetractis Alo.pulchella Dia.spinulosum Macrothrix.sp
## 2.1333333 0.5333333 1.6000000 3.7333333 1.6000000 1.6000000
## Chydorus.sp Pla.patulus Ily.spinifer Dun.odontoplax Trichocerca.sp
## 1.0666667 4.2666667 3.7333333 0.5333333 1.6000000
## character(0)
## character(0)
## Rotaria.sp Rot.neptunia Dis.aculeata Lep.ovalis Lec.quadridentata Lec.cornuta
## 65.6000000 1.6000000 5.8666667 1.6000000 0.5333333 4.2666667
## Lec.luna Lec.lunaris Lec.bulla Euc.dilatata Nauplii Copepodite
## 2.6666667 5.8666667 92.8000000 1.0666667 176.5333333 13.8666667
## Lec.curvicornis Bea.eudactylota Lec.leontina Lec.monostyla Chy.sphaericus Pla.quadricornis
## 3.2000000 0.5333333 2.6666667 1.0666667 3.7333333 0.5333333
## Bra.falcatus Lec.furcata Lep.patella Lec.hornemanni Dia.birgei Lec.hastata
## 25.6000000 12.8000000 64.0000000 3.7333333 2.1333333 1.6000000
## Mac.subquadratus Alonella.sp Bra.quadridentatus Pol.vulgaris Pol.bicerca Dicranop.sp
## 0.5333333 3.2000000 10.1333333 19.2000000 58.1333333 68.8000000
## Cyclopoida Asc.saltans Moi.minuta Alo.hamulata Mac.laticornis Lec.crepida
## 4.2666667 1.0666667 2.6666667 1.0666667 2.6666667 0.5333333
## Mac.mira Pro.similis Tri.tetractis Alo.pulchella Dia.spinulosum Macrothrix.sp
## 2.1333333 0.5333333 1.6000000 3.7333333 1.6000000 1.6000000
## Chydorus.sp Pla.patulus Ily.spinifer Dun.odontoplax Trichocerca.sp
## 1.0666667 4.2666667 3.7333333 0.5333333 1.6000000
## [1] "Lec.curvicornis" "Notholca.sp" "Ascomorpha.sp" "Pom.sulcata" "Harpacticoida" "Epi.senta"
## [1] "Trichocerca.sp" "Lec.furcata" "Col.geophila" "Lep.dactyliseta" "Bra.calyciflorus" "Bra.caudatus"
## [7] "Pla.patulus" "Lec.elasma" "Pla.quadricornis" "Ker.tropica" "Ker.lenzi" "Alo.dadayi"
## [13] "Mac.collinsi" "Paracyclops.sp" "Asc.ecaudis" "Lep.ovalis" "Polyarthra.sp" "Bra.havanaensis"
## [19] "Hexarthra.sp" "Lec.hastata" "Tri.tetractis" "Ker.serrulata" "Notodiaptomus.sp" "Bra.falcatus"
## [25] "Fil.longiseta" "Myt.crassipes" "Lep.patella" "Euchlanis.sp" "Lec.monostyla" "Lec.ligona"
## [1] "Rot.neptunia" "Lep.ovalis" "Lec.cornuta" "Lec.luna" "Euc.dilatata"
## [6] "Lec.curvicornis" "Bea.eudactylota" "Lec.leontina" "Lec.monostyla" "Chy.sphaericus"
## [11] "Pla.quadricornis" "Lec.hornemanni" "Dia.birgei" "Lec.hastata" "Mac.subquadratus"
## [16] "Alonella.sp" "Bra.quadridentatus" "Pol.vulgaris" "Pol.bicerca" "Dicranop.sp"
## [21] "Cyclopoida" "Asc.saltans" "Moi.minuta" "Alo.hamulata" "Mac.laticornis"
## [26] "Lec.crepida" "Mac.mira" "Pro.similis" "Tri.tetractis" "Alo.pulchella"
## [31] "Dia.spinulosum" "Macrothrix.sp" "Chydorus.sp" "Pla.patulus" "Ily.spinifer"
## [36] "Dun.odontoplax"
## [1] "Lec.quadridentata" "Trichocerca.sp"
| Rio | n=315 | ||||
|---|---|---|---|---|---|
| CA | Coleta | Datas | Ponto | Pote | Lâmina |
| BB | 1 | 26-02-2011 | -P1 | . | . |
| . | 2 | 30-04-2011 | -P2 | . | . |
| . | 3 | 30-06-2011 | -P3 | .1 | . |
| . | 4 | 01-09-2011 | . | .2 | . |
| . | 5 | 03-11-2011 | . | .3 | -I |
| . | 6 | 18-01-2012 | . | . | -II |
| . | . | . | . | . | -III |
| 2 | x 12 | . | x 36 | x 108 | = 324 |
1.2 Merging bases de dados fixos e entorno
1.2.1 Taxa compartilhados pelas duas bases de dados
Nos códigos abaixo, a função intersect() é usada para se obter os nomes de colunas em comum entre fixo e entorno, que são guardados em um vetor. Esses vetores são repassados nos outros argumentos subsequentes. O propósito dos argumentos setdiff() e \<- 0 não é preencher células vazias com zeros, mas adicionar novas colunas em cada data frame com nomes de colunas que estão presentes em um data frame ms não em outro. Se uma coluna está faltando em um data frame, ela será adicionada aquele data frame com o termo NA ou NULL. Para substituir os valores rotulados de NA ou NULL usa-se a função merged[is.na(merged)] <- 0. Ver Apêndices.
shared_spp <- intersect(names(fixos), names(entorno)) #get the common column names
shared_spp
fixos_only <- setdiff(names(fixos), names(entorno))
fixos_only
entorno_only <- setdiff(names(entorno), names(fixos))
entorno_only
Riqueza <- length(shared_spp) + length(fixos_only) + length(entorno_only)
Riqueza## [1] "Lec.leontina" "Lec.bulla" "Lec.cornuta" "Lec.curvicornis" "Trichocerca.sp"
## [6] "Lec.quadridentata" "Lec.lunaris" "Rotaria.sp" "Lec.furcata" "Lec.crepida"
## [11] "Pla.patulus" "Pla.quadricornis" "Macrothrix.sp" "Alonella.sp" "Nauplii"
## [16] "Cyclopoida" "Copepodite" "Lep.ovalis" "Lec.hastata" "Tri.tetractis"
## [21] "Bra.falcatus" "Lep.patella" "Lec.monostyla"
## [1] "Bra.angularis" "Lepadella.sp" "Lecane.sp" "Notholca.sp" "Bra.urceolaris" "Lec.kluchor"
## [7] "Aspelta.sp" "Col.geophila" "Lep.dactyliseta" "Bra.calyciflorus" "Bra.caudatus" "Lec.ovalis"
## [13] "Lec.elasma" "Lec.aculeata" "Ker.tropica" "Bdelloidea" "Ker.lenzi" "Con.unicornis"
## [19] "Alo.dadayi" "Chy.eurynotus" "Mac.collinsi" "Paracyclops.sp" "Asc.ecaudis" "Polyarthra.sp"
## [25] "Bra.havanaensis" "Hexarthra.sp" "Ker.serrulata" "Notodiaptomus.sp" "Fil.longiseta" "Myt.crassipes"
## [31] "Euchlanis.sp" "Colurella.sp" "Mytilina.sp" "Lec.ligona" "Ascomorpha.sp" "Pom.sulcata"
## [37] "Harpacticoida" "Epi.senta"
## [1] "Rot.neptunia" "Dis.aculeata" "Lec.luna" "Euc.dilatata" "Bea.eudactylota"
## [6] "Chy.sphaericus" "Lec.hornemanni" "Dia.birgei" "Mac.subquadratus" "Bra.quadridentatus"
## [11] "Pol.vulgaris" "Pol.bicerca" "Dicranop.sp" "Asc.saltans" "Moi.minuta"
## [16] "Alo.hamulata" "Mac.laticornis" "Mac.mira" "Pro.similis" "Alo.pulchella"
## [21] "Dia.spinulosum" "Chydorus.sp" "Ily.spinifer" "Dun.odontoplax"
## [1] 85
shared_fixos <- intersect(names(fixos_bb), names(fixos_ca))
shared_fixos
bb_only <- setdiff(names(fixos_bb), names(fixos_ca))
bb_only
ca_only <- setdiff(names(fixos_ca), names(fixos_bb))
ca_only
Riqueza <- length(shared_fixos) + length(bb_only) + length(ca_only)
Riqueza## [1] "Bra.angularis" "Lepadella.sp" "Lecane.sp" "Lec.leontina" "Lec.bulla"
## [6] "Lec.cornuta" "Bra.urceolaris" "Lec.quadridentata" "Lec.kluchor" "Lec.lunaris"
## [11] "Rotaria.sp" "Aspelta.sp" "Lec.crepida" "Lec.ovalis" "Lec.aculeata"
## [16] "Bdelloidea" "Con.unicornis" "Macrothrix.sp" "Alonella.sp" "Nauplii"
## [21] "Chy.eurynotus" "Cyclopoida" "Copepodite" "Colurella.sp" "Mytilina.sp"
## [1] "Lec.curvicornis" "Notholca.sp" "Ascomorpha.sp" "Pom.sulcata" "Harpacticoida" "Epi.senta"
## [1] "Trichocerca.sp" "Lec.furcata" "Col.geophila" "Lep.dactyliseta" "Bra.calyciflorus" "Bra.caudatus"
## [7] "Pla.patulus" "Lec.elasma" "Pla.quadricornis" "Ker.tropica" "Ker.lenzi" "Alo.dadayi"
## [13] "Mac.collinsi" "Paracyclops.sp" "Asc.ecaudis" "Lep.ovalis" "Polyarthra.sp" "Bra.havanaensis"
## [19] "Hexarthra.sp" "Lec.hastata" "Tri.tetractis" "Ker.serrulata" "Notodiaptomus.sp" "Bra.falcatus"
## [25] "Fil.longiseta" "Myt.crassipes" "Lep.patella" "Euchlanis.sp" "Lec.monostyla" "Lec.ligona"
## [1] 61
Criando um data.frame com todas as espécies compartilhadas e exclusivas.
# Create a data frame with all species
all_species <- data.frame(
type = c(rep("Shared", length(shared_spp)),
rep("Fixos only", length(fixos_only)),
rep("Entorno only", length(entorno_only))),
species = c(shared_spp, fixos_only, entorno_only)
)
# Create a table using the `table()` function
species_table <- table(all_species$type, all_species$species)
# Convert the table to a data frame and format it
species_table_df <- as.data.frame.matrix(species_table)
rownames(species_table_df) <- c("Entorno only", "Fixos only", "Shared")
species_table_df <- t(species_table_df[, order(colnames(species_table_df))])
species_table_df## Entorno only Fixos only Shared
## Alo.dadayi 0 1 0
## Alo.hamulata 1 0 0
## Alo.pulchella 1 0 0
## Alonella.sp 0 0 1
## Asc.ecaudis 0 1 0
## Asc.saltans 1 0 0
## Ascomorpha.sp 0 1 0
## Aspelta.sp 0 1 0
## Bdelloidea 0 1 0
## Bea.eudactylota 1 0 0
## Bra.angularis 0 1 0
## Bra.calyciflorus 0 1 0
## Bra.caudatus 0 1 0
## Bra.falcatus 0 0 1
## Bra.havanaensis 0 1 0
## Bra.quadridentatus 1 0 0
## Bra.urceolaris 0 1 0
## Chy.eurynotus 0 1 0
## Chy.sphaericus 1 0 0
## Chydorus.sp 1 0 0
## Col.geophila 0 1 0
## Colurella.sp 0 1 0
## Con.unicornis 0 1 0
## Copepodite 0 0 1
## Cyclopoida 0 0 1
## Dia.birgei 1 0 0
## Dia.spinulosum 1 0 0
## Dicranop.sp 1 0 0
## Dis.aculeata 1 0 0
## Dun.odontoplax 1 0 0
## Epi.senta 0 1 0
## Euc.dilatata 1 0 0
## Euchlanis.sp 0 1 0
## Fil.longiseta 0 1 0
## Harpacticoida 0 1 0
## Hexarthra.sp 0 1 0
## Ily.spinifer 1 0 0
## Ker.lenzi 0 1 0
## Ker.serrulata 0 1 0
## Ker.tropica 0 1 0
## Lec.aculeata 0 1 0
## Lec.bulla 0 0 1
## Lec.cornuta 0 0 1
## Lec.crepida 0 0 1
## Lec.curvicornis 0 0 1
## Lec.elasma 0 1 0
## Lec.furcata 0 0 1
## Lec.hastata 0 0 1
## Lec.hornemanni 1 0 0
## Lec.kluchor 0 1 0
## Lec.leontina 0 0 1
## Lec.ligona 0 1 0
## Lec.luna 1 0 0
## Lec.lunaris 0 0 1
## Lec.monostyla 0 0 1
## Lec.ovalis 0 1 0
## Lec.quadridentata 0 0 1
## Lecane.sp 0 1 0
## Lep.dactyliseta 0 1 0
## Lep.ovalis 0 0 1
## Lep.patella 0 0 1
## Lepadella.sp 0 1 0
## Mac.collinsi 0 1 0
## Mac.laticornis 1 0 0
## Mac.mira 1 0 0
## Mac.subquadratus 1 0 0
## Macrothrix.sp 0 0 1
## Moi.minuta 1 0 0
## Myt.crassipes 0 1 0
## Mytilina.sp 0 1 0
## Nauplii 0 0 1
## Notholca.sp 0 1 0
## Notodiaptomus.sp 0 1 0
## Paracyclops.sp 0 1 0
## Pla.patulus 0 0 1
## Pla.quadricornis 0 0 1
## Pol.bicerca 1 0 0
## Pol.vulgaris 1 0 0
## Polyarthra.sp 0 1 0
## Pom.sulcata 0 1 0
## Pro.similis 1 0 0
## Rot.neptunia 1 0 0
## Rotaria.sp 0 0 1
## Tri.tetractis 0 0 1
## Trichocerca.sp 0 0 1
Na sequência dos dois próximos tópicos, estou mesclando tudo na base de dados zoorebio (que será a matriz de bruta, subsequentemente) e criando uma copia em .xlsx, .csv e .txt na pasta de trabalho do R.
1.2.2 Definindo a base de dados
library(dplyr)
# Add missing columns with zeros to both data frames
fixos[setdiff(shared_spp, names(fixos))] <- 0
entorno[setdiff(shared_spp, names(entorno))] <- 0
# Combine the two data frames
merged <- bind_rows(fixos, entorno) #merging the two datasets
merged[is.na(merged)] <- 0
# Order the rows by their original data frame names
merged <- merged[order(gsub("[^[:alpha:]]", "", rownames(merged))), ]
# Print the merged data frame
zoorebio <- merged
as.matrix(zoorebio)[1:6, 1:6] ## Bra.angularis Lepadella.sp Lecane.sp Lec.leontina Lec.bulla Lec.cornuta
## BB1-P01 0.0000000 0.0000000 0 0 1.0666667 0
## BB1-P02 0.5333333 0.1777778 0 0 0.0000000 0
## BB1-P03 0.5333333 0.1777778 0 0 0.3555556 0
## BB2-P01 0.0000000 0.5333333 0 0 0.8888889 0
## BB2-P02 0.0000000 0.1777778 0 0 0.1777778 0
## BB2-P03 0.0000000 0.1777778 0 0 0.0000000 0
1.2.3 Fazendo uma copia da base de dados zoorebio
write.table(zoorebio, "zoorebio.txt", sep = "\t", quote = FALSE)
write.table(zoorebio, "zoorebio.csv", append = F, quote = TRUE, sep = ";", row.names = T, dec = ",")
#dir <- getwd()
#shell.exec(dir) #abre o diretorio de trabalho no Windows Explorer
zoorebio_csv <- read.csv("zoorebio.csv",
sep = ";", dec = ",",
header = T,
row.names = 1,
na.strings = NA)1.3 Reset point
m_bruta <- zoorebio_csvAqui cria-se o vertor da matriz bruta a partir da base de dados depois de feitos os ajustes necessários.
1.4 Informações sobre o tamanho da base de dados
range(m_bruta) #menor e maior valores
length(m_bruta) #no. de colunas
ncol(m_bruta) #no. de N colunas
nrow(m_bruta) #no. de M linhas
sum(lengths(m_bruta)) #soma os nos. de colunas
length(as.matrix(m_bruta)) #tamanho da matriz m x n
sum(m_bruta == 0) # número de observações igual a zero
sum(m_bruta > 0) # número de observações maiores que zero
zeros <- (sum(m_bruta == 0)/length(as.matrix(m_bruta)))*100 # proporção de zeros na matriz
zeros## [1] 0 72
## [1] 85
## [1] 85
## [1] 49
## [1] 4165
## [1] 4165
## [1] 3763
## [1] 402
## [1] 90.34814
Tabela que resume as informações geradas (Tabela @ref@(tab:1tbl-tam)).
## Função Resultado
## 1 range 0 - 72
## 2 lenght 85
## 3 n cols 85
## 4 m linhas 49
## 5 Tamanho 4165
## 6 Tamanho 4165
## 7 Zeros 3763
## 8 Nao zeros 402
## 9 % Zeros 90.3
| Função | Resultado |
|---|---|
| range | 0 - 72 |
| lenght | 85 |
| n cols | 85 |
| m linhas | 49 |
| Tamanho | 4165 |
| Tamanho | 4165 |
| Zeros | 3763 |
| Nao zeros | 402 |
| % Zeros | 90.3 |
Ou seja, temos uma matriz de tamanho m x n igual a 49 objetos por 85 atributos, onde 90.35% dos valores da matriz são iguais a zero!
1.5 Criando uma matriz de médias
#Inserindo coluna para agrupamentos
ncol(m_bruta); nrow(m_bruta) #no. de N colunas x M linhas
m_bruta_g <- cbind(Grupos = rownames(m_bruta), m_bruta)
agrup <- substr(m_bruta_g[, 1], 1,2)
agrup
m_bruta_g <- m_bruta_g %>% mutate(Grupos=c(agrup))
m_avg_part <- aggregate(m_bruta_g[, 2:3], list(m_bruta_g$Grupos), mean)
m_avg <- m_bruta_g %>%
group_by(Grupos) %>%
summarise(across(.cols = everything(), ~ mean(.x, na.rm = TRUE)))
#m_avg <- m_bruta_g %>%
# group_by(Grupos) %>%
# summarise(across(.cols = everything(), list(mean = mean, sd = sd)))
?across
#Primeira coluna para nomes das linhas
m_avg <- as.data.frame(m_avg)
class(m_avg)
rownames(m_avg) <- m_avg[,1]
m_avg[,1] <- NULL
#Salvando a matriz
write.table(m_avg,
"m_avgcsv.csv",
append = F,
quote = TRUE,
sep = ";", dec = ",",
row.names = T)
m_avg_csv <- read.csv("m_avgcsv.csv",
sep = ";", dec = ",",
header = T,
row.names = 1,
na.strings = NA)# Análise de espécies compartilhadas
system(paste("open", shQuote("D:/Elvio/OneDrive/MSS/_Zoo-Rebio/R_ZooRebio/shared.qmd")))Apêndices
1.5.1 Sobre o comando setdiff()
These two lines of code are used to replace the columns in the fixos and entorno data frames that are not present in shared_spp with missing values (NA). setdiff(x, y) returns the set difference between two vectors x and y, i.e., all the elements in x that are not in y. In this case, setdiff(shared_spp, names(fixos)) returns the column names in shared_spp that are not present in fixos, and setdiff(shared_spp, names(entorno)) returns the column names in shared_spp that are not present in entorno.
So, fixos[setdiff(shared_spp, names(fixos))] <- NA replaces the columns in fixos that are not present in shared_spp with NA, and entorno[setdiff(shared_spp, names(entorno))] <- NA replaces the columns in entorno that are not present in shared_spp with NA.
This is necessary to ensure that both data frames have the same column names before they are joined together.
This line of code is sorting the rows of the merged data frame by the alphabetical order of the row names. The gsub function is used to remove any non-alphabetic characters from the row names, and the resulting alphabetical order is used to sort the rows of the data frame using the order function.
In other words, the row names are sorted in alphabetical order by removing any non-alphabetic characters, and the resulting order is used to sort the rows of the data frame. This can be useful if the row names have a specific naming convention that needs to be followed when presenting the data or if they need to be in a specific order for a downstream analysis.