Update exercice_fr.Rmd

parent db82b1b4
--- ---
title: "Analyse de l'incidence de la varicelle" title: "Analyse de la varicelle"
author: "HYC" output: html_document
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}
--- ---
```{r} ```{r}
knitr::opts_chunk$set(echo = TRUE) 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" 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("-")) 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) library(parsedate)
convert_week = function(w) { convert_week = function(w) {
ws = paste(w) ws = paste(w)
iso = paste0(substring(ws, 1, 4), "-W", substring(ws, 5, 6)) iso = paste0(substring(ws, 1, 4), "-W", substring(ws, 5, 6))
as.character(parse_iso_8601(iso)) as.character(parse_iso_8601(iso))
} }
data$date = as.Date(convert_week(data$week)) data$date = as.Date(convert_week(data$week))
class(data$date)
data = data[order(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) { pic_annuel = function(annee) {
debut = paste0(annee-1,"-09-01") debut = paste0(annee-1,"-09-01")
fin = paste0(annee,"-09-01") fin = paste0(annee,"-09-01")
semaines = data$date > debut & data$date <= fin semaines = data$date > debut & data$date <= fin
sum(data$inc[semaines], na.rm=TRUE) sum(data$inc[semaines], na.rm=TRUE)
} }
annees = 1992:2025 annees = 1992:2025
inc_annuelle = data.frame(annee = annees, incidence = sapply(annees, pic_annuel)) 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),])
head(inc_annuelle[order(inc_annuelle$incidence),])
hist(inc_annuelle$incidence, breaks=10, xlab="Incidence annuelle", ylab="Nb d'observations", main="") print("--- Epidémie la plus FAIBLE ---")
\ No newline at end of file head(inc_annuelle[order(inc_annuelle$incidence),])
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment