Update exercice_R_fr.org

parent d94cf736
#+TITLE: Votre titre
#+AUTHOR: Votre nom
#+DATE: La date du jour
#+LANGUAGE: fr
# #+PROPERTY: header-args :eval never-export
# -*- mode: org -*-
# -*- coding: utf-8 -*-
#+STARTUP: overview indent inlineimages logdrawer
#+TITLE: Journal
#+AUTHOR: Put your name here
#+LANGUAGE: en
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/readtheorg/css/htmlize.css"/>
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/readtheorg/css/readtheorg.css"/>
......@@ -11,34 +12,27 @@
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/lib/js/jquery.stickytableheaders.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/readtheorg/js/readtheorg.js"></script>
* Quelques explications
Ceci est un document org-mode avec quelques exemples de code
R. Une fois ouvert dans emacs, ce document peut aisément être
exporté au format HTML, PDF, et Office. Pour plus de détails sur
org-mode vous pouvez consulter https://orgmode.org/guide/.
Lorsque vous utiliserez le raccourci =C-c C-e h o=, ce document sera
compilé en html. Tout le code contenu sera ré-exécuté, les résultats
récupérés et inclus dans un document final. Si vous ne souhaitez pas
ré-exécuter tout le code à chaque fois, il vous suffit de supprimer
le # et l'espace qui sont devant le ~#+PROPERTY:~ au début de ce
document.
Comme nous vous l'avons montré dans la vidéo, on inclut du code
R de la façon suivante (et on l'exécute en faisant ~C-c C-c~):
#+begin_src R :results output :exports both
print("Hello world!")
#+end_src
#+RESULTS:
: [1] "Hello world!"
Voici la même chose, mais avec une session R (c'est le cas le
plus courant, R étant vraiment un langage interactif), donc une
persistance d'un bloc à l'autre (et on l'exécute toujours en faisant
~C-c C-c~).
#+LATEX_HEADER: \usepackage[utf8]{inputenc}
#+LATEX_HEADER: \usepackage[T1]{fontenc}
#+LATEX_HEADER: \usepackage[a4paper,margin=.8in]{geometry}
#+LATEX_HEADER: \usepackage[french]{babel}
#+TAGS: LIG(L) HOME(H) Europe(E) Blog(B) noexport(n) Stats(S)
#+TAGS: Epistemology(E) Vulgarization(V) Teaching(T) R(R) OrgMode(O) Python(P)
#+EXPORT_SELECT_TAGS: Blog
#+OPTIONS: H:3 num:t toc:t \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
#+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:t pri:nil tags:not-in-toc
#+EXPORT_SELECT_TAGS: export
#+EXPORT_EXCLUDE_TAGS: noexport
#+COLUMNS: %25ITEM %TODO %3PRIORITY %TAGS
#+SEQ_TODO: TODO(t!) STARTED(s!) WAITING(w@) APPT(a!) | DONE(d!) CANCELLED(c!) DEFERRED(f!)
* 2021
** 2021-03 mars
*** 2021-03-02 mardi
**** Premier pas avec org mode
-note1
-note2
#+begin_src R :results output :session *R* :exports both
summary(cars)
......@@ -53,32 +47,120 @@ summary(cars)
: 3rd Qu.:19.0 3rd Qu.: 56.00
: Max. :25.0 Max. :120.00
Et enfin, voici un exemple de sortie graphique:
#+begin_src R :results output graphics :file "./cars.png" :exports results :width 600 :height 400 :session *R*
#+begin_src R :results output graphics :file (org-babel-temp-file "figure" ".png") :exports both :width 600 :height 400 :session *R*
plot(cars)
#+end_src
#+RESULTS:
#+begin_src R :results output graphics :file (org-babel-temp-file "figure" ".png") :exports both :width 600 :height 400 :session *R*
plot(cars)
#+end_src
#+RESULTS:
[[file:./cars.png]]
Vous remarquerez le paramètre ~:exports results~ 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 changer ce paramètre
(indiquer ~both~) car l'objectif est que vos analyses de données soient
parfaitement transparentes pour être reproductibles.
Attention, la figure ainsi générée n'est pas stockée dans le document
org. C'est un fichier ordinaire, ici nommé ~cars.png~. N'oubliez pas
de le committer si vous voulez que votre analyse soit lisible et
compréhensible sur GitLab.
Enfin, pour les prochains exercices, nous ne vous fournirons pas
forcément de fichier de départ, ça sera à vous de le créer, par
exemple en repartant de ce document et de le commiter vers
gitlab. N'oubliez pas que nous vous fournissons dans les ressources de
ce MOOC une configuration avec un certain nombre de raccourcis
claviers permettant de créer rapidement les blocs de code R (en
faisant ~<r~ ou ~<R~ suivi de ~Tab~).
Maintenant, à vous de jouer! Vous pouvez effacer toutes ces
informations et les remplacer par votre document computationnel.
[[file:/tmp/babel-cFH86o/figureNFJuq7.png]]
#+begin_src python :results output :exports both
print("hello word")
#+end_src
#+RESULTS:
: hello word
#+begin_src python :results output :session :exports both
x=10
#+end_src
#+RESULTS:
#+begin_src python :results file :session :var matplot_lib_filename="foo.png") :exports both
import matplotlib.pyplot as plt
import numpy
x=numpy.linspace(-15,15)
plt.figure(figsize=(10,5))
plt.plot(x,numpy.cos(x)/x)
plt.tight_layout()
plt.savefig(matplot_lib_filename)
matplot_lib_filename
#+end_src
#+RESULTS:
[[file:foo.png]]
Entered on [2021-03-02 mar. 14:09]
[[file:~/org/journal.org::*Org-mode Babel (for literate programming)][Org-mode Babel (for literate programming)]]
*** 2021-03-03 mercredi
**** FUN MOOC reproductibility
***** Exercice 2.4
I worked on the Cars data from R, i trained myself on the usage of
orgmode en the realisation of a journal following the Mooc
recommendation.
Firts I create a csv file in R with the Cars data
#+begin_src R :results output :session *R* :exports both
data <- cars
write.csv(data, 'data_cars_exercice2_3.csv')
#+end_src
Then i load to make statistic on it, the goal here is
to see if the distance cross by a car is influenced by its speed.
#+begin_src R :results output graphics :file data_cars_graph.png :exports both :width 600 :height 400 :session *R*
data <- read.csv('data_cars_exercice2_3.csv')
scatter.smooth(x=data$speed, y=data$dist, main="Dist ~ Speed")
#+end_src
#+RESULTS:
file:data_cars_graph
Here the graph is almost a line, so it will be insteresting to made a
correlation analasys of this data
#+begin_src R :results output :session *R* :exports both
cor(data$speed, data$dist)
#+end_src
#+RESULTS:
: [1] 0.8068949
The correlation between speed and distance is high ( < 0.5) and
positive, which mean higher is the speed, higher will be the
distance. Now to be sure that my hypthesis is good i will apply a the
linear regression.
#+begin_src R :results output :session *R* :exports both
linearMod <- lm(dist ~ speed, data=data)
summary(linearMod)
#+end_src
#+RESULTS:
#+begin_example
Call:
lm(formula = dist ~ speed, data = data)
Residuals:
Min 1Q Median 3Q Max
-29.069 -9.525 -2.272 9.215 43.201
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -17.5791 6.7584 -2.601 0.0123 *
speed 3.9324 0.4155 9.464 1.49e-12 ***
---
codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 15.38 on 48 degrees of freedom
Multiple R-squared: 0.6511, Adjusted R-squared: 0.6438
F-statistic: 89.57 on 1 and 48 DF, p-value: 1.49e-12
#+end_example
LinearMod, both these p-Values are well below the 0.05
threshold, so I can conclude our model is indeed statistically
significant, which mean, now i'm sure that the speed influence the distance
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