--- title: "Your title" author: "Your name" date: "Today's date" output: html_document --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` ## On ouvre le fichier de données ```{r} varicelle <- read.csv(file = "C:/Users/Sarah Chabert/Documents/mooc-rr/module3/exo2/inc-7-PAY.csv", skip = 1) head(varicelle) tail(varicelle) "Est-ce qu'on a des points manquants ?" na_records = apply(varicelle, 1, function (x) any(is.na(x))) varicelle[na_records,] "On véirifie les classes des variables dont on a besoin" class(varicelle$week) class(varicelle$inc) ``` ## Conversion des numéros de la semaine ```{r} 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)) } varicelle$date = as.Date(convert_week(varicelle$week)) class(varicelle$week) varicelle = varicelle[order(varicelle$date),] all(diff(varicelle$date) == 7) ``` ## Inspection ```{r} plot(varicelle$date, varicelle$inc, type="l", xlab="Date", ylab="Incidence hebdomadaire") with(tail(varicelle, 200), plot(date, inc, type="l", xlab="Date", ylab="Incidence hebdomadaire")) ``` ## Incidence annuelle ```{r} pic_annuel = function(annee) { debut = paste0(annee-1,"-09-01") fin = paste0(annee,"-09-01") semaines = varicelle$date > debut & varicelle$date <= fin sum(varicelle$inc[semaines], na.rm=TRUE) } annees = 1991:2024 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") ``` ## Identification de l'épidémie la plus forte et la plus faible ```{r} head(inc_annuelle[order(-inc_annuelle$incidence),]) head(inc_annuelle[order(inc_annuelle$incidence),]) ```