class: center, middle, inverse, title-slide .title[ # BioMath-2023 ] .subtitle[ ## Aplicaciones de las matématicas en biología ] .author[ ### Yostin Jesús Añino Ramos ] .institute[ ###
https://yostinlab.com
] .date[ ### 2023-11-5 ] --- class: inverse, center, middle ### *"El futuro, tal como el pasado estarían presentes ante tus ojos"* <div style="text-align: right;color: yellow; font-size: 40px;font-family: 'Arial'"> Pierre-Simon Laplace </div> --- class: inverse # BioMath-2023 <div style="text-align: left;color: yellow; font-size: 40px;font-family: 'Arial'"> Bienvenidos </div> .pull-left[ <div> <p style = 'text-align:right;'> <iframe width="400" height = "300" src="https://www.youtube.com/embed/BehTPPocqi0"> </iframe> </div> </p> ] .pull-right[ 1. Biología Matemática. Un enfoque desde los sistemas dinámicos 1. Sistemas dinámicos y caos 1. Una ecuación sencilla 1. Aleatoriedad 1. Un caso aplicado ] .footnote[ <div style="text-align: justify;color: yellow; font-size: 20px;font-family: 'Arial'"> Formato: Fuente Garamond 11; 1.15 de espaciado justificado; márgenes 2.5 por lado; Titulo, autor, correo y afiliaciones centrado y sin negritas. Es necesario agregar al menos 3 palabras claves. </div>] --- class: inverse <div style="text-align: left;color: white; font-size: 40px;font-family: 'Arial'"> Sistemas dinámicos y caos </div> <div> <p style = 'text-align:center;'> <iframe width="700" height = "500" src="https://www.youtube.com/embed/dw8dty0-g1k"> </iframe> </div> </p> .footnote[**Fuente:** Derivando <https://www.youtube.com/@Derivando>] --- class: inverse <div style="text-align: left;color: white; font-size: 40px;font-family: 'Arial'"> Sistemas dinámicos y caos </div> <div> <p style = 'text-align:center;'> <iframe width="700" height = "500" src="https://www.youtube.com/embed/gIwvFMiJNVU"> </iframe> </div> </p> .footnote[**Fuente:** Veritasium <https://www.youtube.com/@VeritasiumES>] --- class: inverse <div style="text-align: left;color: white; font-size: 40px;font-family: 'Arial'"> Una ecuación sencilla </div> <div> <p style = 'text-align:center;'> <iframe width="700" height = "500" src="https://www.youtube.com/embed/EOvLhZPevm0"> </iframe> </div> </p> .footnote[**Fuente:** Veritasium <https://www.youtube.com/@VeritasiumES>] --- class: inverse <div style="text-align: left;color: white; font-size: 40px;font-family: 'Arial'"> ¿Existe Algo NO Aleatorio? </div> <div> <p style = 'text-align:center;'> <iframe width="700" height = "500" src="https://www.youtube.com/embed/FtEe0IlK6Hc"> </iframe> </div> </p> .footnote[**Fuente:** Veritasium <https://www.youtube.com/@VeritasiumES>] --- class: inverse <div style="text-align: left;color: white; font-size: 40px;font-family: 'Arial'"> Un caso aplicado a la biología </div> <div> <p style = 'text-align:center;'> <iframe width="700" height = "500" src="https://www.youtube.com/embed/_RAg5--kIm0"> </iframe> </div> </p> .footnote[**Fuente:** Veritasium <https://www.youtube.com/@VeritasiumES>] --- class: inverse, center, middle ### *"Sin datos, eres solo otra persona con una opinión"* <div style="text-align: right;color: yellow; font-size: 40px;font-family: 'Arial'"> W. Edwards Deming </div> ### *"Sin datos **Entendidos**, eres solo otra persona con una opinión"* <div style="text-align: right;color: yellow; font-size: 40px;font-family: 'Arial'"> Yostin Añino </div> --- class: inverse <div style="text-align: left;color: white; font-size: 40px;font-family: 'Arial'"> II FASE </div> <div> <p style = 'text-align:center;'> <iframe width="700" height = "490" src="https://www.youtube.com/embed/qJA3TI2CrCo"> </iframe> </div> </p> .footnote[ <div style="text-align: justify;color: yellow; font-size: 20px;font-family: 'Arial'"> Plantilla:</div> [Descargue Aquí](https://revistas.uned.ac.cr/index.php/cuadernos/libraryFiles/downloadPublic/147)] --- class: inverse <div style="text-align: left;color: white; font-size: 40px;font-family: 'Arial'"> ¿Cómo Descargar e Instalar R y Rstudio? </div> <div> <p style = 'text-align:center;'> <iframe width="700" height = "500" src="https://www.youtube.com/embed/S4J6ikbWxn0"> </iframe> </div> </p> .footnote[**Fuente:** Leducatec <https://www.youtube.com/@Leducatec>] --- class: inverse <div style="text-align: left;color: white; font-size: 40px;font-family: 'Arial'"> Base de Datos </div> ```r Especie<-rep("Euglossa imperialis", 44) Localidad<-rep("BCI", 44) Año<-c(rep("2009", 4), rep("2010", 4), rep("2011", 4), rep("2012", 4), rep("2013", 4), rep("2014", 4), rep("2015", 4), rep("2016", 4), rep("2017", 4), rep("2018", 4), rep("2019", 4)) Mes<-rep(c("A_Marzo","B_Mayo","C_Septiembre","D_Noviembre"), 11) MesN<-c(1, 2, 6, 8, 12, 14, 18, 20, 24, 26, 30, 32, 36, 38, 42, 44, 48, 50, 54, 56, 60, 62, 66, 68, 72, 74, 78, 80, 84, 86, 90, 92, 96, 98, 102, 104, 108, 110, 114, 116,120,122,126,128) Abundancia<-c(480, 277, 338, 187,744, 439, 238, 118, 582, 800, 191, 242, 863, 751, 560, 489, 1008, 541, 187, 70, 703, 928, 272, 677, 641, 731, 518, 491, 814, 416, 236,231, 889,416, 341, 205, 645, 581, 594, 309, 1083, 815, 728, 486) Base<-data.frame(Especie, Localidad, Año, Mes, MesN, Abundancia) ``` .footnote[ <div style="text-align: justify;color: yellow; font-size: 22px;font-family: 'Arial'"> Serie temporal de Euglossa imperialis en la Isla Barro Colorado de marzo 2009 a noviembre 2019. </div> **Fuente:** [Roubik et al., 2019](https://conbio.onlinelibrary.wiley.com/doi/full/10.1111/csp2.543)] --- class: inverse <div style="text-align: left;color: white; font-size: 40px;font-family: 'Arial'"> Visualización de datos </div> ```r # Cargar la librería ggplot2 library(ggplot2) # Crear un campo de fecha con el primer día de cada mes Base$Fecha <- as.Date(paste(Base$Año, Mes, "01"), format = "%Y %B %d") # Crear el gráfico de serie de tiempo plot1 <- ggplot(Base, aes(x =MesN, y = Abundancia)) + geom_line() + labs(x = "Fecha", y = "Abundancia", title = "Serie de Tiempo de Abundancia de Euglossa imperialis en BCI") #Se carga las librerias necesarias library(forecast) library(tseries) library(fpp2) # Grafico de serie de tiempo con autoplot data_serie <-ts(Base$Abundancia,frequency=4, start=2009) Autoplot1<-autoplot(data_serie)+labs(title = "Serie de tiempo", x = "Tiempo",y = "Valor", colour = "#00a0dc")+ theme_bw() ``` .footnote[ <div style="text-align: justify;color: yellow; font-size: 22px;font-family: 'Arial'"> Para visualizar los plot corra los objetos corresponientes </div>] --- class: inverse <div style="text-align: left;color: white; font-size: 40px;font-family: 'Arial'"> Serie Temporal </div> ```r ###Descomposición de la serie de tiempo fit <- decompose(data_serie, type='multiplicative') #autoplot, pero con el objeto fit Desco1<-autoplot(fit)+ labs(title = "Descomposici?n de la serie de tiempo", x = "Tiempo", y = "Valor", colour = "Gears")+ theme_bw() # TENDENCIA Tendencia<-autoplot(data_serie, series="Serie tiempo") + autolayer(trendcycle(fit), series="Tendencia") + labs(title = "Serie de tiempo", x = "Tiempo", y = "Valor") + theme_bw() ``` .footnote[ <div style="text-align: justify;color: yellow; font-size: 28px;font-family: 'Arial'"> TENDENCIA </div>] --- class: inverse <div style="text-align: left;color: white; font-size: 40px;font-family: 'Arial'"> Serie Temporal </div> ```r library(ggplot2) # Boxplot Irrebox<-ggplot(Base, aes(x = Mes, y= Abundancia)) + stat_boxplot() + theme_grey() + # Default theme(legend.position = "top") + geom_point() Irre1<-autoplot(acf(data_serie, plot = FALSE)) # Test Dickey-Fuller Test adf.test(data_serie, alternative = "stationary") ``` ``` ## ## Augmented Dickey-Fuller Test ## ## data: data_serie ## Dickey-Fuller = -2.107, Lag order = 3, p-value = 0.5314 ## alternative hypothesis: stationary ``` .footnote[ <div style="text-align: justify;color: yellow; font-size: 28px;font-family: 'Arial'"> ESTACIONARIEDAD O IRREGULARIDAD </div>] --- class: inverse <div style="text-align: left;color: white; font-size: 40px;font-family: 'Arial'"> Serie Temporal </div> ```r library(ggplot2) estacio1<- ggseasonplot(data_serie) estacio2<-autoplot(fit)+ labs(title = "Descomposici?n de la serie de tiempo", x = "Tiempo", y = "Valor", colour = "Gears", size= 1)+ theme_bw() ``` .footnote[ <div style="text-align: justify;color: yellow; font-size: 28px;font-family: 'Arial'"> ESTACIONALIDAD </div>] --- class: inverse <div style="text-align: left;color: white; font-size: 40px;font-family: 'Arial'"> Serie Temporal </div> ```r # TRANSFORMACION # Doble Diferenciado ndif <- nsdiffs(data_serie) seriedif <- diff(data_serie,lag = 1,differences = ndif) ndif2 <- nsdiffs(seriedif) seriedif2 <- diff(seriedif,lag = 1,differences = ndif2) # Test adf.test(seriedif2, alternative = "stationary") ``` ``` ## ## Augmented Dickey-Fuller Test ## ## data: seriedif2 ## Dickey-Fuller = -9.0844, Lag order = 3, p-value = 0.01 ## alternative hypothesis: stationary ``` .footnote[ <div style="text-align: justify;color: yellow; font-size: 28px;font-family: 'Arial'"> TRANSFORMACIONES </div>] --- class: inverse <div style="text-align: left;color: white; font-size: 40px;font-family: 'Arial'"> Serie Temporal </div> ```r library("fUnitRoots") tsstationary = diff(data_serie, differences=1) timeseriesseasonallyadjusted <- data_serie-fit$seasonal tsstationary <- diff(timeseriesseasonallyadjusted, differences=1) #### AJUSTE DEL MODELO: Calcular p d q fitARIMA <- arima(data_serie, order=c(1,1,1),seasonal = list(order = c(1,0,0), period = 4),method="ML") library(lmtest) coeftest(fitARIMA) ``` ``` ## ## z test of coefficients: ## ## Estimate Std. Error z value Pr(>|z|) ## ar1 0.208122 0.162941 1.2773 0.2015 ## ma1 -0.966519 0.081495 -11.8599 < 2.2e-16 *** ## sar1 0.598337 0.132385 4.5197 6.194e-06 *** ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ``` .footnote[ <div style="text-align: justify;color: yellow; font-size: 28px;font-family: 'Arial'"> ESTIMACIÓN DE UN MODELO </div>] --- class: inverse <div style="text-align: left;color: white; font-size: 40px;font-family: 'Arial'"> Serie Temporal </div> ```r # MODELOS modelo1 <- arima(data_serie, order = c(0,2,1), seasonal = list(order = c(0,0,1),12)) modelo2 <- arima(data_serie, order = c(0,2,1), seasonal = list(order = c(1,0,0),12)) modelo3 <- arima(data_serie, order = c(1,1,1), seasonal = list(order = c(1,0,0),12)) modelo4 <- arima(data_serie, order = c(0,2,0), seasonal = list(order = c(1,0,1),12)) modeloB <- arima(data_serie, order = c(1,1,1), seasonal = list(order = c(1,1,0),12)) library(forecast) auto.arima(data_serie, trace=TRUE) ``` ``` ## ## ARIMA(2,0,2)(1,1,1)[4] with drift : Inf ## ARIMA(0,0,0)(0,1,0)[4] with drift : 557.3659 ## ARIMA(1,0,0)(1,1,0)[4] with drift : 555.0771 ## ARIMA(0,0,1)(0,1,1)[4] with drift : Inf ## ARIMA(0,0,0)(0,1,0)[4] : 556.5374 ## ARIMA(1,0,0)(0,1,0)[4] with drift : 557.8967 ## ARIMA(1,0,0)(2,1,0)[4] with drift : 548.0126 ## ARIMA(1,0,0)(2,1,1)[4] with drift : Inf ## ARIMA(1,0,0)(1,1,1)[4] with drift : Inf ## ARIMA(0,0,0)(2,1,0)[4] with drift : 548.455 ## ARIMA(2,0,0)(2,1,0)[4] with drift : 547.6657 ## ARIMA(2,0,0)(1,1,0)[4] with drift : 555.9147 ## ARIMA(2,0,0)(2,1,1)[4] with drift : Inf ## ARIMA(2,0,0)(1,1,1)[4] with drift : Inf ## ARIMA(3,0,0)(2,1,0)[4] with drift : 550.0537 ## ARIMA(2,0,1)(2,1,0)[4] with drift : 550.1453 ## ARIMA(1,0,1)(2,1,0)[4] with drift : 549.5051 ## ARIMA(3,0,1)(2,1,0)[4] with drift : 553.1846 ## ARIMA(2,0,0)(2,1,0)[4] : 546.6224 ## ARIMA(2,0,0)(1,1,0)[4] : 554.4925 ## ARIMA(2,0,0)(2,1,1)[4] : 549.1452 ## ARIMA(2,0,0)(1,1,1)[4] : Inf ## ARIMA(1,0,0)(2,1,0)[4] : 547.5283 ## ARIMA(3,0,0)(2,1,0)[4] : 548.9706 ## ARIMA(2,0,1)(2,1,0)[4] : 549.0133 ## ARIMA(1,0,1)(2,1,0)[4] : 548.4839 ## ARIMA(3,0,1)(2,1,0)[4] : 551.9248 ## ## Best model: ARIMA(2,0,0)(2,1,0)[4] ``` ``` ## Series: data_serie ## ARIMA(2,0,0)(2,1,0)[4] ## ## Coefficients: ## ar1 ar2 sar1 sar2 ## 0.2636 0.3465 -0.6425 -0.5195 ## s.e. 0.1534 0.1809 0.1496 0.1373 ## ## sigma^2 = 38466: log likelihood = -267.43 ## AIC=544.86 AICc=546.62 BIC=553.3 ``` --- class: inverse <div style="text-align: left;color: white; font-size: 40px;font-family: 'Arial'"> Serie Temporal </div> ```r library(forecast) model=auto.arima(data_serie,stepwise=FALSE,approximation=FALSE) summary(model) ``` ``` ## Series: data_serie ## ARIMA(0,0,2)(0,1,1)[4] ## ## Coefficients: ## ma1 ma2 sma1 ## 0.2692 0.3961 -0.8023 ## s.e. 0.1525 0.1418 0.2189 ## ## sigma^2 = 36621: log likelihood = -267.76 ## AIC=543.53 AICc=544.67 BIC=550.28 ## ## Training set error measures: ## ME RMSE MAE MPE MAPE MASE ## Training set 50.37807 175.4843 134.2306 -0.2656975 27.21404 0.6360134 ## ACF1 ## Training set -0.08878148 ``` .footnote[ <div style="text-align: justify;color: yellow; font-size: 28px;font-family: 'Arial'"> ESTIMACIÓN DE UN MODELO </div>] --- class: center, middle # Thanks! Preguntas?