Introducción al uso de Sinax

Descargue el paquete desde el github.

#install.packages("devtools")
library(devtools)
#install_github("osoramirez/Sinax")

Activar el paquete

library(Sinax)
## Loading required package: tuneR
## Loading required package: seewave
## Loading required package: soundecology

El paquete le permite estimar de una forma fácil y rápida, una serie de índices acústicos, que son usados en publicaciones científica.

Sinax le permite analizar con códigos simples, un conjunto de archivos, en los cuales usted puede organizarlos por carpeta o sitio.

El único requisito es que el archivo no sea un audio menor a un intervalo de tiempo de 2 min, dado que tiene una función que permite de forma automática estimar índices por intervalos de tiempo de un minuto de forma automática.

Establezca su directorio de trabajo

Para ello utilice la función “setwd”

Ejemplo: setwd(“ruta/de/sus/archivos/.wav”)

Esta ruta es la que contiene sus archivos .wav

setwd("F:\\Dropbox\\Sinax\\")

Una vez establecido su directorio de trabajo podemos empezar a estimar los índices.

SINAX contiene varias funciones principales

soundindex

par(mfrow=c(3,3))
library(Sinax)
time<-seq(0:5)
dom.freq()->Fdom.freq

head(Fdom.freq,3)
##                    Mean  F01 F12 F23 F34 F45 F56 F67 F78 F89 F910 F1011
## OSA_500.wav  0.03926496 2569   2   1   3   7   0   1   0   0    0     0
## OSA_500.wav1 0.02952792 2573   5   2   0   1   2   0   0   0    0     0
## OSA_500.wav2 0.02977801 2571   7   4   1   0   0   0   0   0    0     0
##              F1112 F1213 F1314 F1415 F15
## OSA_500.wav      0     0     0     0   0
## OSA_500.wav1     0     0     0     0   0
## OSA_500.wav2     0     0     0     0   0

Explore las otras funciones de “Sinax”, como “soundindex” y analice sus resultados.

Procesando los datos

Asegúrese de identificar muy bien la matriz de sus resultados, tal como el sitio por ejemplo de donde fueron grabados sus archivos .wav

Agregar una columna para identificar al sitio de donde provienen los datos

Fdom.freq$Sites <- "OSA1" 
head(Fdom.freq,2)
##                    Mean  F01 F12 F23 F34 F45 F56 F67 F78 F89 F910 F1011
## OSA_500.wav  0.03926496 2569   2   1   3   7   0   1   0   0    0     0
## OSA_500.wav1 0.02952792 2573   5   2   0   1   2   0   0   0    0     0
##              F1112 F1213 F1314 F1415 F15 Sites
## OSA_500.wav      0     0     0     0   0  OSA1
## OSA_500.wav1     0     0     0     0   0  OSA1

En caso de requerir ingresar mas información, como fechas, horas u otras descriptores, proceda a ingresarla de la misma forma.

Vamos a suponer que usted tomó algunas covariables que podrían explicar las frecuencias dominantes estimadas, para ello vamos a generar datos que suponen reflejan la riqueza del sitio

set.seed(2019)
dat <- data.frame(Riq=rnorm(6,25,8), abun=rnorm(6,5,2), Cob=rnorm(6,70,30))
head(dat)
##        Riq     abun      Cob
## 1 30.90818 3.434754 36.47197
## 2 20.88192 6.018592 77.02008
## 3 11.87855 2.020122 79.48455
## 4 32.32829 4.361641 81.12306
## 5 14.86014 4.524178 96.32766
## 6 30.90598 8.237246 16.95029

Unir las bases de datos

datos <- data.frame(Fdom.freq, dat)
head(datos)
##                    Mean  F01 F12 F23 F34 F45 F56 F67 F78 F89 F910 F1011
## OSA_500.wav  0.03926496 2569   2   1   3   7   0   1   0   0    0     0
## OSA_500.wav1 0.02952792 2573   5   2   0   1   2   0   0   0    0     0
## OSA_500.wav2 0.02977801 2571   7   4   1   0   0   0   0   0    0     0
## OSA_500.wav3 0.02602658 2580   1   1   0   0   0   1   0   0    0     0
## OSA_500.wav4 0.02595989 2581   0   0   0   0   1   0   1   0    0     0
## OSA_500.wav5 0.01787348 2583   0   0   0   0   0   0   0   0    0     0
##              F1112 F1213 F1314 F1415 F15 Sites      Riq     abun      Cob
## OSA_500.wav      0     0     0     0   0  OSA1 30.90818 3.434754 36.47197
## OSA_500.wav1     0     0     0     0   0  OSA1 20.88192 6.018592 77.02008
## OSA_500.wav2     0     0     0     0   0  OSA1 11.87855 2.020122 79.48455
## OSA_500.wav3     0     0     0     0   0  OSA1 32.32829 4.361641 81.12306
## OSA_500.wav4     0     0     0     0   0  OSA1 14.86014 4.524178 96.32766
## OSA_500.wav5     0     0     0     0   0  OSA1 30.90598 8.237246 16.95029

Supongamos que queremos buscar explicaciones acerca de los que encontramos con nuestras variables. Para ello iniciaremos generando modelos básicos de relaciones. Nuevamente tener en cuenta que es su hipótesis de trabajo. Hay muchas alternativas de análisis, aquí se muestra un análisis clásico para tratar de explicar en términos de una relación lineal.

Estandarizar las variables explicativas

