Update exercice_R_fr.org

parent d94cf736
#+TITLE: Votre titre # -*- mode: org -*-
#+AUTHOR: Votre nom # -*- coding: utf-8 -*-
#+DATE: La date du jour #+STARTUP: overview indent inlineimages logdrawer
#+LANGUAGE: fr #+TITLE: Journal
# #+PROPERTY: header-args :eval never-export #+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/htmlize.css"/>
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/readtheorg/css/readtheorg.css"/> #+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/readtheorg/css/readtheorg.css"/>
...@@ -11,34 +12,27 @@ ...@@ -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/lib/js/jquery.stickytableheaders.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/readtheorg/js/readtheorg.js"></script> #+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/readtheorg/js/readtheorg.js"></script>
* Quelques explications #+LATEX_HEADER: \usepackage[utf8]{inputenc}
#+LATEX_HEADER: \usepackage[T1]{fontenc}
Ceci est un document org-mode avec quelques exemples de code #+LATEX_HEADER: \usepackage[a4paper,margin=.8in]{geometry}
R. Une fois ouvert dans emacs, ce document peut aisément être #+LATEX_HEADER: \usepackage[french]{babel}
exporté au format HTML, PDF, et Office. Pour plus de détails sur #+TAGS: LIG(L) HOME(H) Europe(E) Blog(B) noexport(n) Stats(S)
org-mode vous pouvez consulter https://orgmode.org/guide/. #+TAGS: Epistemology(E) Vulgarization(V) Teaching(T) R(R) OrgMode(O) Python(P)
#+EXPORT_SELECT_TAGS: Blog
Lorsque vous utiliserez le raccourci =C-c C-e h o=, ce document sera #+OPTIONS: H:3 num:t toc:t \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
compilé en html. Tout le code contenu sera ré-exécuté, les résultats #+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:t pri:nil tags:not-in-toc
récupérés et inclus dans un document final. Si vous ne souhaitez pas #+EXPORT_SELECT_TAGS: export
ré-exécuter tout le code à chaque fois, il vous suffit de supprimer #+EXPORT_EXCLUDE_TAGS: noexport
le # et l'espace qui sont devant le ~#+PROPERTY:~ au début de ce #+COLUMNS: %25ITEM %TODO %3PRIORITY %TAGS
document. #+SEQ_TODO: TODO(t!) STARTED(s!) WAITING(w@) APPT(a!) | DONE(d!) CANCELLED(c!) DEFERRED(f!)
Comme nous vous l'avons montré dans la vidéo, on inclut du code * 2021
R de la façon suivante (et on l'exécute en faisant ~C-c C-c~): ** 2021-03 mars
*** 2021-03-02 mardi
#+begin_src R :results output :exports both **** Premier pas avec org mode
print("Hello world!")
#+end_src -note1
-note2
#+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~).
#+begin_src R :results output :session *R* :exports both #+begin_src R :results output :session *R* :exports both
summary(cars) summary(cars)
...@@ -53,32 +47,120 @@ summary(cars) ...@@ -53,32 +47,120 @@ summary(cars)
: 3rd Qu.:19.0 3rd Qu.: 56.00 : 3rd Qu.:19.0 3rd Qu.: 56.00
: Max. :25.0 Max. :120.00 : Max. :25.0 Max. :120.00
Et enfin, voici un exemple de sortie graphique: #+begin_src R :results output graphics :file (org-babel-temp-file "figure" ".png") :exports both :width 600 :height 400 :session *R*
#+begin_src R :results output graphics :file "./cars.png" :exports results :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) plot(cars)
#+end_src #+end_src
#+RESULTS: #+RESULTS:
[[file:./cars.png]] [[file:/tmp/babel-cFH86o/figureNFJuq7.png]]
#+begin_src python :results output :exports both
Vous remarquerez le paramètre ~:exports results~ qui indique que le code print("hello word")
ne doit pas apparaître dans la version finale du document. Nous vous #+end_src
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 #+RESULTS:
parfaitement transparentes pour être reproductibles. : hello word
Attention, la figure ainsi générée n'est pas stockée dans le document #+begin_src python :results output :session :exports both
org. C'est un fichier ordinaire, ici nommé ~cars.png~. N'oubliez pas x=10
de le committer si vous voulez que votre analyse soit lisible et #+end_src
compréhensible sur GitLab.
#+RESULTS:
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 #+begin_src python :results file :session :var matplot_lib_filename="foo.png") :exports both
exemple en repartant de ce document et de le commiter vers import matplotlib.pyplot as plt
gitlab. N'oubliez pas que nous vous fournissons dans les ressources de
ce MOOC une configuration avec un certain nombre de raccourcis import numpy
claviers permettant de créer rapidement les blocs de code R (en x=numpy.linspace(-15,15)
faisant ~<r~ ou ~<R~ suivi de ~Tab~). plt.figure(figsize=(10,5))
plt.plot(x,numpy.cos(x)/x)
Maintenant, à vous de jouer! Vous pouvez effacer toutes ces plt.tight_layout()
informations et les remplacer par votre document computationnel.
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