Skip to content

Commit

Permalink
Correction quiz
Browse files Browse the repository at this point in the history
  • Loading branch information
appariciop committed Aug 13, 2024
1 parent 44f0222 commit dbb57d5
Show file tree
Hide file tree
Showing 22 changed files with 377 additions and 293 deletions.
20 changes: 10 additions & 10 deletions 03-MethodesRepartitionPonctuelle.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -956,10 +956,10 @@ library(spatstat)
library(ggplot2)
## Indice du plus proche voisin : R observé (équation 3.20)
# le paramètre k indique le nombre de plus proches voisins
Robs2019 <- mean(nndist(st_coordinates(M2019),k=1))
Robs2020 <- mean(nndist(st_coordinates(M2020),k=1))
Robs2021 <- mean(nndist(st_coordinates(M2021),k=1))
Robs2022 <- mean(nndist(st_coordinates(M2022),k=1))
Robs2019 <- mean(nndist(st_coordinates(M2019), k=1))
Robs2020 <- mean(nndist(st_coordinates(M2020), k=1))
Robs2021 <- mean(nndist(st_coordinates(M2021), k=1))
Robs2022 <- mean(nndist(st_coordinates(M2022), k=1))
## Indice du plus proche voisin : R attendu (distribution aléatoire) (équation 3.21)
# Attention, il faut spéficier S, la superficie de l'espace d'étude
Arrondissements <- st_read(dsn = "data/chap03/Arrondissements.shp", quiet=TRUE)
Expand Down Expand Up @@ -1227,7 +1227,7 @@ S <- as.numeric(st_area(st_union(Arrondissements)))
Sq <- (2*S) / npoints
# Longueur du carré et du côté de l'hexagone régulier (équation 3.25)
lq <- sqrt(Sq)
la <- sqrt( (2*Sq) / (3*sqrt(3)))
la <- sqrt((2*Sq) / (3*sqrt(3)))
# Trouver la longueur du côté du carré dans lequel est compris l'hexagone
cellsizeHex <- 2 * sqrt(Sq/((3*sqrt(3)/2))) * sqrt(3)/2
cat("Nombre de points =", npoints,
Expand Down Expand Up @@ -1284,12 +1284,12 @@ La figure ci-dessus permet de constater que certains carrés et hexagones n'inte
RequeteSpatiale <- st_intersects(Carres.sf,
st_union(Arrondissements), sparse = FALSE)
Carres.sf$Intersect <- RequeteSpatiale[, 1]
Carres.sf <- Carres.sf[Carres.sf$Intersect== TRUE, ]
Carres.sf <- Carres.sf[Carres.sf$Intersect == TRUE, ]
## Suppression des hexagones qui n'intersectent pas les quatre arrondissements
RequeteSpatiale <- st_intersects(Hexagones.sf,
st_union(Arrondissements), sparse = FALSE)
Hexagones.sf$Intersect <- RequeteSpatiale[, 1]
Hexagones.sf <- Hexagones.sf[Hexagones.sf$Intersect== TRUE, ]
Hexagones.sf <- Hexagones.sf[Hexagones.sf$Intersect == TRUE, ]
## Jointure spatiale : compter le nombre de méfaits de 2020 dans les carrés et les hexagones
Carres.sf$Mefaits2020 = lengths(st_intersects(Carres.sf, M2020))
Hexagones.sf$Mefaits2020 = lengths(st_intersects(Hexagones.sf, M2020))
Expand Down Expand Up @@ -1338,7 +1338,7 @@ Nous pouvons maintenant construire le tableau de fréquences et mettre en œuvre
#| warning: false
## Construction du tableau de fréquences
TabFreq <- as.data.frame(table(Carres.sf$Mefaits2020))
names(TabFreq) <- c("Npoints","Fo")
names(TabFreq) <- c("Npoints", "Fo")
TabFreq$Npoints <- as.numeric(as.character(TabFreq$Npoints))
# Calcul pour les fréquences observées (fo)
TabFreq$Fo.pro <- TabFreq$Fo / sum(TabFreq$Fo)
Expand All @@ -1347,8 +1347,8 @@ TabFreq$Fo.proCum <- cumsum(TabFreq$Fo.pro)
npoints <- sum(TabFreq$Npoints*TabFreq$Fo)
nquadrats <- sum(TabFreq$Fo)
Lambda <- npoints / nquadrats
TabFreq$Ft.pro <- dpois(TabFreq$Npoints, lambda= Lambda)
TabFreq$Ft.proCum <- ppois(TabFreq$Npoints, lambda= Lambda, lower.tail = TRUE)
TabFreq$Ft.pro <- dpois(TabFreq$Npoints, lambda = Lambda)
TabFreq$Ft.proCum <- ppois(TabFreq$Npoints, lambda = Lambda, lower.tail = TRUE)
TabFreq$Ft <- TabFreq$Ft.pro * TabFreq$Npoints
# Différences absolues entre les fréquences observées et théoriques cumulées
TabFreq$Difffoft <- abs(TabFreq$Fo.proCum - TabFreq$Ft.proCum)
Expand Down
1 change: 1 addition & 0 deletions 07-RegressionSpatiales.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ Avec la fonction `lm()`, il est facile de construire un modèle de régression l
#| echo: true
#| message: false
#| eval: true
#| warning: false
# Appel des différents packages utilisés dans le chapitre
library(spdep)
## Construction du modèle
Expand Down
6 changes: 3 additions & 3 deletions data/chap01/export/Carte1.html

Large diffs are not rendered by default.

Binary file modified data/chap01/export/Carte1.pdf
Binary file not shown.
Binary file modified data/chap01/export/Data.gpkg
Binary file not shown.
Binary file modified data/chap01/export/PointsGPS.dbf
Binary file not shown.
89 changes: 89 additions & 0 deletions data/chap01/export/PointsGPS.geojson

Large diffs are not rendered by default.

Binary file modified data/chap05/_DataReseau/GTFS_clients.zip
Binary file not shown.
34 changes: 17 additions & 17 deletions docs/01-ManipulationDonneesSpatiales.html

Large diffs are not rendered by default.

144 changes: 72 additions & 72 deletions docs/02-Autocorrelation.html
Original file line number Diff line number Diff line change
Expand Up @@ -2242,7 +2242,7 @@ <h1 class="title"><span id="sec-chap02" class="quarto-section-identifier"><span
<div class="sourceCode" id="cb56"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="co">## Valeurs permutées</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/base/print.html">print</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/sample.html">sample</a></span><span class="op">(</span><span class="va">Carres</span><span class="op">$</span><span class="va">CasA</span><span class="op">)</span><span class="op">)</span></span></code><button title="Copier vers le presse-papier" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code> [1] 0 0 0 0 0 1 0 0 0 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 1 1 0 0 0 0</code></pre>
<pre><code> [1] 1 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 1 0 1 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 0</code></pre>
</div>
</div>
</div>
Expand Down Expand Up @@ -2363,7 +2363,7 @@ <h1 class="title"><span id="sec-chap02" class="quarto-section-identifier"><span
alternative hypothesis: greater
sample estimates:
mean of simulation variance of simulation
162.2823 110.6858
162.5606 103.3648


Monte-Carlo simulation of join-count statistic
Expand All @@ -2377,7 +2377,7 @@ <h1 class="title"><span id="sec-chap02" class="quarto-section-identifier"><span
alternative hypothesis: greater
sample estimates:
mean of simulation variance of simulation
214.4114 132.9979 </code></pre>
214.4314 134.7405 </code></pre>
</div>
</div>
<p>L’approche d’inférence basée sur les permutations signale aussi que les deux distributions sont significativement autocorrélées spatialement (<em>p</em>&nbsp;=&nbsp;0,001).</p>
Expand Down Expand Up @@ -2409,104 +2409,104 @@ <h1 class="title"><span id="sec-chap02" class="quarto-section-identifier"><span
</tr></thead>
<tbody>
<tr class="odd">
<td style="text-align: center;">0,79</td>
<td style="text-align: center;">-0,56</td>
<td style="text-align: center;">0,69</td>
<td style="text-align: center;">3,83</td>
</tr>
<tr class="even">
<td style="text-align: center;">1,48</td>
<td style="text-align: center;">4,90</td>
<td style="text-align: center;">0,30</td>
<td style="text-align: center;">3,25</td>
</tr>
<tr class="odd">
<td style="text-align: center;">-4,16</td>
<td style="text-align: center;">-18,25</td>
<td style="text-align: center;">-0,75</td>
<td style="text-align: center;">-1,85</td>
</tr>
<tr class="even">
<td style="text-align: center;">1,58</td>
<td style="text-align: center;">9,92</td>
<td style="text-align: center;">0,72</td>
<td style="text-align: center;">4,07</td>
</tr>
<tr class="odd">
<td style="text-align: center;">0,03</td>
<td style="text-align: center;">-2,25</td>
<td style="text-align: center;">1,23</td>
<td style="text-align: center;">6,90</td>
</tr>
<tr class="even">
<td style="text-align: center;">2,77</td>
<td style="text-align: center;">2,31</td>
<td style="text-align: center;">-1,36</td>
<td style="text-align: center;">1,00</td>
</tr>
<tr class="odd">
<td style="text-align: center;">2,42</td>
<td style="text-align: center;">6,16</td>
<td style="text-align: center;">0,86</td>
<td style="text-align: center;">3,83</td>
</tr>
<tr class="even">
<td style="text-align: center;">-0,08</td>
<td style="text-align: center;">-5,05</td>
<td style="text-align: center;">0,63</td>
<td style="text-align: center;">3,32</td>
</tr>
<tr class="odd">
<td style="text-align: center;">-2,31</td>
<td style="text-align: center;">-6,05</td>
<td style="text-align: center;">-1,02</td>
<td style="text-align: center;">0,95</td>
</tr>
<tr class="even">
<td style="text-align: center;">0,02</td>
<td style="text-align: center;">2,32</td>
<td style="text-align: center;">1,17</td>
<td style="text-align: center;">3,80</td>
</tr>
<tr class="odd">
<td style="text-align: center;">-1,76</td>
<td style="text-align: center;">-7,36</td>
<td style="text-align: center;">1,39</td>
<td style="text-align: center;">8,01</td>
</tr>
<tr class="even">
<td style="text-align: center;">-0,82</td>
<td style="text-align: center;">-3,04</td>
<td style="text-align: center;">2,04</td>
<td style="text-align: center;">8,17</td>
</tr>
<tr class="odd">
<td style="text-align: center;">0,28</td>
<td style="text-align: center;">3,40</td>
<td style="text-align: center;">0,25</td>
<td style="text-align: center;">2,35</td>
</tr>
<tr class="even">
<td style="text-align: center;">-0,23</td>
<td style="text-align: center;">3,94</td>
<td style="text-align: center;">-0,92</td>
<td style="text-align: center;">-3,82</td>
</tr>
<tr class="odd">
<td style="text-align: center;">1,03</td>
<td style="text-align: center;">4,55</td>
<td style="text-align: center;">1,89</td>
<td style="text-align: center;">8,82</td>
</tr>
<tr class="even">
<td style="text-align: center;">-3,66</td>
<td style="text-align: center;">-12,05</td>
<td style="text-align: center;">-1,78</td>
<td style="text-align: center;">-5,34</td>
</tr>
<tr class="odd">
<td style="text-align: center;">2,14</td>
<td style="text-align: center;">5,28</td>
<td style="text-align: center;">-1,54</td>
<td style="text-align: center;">-5,72</td>
</tr>
<tr class="even">
<td style="text-align: center;">0,25</td>
<td style="text-align: center;">0,48</td>
<td style="text-align: center;">-1,97</td>
<td style="text-align: center;">-11,30</td>
</tr>
<tr class="odd">
<td style="text-align: center;">2,76</td>
<td style="text-align: center;">9,60</td>
<td style="text-align: center;">3,47</td>
<td style="text-align: center;">14,86</td>
</tr>
<tr class="even">
<td style="text-align: center;">-0,08</td>
<td style="text-align: center;">-1,61</td>
<td style="text-align: center;">1,56</td>
<td style="text-align: center;">10,70</td>
</tr>
<tr class="odd">
<td style="text-align: center;">-1,29</td>
<td style="text-align: center;">-7,83</td>
<td style="text-align: center;">2,03</td>
<td style="text-align: center;">6,37</td>
</tr>
<tr class="even">
<td style="text-align: center;">0,30</td>
<td style="text-align: center;">-0,40</td>
<td style="text-align: center;">2,37</td>
<td style="text-align: center;">5,46</td>
</tr>
<tr class="odd">
<td style="text-align: center;">-0,87</td>
<td style="text-align: center;">-3,53</td>
<td style="text-align: center;">1,55</td>
<td style="text-align: center;">10,17</td>
</tr>
<tr class="even">
<td style="text-align: center;">-1,47</td>
<td style="text-align: center;">-1,26</td>
<td style="text-align: center;">5,32</td>
<td style="text-align: center;">22,36</td>
</tr>
<tr class="odd">
<td style="text-align: center;">3,18</td>
<td style="text-align: center;">16,63</td>
<td style="text-align: center;">1,41</td>
<td style="text-align: center;">4,75</td>
</tr>
</tbody>
</table>
Expand Down Expand Up @@ -2974,26 +2974,26 @@ <h1 class="title"><span id="sec-chap02" class="quarto-section-identifier"><span
<div class="sourceCode" id="cb80"><pre class="downlit sourceCode r code-with-copy"><code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/r/base/summary.html">summary</a></span><span class="op">(</span><span class="va">localMoranI.mc</span><span class="op">)</span></span></code><button title="Copier vers le presse-papier" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code> Ii E.Ii Var.Ii Z.Ii
Min. :-0.90053 Min. :-0.060602 Min. :0.0000002 Min. :-2.0071
1st Qu.: 0.08313 1st Qu.:-0.009582 1st Qu.:0.0384774 1st Qu.: 0.4595
Median : 0.49029 Median :-0.001492 Median :0.1338059 Median : 1.4115
Mean : 0.61678 Mean :-0.003182 Mean :0.2176718 Mean : 1.2387
3rd Qu.: 0.97602 3rd Qu.: 0.003631 3rd Qu.:0.2659243 3rd Qu.: 2.1448
Max. : 3.37625 Max. : 0.076793 Max. :1.8333592 Max. : 3.8502
Pr(z != E(Ii)) Pr(z != E(Ii)) Sim Pr(folded) Sim Skewness
Min. :0.000118 Min. :0.0020 Min. :0.0010 Min. :-0.41115
1st Qu.:0.031970 1st Qu.:0.0240 1st Qu.:0.0120 1st Qu.:-0.23013
Median :0.126484 Median :0.1340 Median :0.0670 Median :-0.09598
Mean :0.249030 Mean :0.2549 Mean :0.1275 Mean :-0.01717
3rd Qu.:0.389883 3rd Qu.:0.4020 3rd Qu.:0.2010 3rd Qu.: 0.21404
Max. :0.991627 Max. :0.9980 Max. :0.4990 Max. : 0.43140
Min. :-0.90053 Min. :-0.066253 Min. :0.0000003 Min. :-1.9937
1st Qu.: 0.08313 1st Qu.:-0.010162 1st Qu.:0.0376542 1st Qu.: 0.4443
Median : 0.49029 Median :-0.001633 Median :0.1326308 Median : 1.4322
Mean : 0.61678 Mean :-0.004317 Mean :0.2163282 Mean : 1.2424
3rd Qu.: 0.97602 3rd Qu.: 0.003903 3rd Qu.:0.2600487 3rd Qu.: 2.1688
Max. : 3.37625 Max. : 0.037456 Max. :1.8514704 Max. : 3.8646
Pr(z != E(Ii)) Pr(z != E(Ii)) Sim Pr(folded) Sim Skewness
Min. :0.0001113 Min. :0.0020 Min. :0.0010 Min. :-0.392043
1st Qu.:0.0300950 1st Qu.:0.0220 1st Qu.:0.0110 1st Qu.:-0.216534
Median :0.1324638 Median :0.1340 Median :0.0670 Median :-0.094277
Mean :0.2491768 Mean :0.2538 Mean :0.1269 Mean :-0.006866
3rd Qu.:0.4064456 3rd Qu.:0.4120 3rd Qu.:0.2060 3rd Qu.: 0.222448
Max. :0.9896398 Max. :0.9720 Max. :0.4860 Max. : 0.427961
Kurtosis
Min. :-0.49934
1st Qu.:-0.27116
Median :-0.17963
Mean :-0.16986
3rd Qu.:-0.08581
Max. : 0.43309 </code></pre>
Min. :-0.60083
1st Qu.:-0.28631
Median :-0.18068
Mean :-0.17267
3rd Qu.:-0.07309
Max. : 0.31386 </code></pre>
</div>
</div>
<p>Avec la cartographie du <em>I</em> de Moran local, nous repérons localement l’autocorrélation spatiale positive (valeurs similaires, fortes ou faibles localement) et l’autocorrélation spatiale négative (valeurs dissemblables localement) (<a href="#fig-Chap02CartoIMoranLocal">figure&nbsp;<span>2.28</span></a>).</p>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/02-Autocorrelation_files/figure-html/fig-ExMapBivar-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/02-Autocorrelation_files/figure-html/fig-localLeeMaps-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit dbb57d5

Please sign in to comment.