Commit 4c4693bf authored by Ana Sodan's avatar Ana Sodan

Exercice 2 module 3

parent 870905c4
---
title: "Analyse de l'incidence su syndrôme grippal"
author: '*Ana Sodan*'
date: "08/05/2020"
output: html_document
editor_options:
chunk_output_type: inline
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
data_url="https://www.sentiweb.fr/datasets/incidence-PAY-3.csv"
```
```{r}
data_file="syndrome-grippal.csv"
if(!file.exists(data_file)){download.file(data_url,data_file,method="auto")}
```
```{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}
library(parsedate)
```
```{r}
convert_week=function(date){ ws=paste(date)
iso=paste0(substring(ws,1,4),"-W",substring(ws,5,6))
as.character(parse_iso_8601(iso))}
```
```{r}
data$date=as.Date(sapply(data$week,convert_week))
```
```{r}
class(data$date)
```
```{r}
data=data[order(data$date),]
```
```{r}
head(data)
```
Pour vérifier que la distance entre deux dates est bien 7 jours
```{r}
all(diff(data$date)==7)
```
```{r}
with(data,plot(date,inc,type="l"))
```
On peut appliquer cela juste sur les dernières données. Exemple sur les 200 dernières.
```{r}
with(tail(data,200),plot(date,inc,type="l"))
```
```{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}
annees=1986:2019
```
```{r}
incidence_annuelle=data.frame(annee=annees,incidence=sapply(annees,pic_annuel))
```
```{r}
head(incidence_annuelle)
```
```{r}
plot(incidence_annuelle,"p")
```
```{r}
head(incidence_annuelle[order(-incidence_annuelle$incidence),])
```
Dans Hist Breaks signifie le nombre de barres que l'on veut avoir.
```{r}
hist(incidence_annuelle$incidence,breaks=10)
```
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