--- title: "Exercice 2 Module 3" author: "Da Mota Mégane" date: "02/03/2022" output: html_document --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` ## Préparation des données : Etude de la varicelle, étude des données du réseau sentinelle. L'URL est : ```{r} data_url = "http://www.sentiweb.fr/datasets/incidence-PAY-7.csv" ``` ## Téléchargement : ```{r} data = read.csv(data_url, skip=1) ``` ```{r} head(data) tail(data) ``` ```{r} na_records = apply(data, 1, function (x) any(is.na(x))) data[na_records,] ``` ```{r} class(data$week) class(data$inc) ``` ```{r} library(parsedate) ``` ```{r} convert_week = function(w) { ws = paste(w) iso = paste0(substring(ws, 1, 4), "-W", substring(ws, 5, 6)) as.character(parse_iso_8601(iso)) } ``` ```{r} data$date = as.Date(convert_week(data$week)) ``` ```{r} class(data$date) ``` ```{r} data = data[order(data$date),] ``` ```{r} all(diff(data$date) == 7) ``` ```{r} plot(data$date, data$inc, type="l", xlab="Date", ylab="Incidence hebdomadaire") ``` ```{r} with(tail(data, 200), plot(date, inc, type="l", xlab="Date", ylab="Incidence hebdomadaire")) ``` ```{r} pic_annuel = function(annee) { debut = paste0(annee-1,"-09-01") fin = paste0(annee,"-09-01") semaines = data$date > debut & data$date <= fin sum(data$inc[semaines], na.rm=TRUE) } ``` ```{r} annees = 1991:2021 ``` ```{r} inc_annuelle = data.frame(annee = annees, incidence = sapply(annees, pic_annuel)) head(inc_annuelle) ``` ```{r} plot(inc_annuelle, type="p", xlab="Année", ylab="Incidence annuelle") ``` ```{r} head(inc_annuelle[order(-inc_annuelle$incidence),]) ```