#Rescalamiento
datos$Riq <-scale(datos$Riq , center = TRUE, scale = TRUE)
datos$abun <-scale(datos$abun , center = TRUE, scale = TRUE)
datos$Cob <-scale(datos$Cob , center = TRUE, scale = TRUE)
head(datos)
##                    Mean  F01 F12 F23 F34 F45 F56 F67 F78 F89 F910 F1011
## OSA_500.wav  0.03926496 2569   2   1   3   7   0   1   0   0    0     0
## OSA_500.wav1 0.02952792 2573   5   2   0   1   2   0   0   0    0     0
## OSA_500.wav2 0.02977801 2571   7   4   1   0   0   0   0   0    0     0
## OSA_500.wav3 0.02602658 2580   1   1   0   0   0   1   0   0    0     0
## OSA_500.wav4 0.02595989 2581   0   0   0   0   1   0   1   0    0     0
## OSA_500.wav5 0.01787348 2583   0   0   0   0   0   0   0   0    0     0
##              F1112 F1213 F1314 F1415 F15 Sites        Riq       abun
## OSA_500.wav      0     0     0     0   0  OSA1  0.8621721 -0.6586448
## OSA_500.wav1     0     0     0     0   0  OSA1 -0.3250772  0.6196450
## OSA_500.wav2     0     0     0     0   0  OSA1 -1.3912011 -1.3584994
## OSA_500.wav3     0     0     0     0   0  OSA1  1.0303332 -0.2000904
## OSA_500.wav4     0     0     0     0   0  OSA1 -1.0381387 -0.1196795
## OSA_500.wav5     0     0     0     0   0  OSA1  0.8619117  1.7172692
##                     Cob
## OSA_500.wav  -0.9736241
## OSA_500.wav1  0.4317609
## OSA_500.wav2  0.5171784
## OSA_500.wav3  0.5739687
## OSA_500.wav4  1.1009553
## OSA_500.wav5 -1.6502391
datos$File<- rownames(datos)
rownames(datos)<- NULL
names(datos)
##  [1] "Mean"  "F01"   "F12"   "F23"   "F34"   "F45"   "F56"   "F67"  
##  [9] "F78"   "F89"   "F910"  "F1011" "F1112" "F1213" "F1314" "F1415"
## [17] "F15"   "Sites" "Riq"   "abun"  "Cob"   "File"
datos2 <- datos2 <- datos[,c(2:17, 19:21, 18,22)]
head(datos2,2)
##    F01 F12 F23 F34 F45 F56 F67 F78 F89 F910 F1011 F1112 F1213 F1314 F1415
## 1 2569   2   1   3   7   0   1   0   0    0     0     0     0     0     0
## 2 2573   5   2   0   1   2   0   0   0    0     0     0     0     0     0
##   F15        Riq       abun        Cob Sites         File
## 1   0  0.8621721 -0.6586448 -0.9736241  OSA1  OSA_500.wav
## 2   0 -0.3250772  0.6196450  0.4317609  OSA1 OSA_500.wav1

Observe que hemos estandarizados nuestras variables explicativas, ahora buscaremos algunas relaciones.

library("PerformanceAnalytics")
## Loading required package: xts
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## 
## Attaching package: 'PerformanceAnalytics'
## The following object is masked from 'package:graphics':
## 
##     legend
chart.Correlation(datos2[, c(1:6, 18,19)], histogram=TRUE, pch=19)

library("FactoMineR")
## Warning: package 'FactoMineR' was built under R version 3.5.2
library("factoextra")
## Warning: package 'factoextra' was built under R version 3.5.2
## Loading required package: ggplot2
## Welcome! Related Books: `Practical Guide To Cluster Analysis in R` at https://goo.gl/13EFCZ
res.pca <- PCA(datos2[, c(1:6, 18,19)], graph = FALSE)
eig.val <- get_eigenvalue(res.pca)
fviz_eig(res.pca, addlabels = TRUE)

head(res.pca$var$coord)
##          Dim.1       Dim.2       Dim.3       Dim.4         Dim.5
## F01 -0.9877265 -0.01388877 -0.07388153  0.06136804 -0.0002412928
## F12 -0.3770718  0.51652177  0.42373892 -0.43754848  0.4083209090
## F23  0.7841297 -0.14240284 -0.13973398 -0.47265377  0.2059476473
## F34  0.6830410 -0.35376331 -0.23862392  0.35576672  0.4261140074
## F45  0.7650025  0.29573233  0.14249490 -0.21354833 -0.4743598600
## F56  0.4605615  0.39905744  0.65431827  0.28765460  0.1319415224
fviz_pca_var(res.pca, col.var = "cos2",
             repel = TRUE)

fviz_pca_biplot(res.pca,  geom = "text")

Buscando relaciones lineales

lm1 <- lm(F23~Cob, data = datos2)
summary(lm1)
## 
## Call:
## lm(formula = F23 ~ Cob, data = datos2)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -5.101 -2.990 -1.183  1.331  9.350 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)   
## (Intercept)   4.0000     0.9973   4.011  0.00101 **
## Cob          -0.6673     1.0262  -0.650  0.52474   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.231 on 16 degrees of freedom
## Multiple R-squared:  0.02575,    Adjusted R-squared:  -0.03514 
## F-statistic: 0.4229 on 1 and 16 DF,  p-value: 0.5247
library(ggplot2)
ggplot(lm1, aes(Cob, F23)) + geom_point() + geom_smooth()
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

Nota: No olvide nunca confirmar los supuestos de sus datos “residuos”, para aplicar a los diferentes modelos que tiene alternativos como glm, gam, etc.

La información del Taller se encuntra disponible en: https://www.dropbox.com/sh/b9l5lsjr9id74ty/AABKPJ39rmsN3ALTQc0pXdi5a?dl=0