diff --git a/module3/exo2/exercice_fr.Rmd b/module3/exo2/exercice_fr.Rmd index a32f3e8680b86641b2e5989ebcbe65cd2344159a..860d37fc81c7dbaa40a813b6292bfa665e488d80 100644 --- a/module3/exo2/exercice_fr.Rmd +++ b/module3/exo2/exercice_fr.Rmd @@ -1,54 +1,36 @@ --- -title: "Analyse de l'incidence de la varicelle" -author: "HYC" -output: - html_document: - toc: true - theme: journal - pdf_document: - toc: true -documentclass: article -classoption: a4paper -header-includes: -- \usepackage[french]{babel} -- \usepackage[upright]{fourier} -- \hypersetup{colorlinks=true,pagebackref=true} +title: "Analyse de la varicelle" +output: html_document --- ```{r} knitr::opts_chunk$set(echo = TRUE) -data_url = "[https://www.sentiweb.fr/datasets/incidence-PAY-7.csv](https://www.sentiweb.fr/datasets/incidence-PAY-7.csv)" local_file = "varicelle.csv" -if (!file.exists(local_file)) { download.file(url = data_url, destfile = local_file, method = "auto") } + data = read.csv(local_file, skip=1, na.strings=c("-")) -head(data) -tail(data) -na_records = apply(data, 1, function (x) any(is.na(x))) -data[na_records,] -class(data$week) -class(data$inc) + library(parsedate) convert_week = function(w) { ws = paste(w) iso = paste0(substring(ws, 1, 4), "-W", substring(ws, 5, 6)) as.character(parse_iso_8601(iso)) } + data$date = as.Date(convert_week(data$week)) -class(data$date) data = data[order(data$date),] -all(diff(data$date) == 7) -plot(data$date, data$inc, type="l", xlab="Date", ylab="Incidence hebdomadaire") -with(tail(data, 200), plot(date, inc, type="l", xlab="Date", ylab="Incidence hebdomadaire")) + 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) } + annees = 1992:2025 inc_annuelle = data.frame(annee = annees, incidence = sapply(annees, pic_annuel)) -head(inc_annuelle) -plot(inc_annuelle, type="p", xlab="Année", ylab="Incidence annuelle") + +print("--- Epidémie la plus FORTE ---") head(inc_annuelle[order(-inc_annuelle$incidence),]) -head(inc_annuelle[order(inc_annuelle$incidence),]) -hist(inc_annuelle$incidence, breaks=10, xlab="Incidence annuelle", ylab="Nb d'observations", main="") \ No newline at end of file + +print("--- Epidémie la plus FAIBLE ---") +head(inc_annuelle[order(inc_annuelle$incidence),]) \ No newline at end of file