--- title: "Analyse de l'incidence du syndrome grippal" author: "Clément MOLINA" date: "2023-08-31" output: html_document --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` ```{r} data_url = "https://www.sentiweb.fr/datasets/incidence-PAY-3.csv?v=4bf55" ``` ```{r} data = read.csv(data_url, skip = 1) head(data) ``` ```{r} tail(data) ``` ```{r} lignes_na = apply(data, 1, function (x) any(is.na(x))) data [lignes_na,] ``` ```{r} class(data$week) ``` ```{r} class(data$inc) ``` ```{r} data = read.csv(data_url, skip = 1,na.strings = "-") ``` ```{r} lignes_na = apply(data, 1, function (x) any(is.na(x))) data [lignes_na,] ``` ```{r} library(parsedate) ``` ```{r} convert_date = 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_date(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,"-08-01") fin = paste0(annee,"-08-01") semaines = data$date > debut & data$date <= fin sum(data$inc[semaines], na.rm=TRUE) } ``` ```{r} inc_annuelle = data.frame(annee = 1986:2023, incidence = sapply(1986:2023, pic_annuel)) head(inc_annuelle) ``` ```{r} plot(inc_annuelle, type="p", xlab="Année", ylab="Incidence annuelle") ``` ```{r} tail(inc_annuelle[order(-inc_annuelle$incidence),]) ``` ```{r} hist(inc_annuelle$incidence, breaks=10, xlab="Incidence annuelle", ylab="Nb d'observations", main="") ```