From 1b02b77aa147f7e57d34bffa22970ade418b5e03 Mon Sep 17 00:00:00 2001 From: feee8ecec645c53ceeda57e948ea51be Date: Tue, 7 Sep 2021 20:51:02 +0000 Subject: [PATCH] Update influenza-like-illness-analysis.Rmd --- .../exo1/influenza-like-illness-analysis.Rmd | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/module3/exo1/influenza-like-illness-analysis.Rmd b/module3/exo1/influenza-like-illness-analysis.Rmd index 8047fa0..edc2ac5 100644 --- a/module3/exo1/influenza-like-illness-analysis.Rmd +++ b/module3/exo1/influenza-like-illness-analysis.Rmd @@ -1,16 +1,16 @@ --- title: "Incidence of influenza-like illness in France" -author: "Konrad Hinsen" +author: "Eleni Gkiouzepi" output: - pdf_document: - toc: true html_document: toc: true theme: journal + pdf_document: + toc: true documentclass: article classoption: a4paper header-includes: -- \usepackage[french]{babel} +- \usepackage[english]{babel} - \usepackage[upright]{fourier} - \hypersetup{colorlinks=true,pagebackref=true} --- @@ -41,11 +41,25 @@ This is the documentation of the data from [the download site](https://ns.sentiw | `geo_insee` | Identifier of the geographic area, from INSEE https://www.insee.fr | | `geo_name` | Geographic label of the area, corresponding to INSEE code. This label is not an id and is only provided for human reading | -### Download +### If the local file does not exist, download the data and put them into the local file + +```{r} +destfile = "incidence-PAY-3.csv" + +if(!file.exists(destfile)){ + res <- tryCatch(download.file(data_url, + destfile, + method="auto"), + error=function(e) 1) +} +``` + +### Read the local CSV file. The first line of the CSV file is a comment, which we ignore with `skip=1`. + ```{r} -data = read.csv(data_url, skip=1) +data = read.csv(destfile, skip=1) ``` Let's have a look at what we got: @@ -72,7 +86,8 @@ Integers, fine! Date handling is always a delicate subject. There are many conventions that are easily confused. Our dataset uses the [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601) week number format, which is popular in Europe but less so in North America. In `R`, it is handled by the library [parsedate](https://cran.r-project.org/package=parsedate): ```{r} -library(parsedate) +if(!require(parsedate)) install.packages("parsedate") + require(parsedate) ``` In order to facilitate the subsequent treatment, we replace the ISO week numbers by the dates of each week's Monday. This function does it for one value: @@ -161,5 +176,6 @@ head(annnual_inc[order(-annnual_inc$incidence),]) Finally, a histogram clearly shows the few very strong epidemics, which affect about 10% of the French population, but are rare: there were three of them in the course of 35 years. The typical epidemic affects only half as many people. ```{r} -hist(annnual_inc$incidence, breaks=10, xlab="Annual incidence", ylab="Number of observations", main="") +hist(annnual_inc$incidence, breaks=10, xlab="Annual incidence", + ylab="Number of observations", main="") ``` -- 2.18.1