...
 
Commits (42)
# Partie 1
## Sous-partie 1 : texte
Une phrase sans rien
*Une phrase en italique*
**Une phrase en gras**
Un lien vers (http://fun-mooc.fr)
Une ligne de `code`
## Sous-partie 2 : listes
**Liste à puce**
- item
- sous-item
- sous-item
- item
- item
**Liste numérotée**
1. item
2. item
3. item
## Sous-partie 3 : code
```
# Extrait de code
```
\ No newline at end of file
---
title: "Your title"
author: "Your name"
date: "Today's date"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Some explanations
This is an R Markdown document that you can easily export to HTML, PDF, and MS Word formats. For more information on R Markdown, see <http://rmarkdown.rstudio.com>.
When you click on the button **Knit**, the document will be compiled in order to re-execute the R code and to include the results into the final document. As we have shown in the video, R code is inserted as follows:
```{r cars}
summary(cars)
```
It is also straightforward to include figures. For example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Note the parameter `echo = FALSE` that indicates that the code will not appear in the final version of the document. We recommend not to use this parameter in the context of this MOOC, because we want your data analyses to be perfectly transparent and reproducible.
Since the results are not stored in Rmd files, you should generate an HTML or PDF version of your exercises and commit them. Otherwise reading and checking your analysis will be difficult for anyone else but you.
Now it's your turn! You can delete all this information and replace it by your computational document.
--- ---
title: "Votre titre" title: "On the computation of pi"
author: "Votre nom" author: "Tegegne"
date: "La date du jour" date: "14 june 2020"
output: html_document output: html_document
--- ---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```{r setup, include=FALSE} ```
knitr::opts_chunk$set(echo = TRUE) ## Asking the maths library
``` My computer tells me that $\pi$ is *approximatively*
```{r}
## Quelques explications pi
```
Ceci est un document R markdown que vous pouvez aisément exporter au format HTML, PDF, et MS Word. Pour plus de détails sur R Markdown consultez <http://rmarkdown.rstudio.com>. ## Buffon's needle
Applying the method of [Buffon's needle](https://en.wikipedia.org/wiki/Buffon%27s_needle_problem), we get the __approximation__
Lorsque vous cliquerez sur le bouton **Knit** ce document sera compilé afin de ré-exécuter le code R et d'inclure les résultats dans un document final. Comme nous vous l'avons montré dans la vidéo, on inclue du code R de la façon suivante: ```{r}
set.seed(42)
```{r cars} N = 100000
summary(cars) x = runif(N)
``` theta = pi/2*runif(N)
2/(mean(x+sin(theta)>1))
Et on peut aussi aisément inclure des figures. Par exemple: ```
## Using a surface fraction argument
```{r pressure, echo=FALSE} A method that is easier to understand and does not make use of the $\sin$ function is based on the fact that if $X\sim U(0,1)$ and $Y\sim U(0,1)$, then $P[X^2+Y^2\leq 1] = \pi/4$ (see ["Monte Carlo method" on Wikipedia](https://en.wikipedia.org/wiki/Monte_Carlo_method)). The following code uses this approach:
plot(pressure) ```{r}
``` set.seed(42)
N = 1000
Vous remarquerez le paramètre `echo = FALSE` qui indique que le code ne doit pas apparaître dans la version finale du document. Nous vous recommandons dans le cadre de ce MOOC de ne pas utiliser ce paramètre car l'objectif est que vos analyses de données soient parfaitement transparentes pour être reproductibles. df = data.frame(X = runif(N), Y = runif(N))
df$Accept = (df$X**2 + df$Y**2 <=1)
Comme les résultats ne sont pas stockés dans les fichiers Rmd, pour faciliter la relecture de vos analyses par d'autres personnes, vous aurez donc intérêt à générer un HTML ou un PDF et à le commiter. library(ggplot2)
ggplot(df, aes(x=X,y=Y,color=Accept)) + geom_point(alpha=.2) + coord_fixed() + theme_bw()
Maintenant, à vous de jouer! Vous pouvez effacer toutes ces informations et les remplacer par votre document computationnel. ```
It is then straightforward to obtain a (not really good) approximation to $\pi$ by counting how many times, on average, $X^2 + Y^2$ is smaller than 1:
```{r}
4*mean(df$Accept)
```
--- ---
title: "Your title" title: "MR"
author: "Your name" author: "TEGEGNE"
date: "Today's date" date: "Today's date"
output: html_document output: html_document
--- ---
```{r}
df =c(14.0, 7.6, 11.2, 12.8, 12.5, 9.9, 14.9, 9.4, 16.9, 10.2, 14.9, 18.1, 7.3, 9.8, 10.9,12.2, 9.9, 2.9, 2.8, 15.4, 15.7, 9.7, 13.1, 13.2, 12.3, 11.7, 16.0, 12.4, 17.9, 12.2, 16.2, 18.7, 8.9, 11.9, 12.1, 14.6, 12.1, 4.7, 3.9, 16.9, 16.8, 11.3, 14.4, 15.7, 14.0, 13.6, 18.0, 13.6, 19.9, 13.7, 17.0, 20.5, 9.9, 12.5, 13.2, 16.1, 13.5, 6.3, 6.4, 17.6, 19.1, 12.8, 15.5, 16.3, 15.2, 14.6, 19.1, 14.4, 21.4, 15.1, 19.6, 21.7, 11.3, 15.0, 14.3, 16.8, 14.0, 6.8, 8.2, 19.9, 20.4, 14.6, 16.4, 18.7, 16.8, 15.8, 20.4, 15.8, 22.4, 16.2, 20.3, 23.4, 12.1, 15.5, 15.4, 18.4, 15.7, 10.2, 8.9, 21.0)
```
```{r setup, include=FALSE} ```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE) knitr::opts_chunk$set(echo = TRUE)
...@@ -16,14 +20,20 @@ This is an R Markdown document that you can easily export to HTML, PDF, and MS W ...@@ -16,14 +20,20 @@ This is an R Markdown document that you can easily export to HTML, PDF, and MS W
When you click on the button **Knit**, the document will be compiled in order to re-execute the R code and to include the results into the final document. As we have shown in the video, R code is inserted as follows: When you click on the button **Knit**, the document will be compiled in order to re-execute the R code and to include the results into the final document. As we have shown in the video, R code is inserted as follows:
```{r cars} ```{r}
summary(cars) summary(df)
```
```{r}
sd(df)
``` ```
It is also straightforward to include figures. For example: It is also straightforward to include figures. For example:
```{r pressure, echo=FALSE} ```{r}
plot(pressure) plot(df)
``` ```
Note the parameter `echo = FALSE` that indicates that the code will not appear in the final version of the document. We recommend not to use this parameter in the context of this MOOC, because we want your data analyses to be perfectly transparent and reproducible. Note the parameter `echo = FALSE` that indicates that the code will not appear in the final version of the document. We recommend not to use this parameter in the context of this MOOC, because we want your data analyses to be perfectly transparent and reproducible.
...@@ -31,3 +41,4 @@ Note the parameter `echo = FALSE` that indicates that the code will not appear i ...@@ -31,3 +41,4 @@ Note the parameter `echo = FALSE` that indicates that the code will not appear i
Since the results are not stored in Rmd files, you should generate an HTML or PDF version of your exercises and commit them. Otherwise reading and checking your analysis will be difficult for anyone else but you. Since the results are not stored in Rmd files, you should generate an HTML or PDF version of your exercises and commit them. Otherwise reading and checking your analysis will be difficult for anyone else but you.
Now it's your turn! You can delete all this information and replace it by your computational document. Now it's your turn! You can delete all this information and replace it by your computational document.
--- ---
title: "Your title" title: "MR"
author: "Your name" author: "TEGEGNE"
date: "Today's date" date: "June 16, 2020"
output: html_document output: html_document
--- ---
```{r}
df =c(14.0, 7.6, 11.2, 12.8, 12.5, 9.9, 14.9, 9.4, 16.9, 10.2, 14.9, 18.1, 7.3, 9.8, 10.9,12.2, 9.9, 2.9, 2.8, 15.4, 15.7, 9.7, 13.1, 13.2, 12.3, 11.7, 16.0, 12.4, 17.9, 12.2, 16.2, 18.7, 8.9, 11.9, 12.1, 14.6, 12.1, 4.7, 3.9, 16.9, 16.8, 11.3, 14.4, 15.7, 14.0, 13.6, 18.0, 13.6, 19.9, 13.7, 17.0, 20.5, 9.9, 12.5, 13.2, 16.1, 13.5, 6.3, 6.4, 17.6, 19.1, 12.8, 15.5, 16.3, 15.2, 14.6, 19.1, 14.4, 21.4, 15.1, 19.6, 21.7, 11.3, 15.0, 14.3, 16.8, 14.0, 6.8, 8.2, 19.9, 20.4, 14.6, 16.4, 18.7, 16.8, 15.8, 20.4, 15.8, 22.4, 16.2, 20.3, 23.4, 12.1, 15.5, 15.4, 18.4, 15.7, 10.2, 8.9, 21.0)
```
```{r setup, include=FALSE} ```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE) knitr::opts_chunk$set(echo = TRUE)
``` ```
## Some explanations
This is an R Markdown document that you can easily export to HTML, PDF, and MS Word formats. For more information on R Markdown, see <http://rmarkdown.rstudio.com>.
When you click on the button **Knit**, the document will be compiled in order to re-execute the R code and to include the results into the final document. As we have shown in the video, R code is inserted as follows:
```{r cars}
summary(cars)
```
It is also straightforward to include figures. For example: It is also straightforward to include figures. For example:
```{r pressure, echo=FALSE} ```{r}
plot(pressure) hist(df, ylim=c(0, 25), xlim=c(0, 25), col="Blue")
``` ```
Note the parameter `echo = FALSE` that indicates that the code will not appear in the final version of the document. We recommend not to use this parameter in the context of this MOOC, because we want your data analyses to be perfectly transparent and reproducible.
Since the results are not stored in Rmd files, you should generate an HTML or PDF version of your exercises and commit them. Otherwise reading and checking your analysis will be difficult for anyone else but you. ```{r}
plot(df, type="l", col="Blue")
```
Now it's your turn! You can delete all this information and replace it by your computational document.
--- ---
title: "Incidence of influenza-like illness in France" title: "Incidence of influenza-like illness in France"
author: "Konrad Hinsen" author: "Tegegne Henok Ayalew"
output: date: "6/15/2020"
pdf_document: output: html_document
toc: true
html_document:
toc: true toc: true
theme: journal theme: journal
documentclass: article documentclass: article
...@@ -13,7 +11,9 @@ header-includes: ...@@ -13,7 +11,9 @@ header-includes:
- \usepackage[french]{babel} - \usepackage[french]{babel}
- \usepackage[upright]{fourier} - \usepackage[upright]{fourier}
- \hypersetup{colorlinks=true,pagebackref=true} - \hypersetup{colorlinks=true,pagebackref=true}
--- ---
```{r setup, include=FALSE} ```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE) knitr::opts_chunk$set(echo = TRUE)
......
--- ---
title: "Your title" title: "Analysis of the incidence of chickenpox"
author: "Your name" author: "Tegegne Henok Ayalew"
date: "Today's date" date: "6/15/2020"
output: html_document output: html_document
--- toc: true
theme: journal
documentclass: article
classoption: a4paper
header-includes:
- \usepackage[french]{babel}
- \usepackage[upright]{fourier}
- \hypersetup{colorlinks=true,pagebackref=true}
---
```{r setup, include=FALSE} ```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE) knitr::opts_chunk$set(echo = TRUE)
``` ```
## Some explanations ## Data preprocessing
The data on the incidence of chickenpox are available from the Web site of the [Réseau Sentinelles](http://www.sentiweb.fr/). We download them as a file in CSV format, in which each line corresponds to a week in the observation period. Only the complete dataset, starting in 1984 and ending with a recent week, is available for download. The URL is:
```{r}
data_url = "http://www.sentiweb.fr/datasets/incidence-PAY-7.csv"
```
This is the documentation of the data from [the download site](https://www.sentiweb.fr/france/en/?page=table):
| Column name | Description |
|--------------+---------------------------------------------------------------------------------------------------------------------------|
| `week` | ISO8601 Yearweek number as numeric (year*100 + week nubmer) |
| `indicator` | Unique identifier of the indicator, see metadata document https://www.sentiweb.fr/meta.json |
| `inc` | Estimated incidence value for the time step, in the geographic level |
| `inc_low` | Lower bound of the estimated incidence 95% Confidence Interval |
| `inc_up` | Upper bound of the estimated incidence 95% Confidence Interval |
| `inc100` | Estimated rate incidence per 100,000 inhabitants |
| `inc100_low` | Lower bound of the estimated incidence 95% Confidence Interval |
| `inc100_up` | Upper bound of the estimated rate incidence 95% Confidence Interval |
| `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
The first line of the CSV file is a comment, which we ignore with `skip=1`.
```{r}
data = read.csv(data_url, skip=1)
```
Let's have a look at what we got:
```{r}
head(data)
tail(data)
```
Are there missing data points?
```{r}
na_records = apply(data, 1, function (x) any(is.na(x)))
data[na_records,]
```
The two relevant columns for us are `week` and `inc`. Let's verify their classes:
```{r}
class(data$week)
class(data$inc)
```
Integers, fine!
### Conversion of the week numbers
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)
```
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:
```{r}
convert_week = function(w) {
ws = paste(w)
iso = paste0(substring(ws, 1, 4), "-W", substring(ws, 5, 6))
as.character(parse_iso_8601(iso))
}
```
We apply it to all points, creating a new column `date` in our data frame:
```{r}
data$date = as.Date(convert_week(data$week))
```
This is an R Markdown document that you can easily export to HTML, PDF, and MS Word formats. For more information on R Markdown, see <http://rmarkdown.rstudio.com>. Let's check that is has class `Date`:
```{r}
class(data$date)
```
When you click on the button **Knit**, the document will be compiled in order to re-execute the R code and to include the results into the final document. As we have shown in the video, R code is inserted as follows: The points are in inverse chronological order, so it's preferable to sort them:
```{r}
data = data[order(data$date),]
```
```{r cars} That's a good occasion for another check: our dates should be separated by exactly seven days:
summary(cars) ```{r}
all(diff(data$date) == 7)
``` ```
It is also straightforward to include figures. For example: ### Inspection
```{r pressure, echo=FALSE} Finally we can look at a plot of our data!
plot(pressure) ```{r}
plot(data$date, data$inc, type="l", xlab="Date", ylab="Weekly incidence")
``` ```
Note the parameter `echo = FALSE` that indicates that the code will not appear in the final version of the document. We recommend not to use this parameter in the context of this MOOC, because we want your data analyses to be perfectly transparent and reproducible. A zoom on the last few years makes the peaks in winter stand out more clearly.
```{r}
with(tail(data, 200), plot(date, inc, type="l", xlab="Date", ylab="Weekly incidence"))
```
Since the results are not stored in Rmd files, you should generate an HTML or PDF version of your exercises and commit them. Otherwise reading and checking your analysis will be difficult for anyone else but you. ## Annual incidence
Now it's your turn! You can delete all this information and replace it by your computational document. ### Computation
Since the peaks of the epidemic happen in winter, near the transition between calendar years, we define the reference period for the annual incidence from August 1st of year $N$ to August 1st of year $N+1$. We label this period as year $N+1$ because the peak is always located in year $N+1$. The very low incidence in summer ensures that the arbitrariness of the choice of reference period has no impact on our conclusions.
The argument `na.rm=True` in the sum indicates that missing data points are removed. This is a reasonable choice since there is only one missing point, whose impact cannot be very strong.
```{r}
yearly_peak = function(year) {
debut = paste0(year-1,"-08-01")
fin = paste0(year,"-08-01")
semaines = data$date > debut & data$date <= fin
sum(data$inc[semaines], na.rm=TRUE)
}
```
We must also be careful with the first and last years of the dataset. The data start in October 1984, meaning that we don't have all the data for the peak attributed to the year 1985. We therefore exclude it from the analysis. For the same reason, we define 2018 as the final year. We can increase this value to 2019 only when all data up to July 2019 is available.
```{r}
years = 1986:2018
```
We make a new data frame for the annual incidence, applying the function `yearly_peak` to each year:
```{r}
annnual_inc = data.frame(year = years,
incidence = sapply(years, yearly_peak))
head(annnual_inc)
```
### Inspection
A plot of the annual incidences:
```{r}
plot(annnual_inc, type="p", xlab="Année", ylab="Annual incidence")
```
### Identification of the strongest epidemics
A list sorted by decreasing annual incidence makes it easy to find the most important ones:
```{r}
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="")
```
This diff is collapsed.
mooc-rr @ 8f611497
Subproject commit 8f6114973dbef9cddc474e7ad754b25cc78ae68e