diff --git a/07-basic_statistics.qmd b/07-basic_statistics.qmd
index 9f29e634d1ccca235d49b2af8accb9f09aa02479..cdfb0ecc8949c1504e63afd9b3b9ccc9720b4a1c 100644
--- a/07-basic_statistics.qmd
+++ b/07-basic_statistics.qmd
@@ -4,7 +4,7 @@ bibliography: references.bib
 
 # Basic statistics for spatial analysis
 
-This section aims at providing some basic statistical tools to study the spatial distribution of epidemiological data.
+This section aims at providing some basic statistical tools to study the spatial distribution of epidemiological data. If you wish to go further into these analysis and their limitations you can consult the tutorial "[Spatial Epidemiology](https://mkram01.github.io/EPI563-SpatialEPI/index.html)" from M. Kramer from which the statistical analysis of his section were adapted. 
 
 ## Import and visualize epidemiological data
 
@@ -222,20 +222,56 @@ For each district $i$, the Moran's statistics is :
 $$I_i = \frac{(Y_i-\bar{Y})}{\sum_{i=1}^N(Y_i-\bar{Y})^2}\sum_{j=1}^Nw_{ij}(Y_j - \bar{Y}) \text{ with }  I = \sum_{i=1}^NI_i/N$$
 :::
 
-The `localmoran()`function from the package `spdep` treats the variable of interest as if it was normally distributed. In some cases, this assumption could be reasonable for incidence rate, especially when the areal units of analysis have sufficiently large population count suggesting that the values have similar level of variances.
+The `localmoran()`function from the package `spdep` treats the variable of interest as if it was normally distributed. In some cases, this assumption could be reasonable for incidence rate, especially when the areal units of analysis have sufficiently large population count suggesting that the values have similar level of variances. Unfortunately, the local moran's test has not been implemented for poisson distribution (population not large enough in some districts) in `spdep` package. However Bivand **et al.** [@bivand2008applied] provided some code to manual perform the analysis using poisson distribution and was further implemented in the course "[Spatial Epidemiology](https://mkram01.github.io/EPI563-SpatialEPI/index.html)" .
+
+
 
 ```{r LocalMoransI, eval = TRUE, echo = TRUE, nm = TRUE, fig.width=8, class.output="code-out", warning=FALSE, message=FALSE}
 
-lm_test <- localmoran(x = district$incidence,
-                  listw = q_listw) 
+# Step 1 - Create the standardized deviation of observed from expected
+sd_lm <- (district$cases - district$expected) / sqrt(district$expected)
+
+# Step 2 - Create a spatially lagged version of standardized deviation of neighbors
+wsd_lm <- lag.listw(q_listw, sd_lm)
+
+# Step 3 - the local Moran's I is the product of step 1 and step 2
+district$I_lm <- sd_lm * wsd_lm
+
+# Step 4 - setup parameters for simulation of the null distribution
+
+# Specify number of simulations to run
+nsim <- 499
+
+# Specify dimensions of result based on number of regions
+N <- length(district$expected)
+
+# Create a matrix of zeros to hold results, with a row for each county, and a column for each simulation
+sims <- matrix(0, ncol = nsim, nrow = N)
+
+# Step 5 - Start a for-loop to iterate over simulation columns
+for(i in 1:nsim){
+  y <- rpois(N, lambda = district$expected) # generate a random event count, given expected
+  sd_lmi <- (y - district$expected) / sqrt(district$expected) # standardized local measure
+  wsd_lmi <- lag.listw(q_listw, sd_lmi) # standardized spatially lagged measure
+  sims[, i] <- sd_lmi * wsd_lmi # this is the I(i) statistic under this iteration of null
+}
 
-summary(lm_test)
+hist(sims[1,])
+# Step 6 - For each county, test where the observed value ranks with respect to the null simulations
+xrank <- apply(cbind(district$I_lm, sims), 1, function(x) rank(x)[1])
 
+# Step 7 - Calculate the difference between observed rank and total possible (nsim)
+diff <- nsim - xrank
+diff <- ifelse(diff > 0, diff, 0)
+
+# Step 8 - Assuming a uniform distribution of ranks, calculate p-value for observed
+# given the null distribution generate from simulations
+district$pval_lm <- punif((diff + 1) / (nsim + 1))
 ```
 
-`localmoran()`returns for each district fives outputs : the local moran indice $I_i$, the is the expected value of the Moran's I statistic under the null hypothesis $E_i$, the variance of each local moran's I statistics Var.Ii, the standardized deviation of the local Moran's I statistic Z.Ii and Pr(Z\>0) is the p-value.
+For each district, we obtain a p-value based on permutations process
 
-A conventional way of plotting these results is to classify the district into 5 classes based on local Moran's I outputs. Classification is performed based on a comparison of the scaled incidence in the district compared to the scaled weighted averaged incidence of it neighboring districts (computed with `lag.listw()`) :
+A conventional way of plotting these results is to classify the districts into 5 classes based on local Moran's I outputs. The classification of cluster that are significantly autocorrelated to their neighbors is performed based on a comparison of the scaled incidence in the district compared to the scaled weighted averaged incidence of it neighboring districts (computed with `lag.listw()`) :
 
 -    Districts that have higher-than-average rates in both index regions and their neighbors and showing statistically significant positive values for the local $I_i$ statistic are defined as __High-High__ (hotspot of the disease)
 
@@ -248,8 +284,6 @@ A conventional way of plotting these results is to classify the district into 5
 -   Districts with non-significant values for the $I_i$ statistic are defined as __Non-significant__.
 
 
-In this example, we adjusted for multiple testing using bonferroni correction, i.e. the p-value are multiplied by the number of tests. 
-
 ```{r LocalMoransI_plt, eval = TRUE, echo = TRUE, nm = TRUE, fig.width=8, class.output="code-out", warning=FALSE, message=FALSE}
 
 # create lagged local raw_rate - in other words the average of the queen neighbors value
@@ -257,8 +291,8 @@ In this example, we adjusted for multiple testing using bonferroni correction, i
 district$lag_std   <- scale(lag.listw(q_listw, var = district$incidence))
 district$incidence_std <- scale(district$incidence)
 
-# adjust for pvalues
-district$lm_pv <- p.adjust(lm_test[,5], "bonferroni")
+# extract pvalues
+# district$lm_pv <- lm_test[,5]
 
 # Classify local moran's outputs
 district$lm_class <- NA
@@ -266,7 +300,7 @@ district$lm_class[district$incidence_std >=0 & district$lag_std >=0] <- 'High-Hi
 district$lm_class[district$incidence_std <=0 & district$lag_std <=0] <- 'Low-Low'
 district$lm_class[district$incidence_std <=0 & district$lag_std >=0] <- 'Low-High'
 district$lm_class[district$incidence_std >=0 & district$lag_std <=0] <- 'High-Low'
-district$lm_class[district$lm_pv >= 0.5] <- 'Non-significant'
+district$lm_class[district$pval_lm >= 0.05] <- 'Non-significant'
 
 district$lm_class <- factor(district$lm_class, levels=c("High-High", "Low-Low", "High-Low",  "Low-High", "Non-significant") )
 
@@ -277,7 +311,7 @@ mf_map(x = district,
        cex = 2,
        col_na = "white",
        #val_order = c("High-High", "Low-Low", "High-Low",  "Low-High", "Non-significant") ,
-       pal = c("#6D0026" , "#7FABD3" , "white") , # "blue", "#FF755F",
+       pal = c("#6D0026" , "blue",  "white") , # "#FF755F","#7FABD3" ,
        leg_title = "Clusters")
 
 mf_layout(title = "Cluster using Local moran'I statistic")
@@ -286,6 +320,8 @@ mf_layout(title = "Cluster using Local moran'I statistic")
 
 ```
 
+
+
 ### Spatial scan statistics
 
 While Moran's indice focuses on testing for autocorrelation between neighboring polygons (under the null assumption of spatial independance), the spatial scan statistic aims at identifying an abnormal higher risk in a given region compared to the risk outside of this region (under the null assumption of homogeneous distribution). The conception of a cluster is therefore different between the two methods.
@@ -410,3 +446,8 @@ In this example, the expected number of cases was defined using the population c
 
 In addition, this cluster analysis was performed solely using the spatial scan but you should keep in mind that this method of cluster detection can be implemented for spatio-temporal data as well where the cluster definition is an abnormal number of cases in a delimited spatial area and during a given period of time. The windows of observation are therefore defined for a different center, radius and period of time. You should look at the function `scan_ep_poisson()` function in the package `scanstatistic` [@scanstatistics] for this analysis.
 :::
+
+
+
+
+
diff --git a/public/07-basic_statistics.html b/public/07-basic_statistics.html
index 49b818ad4c3768e45c005ec223b64ff18143d9b6..3e6528c54f888c18c6703dfba8cc9286da3f254c 100644
--- a/public/07-basic_statistics.html
+++ b/public/07-basic_statistics.html
@@ -268,7 +268,7 @@ div.csl-indent {
 
 </header>
 
-<p>This section aims at providing some basic statistical tools to study the spatial distribution of epidemiological data.</p>
+<p>This section aims at providing some basic statistical tools to study the spatial distribution of epidemiological data. If you wish to go further into these analysis and their limitations you can consult the tutorial “<a href="https://mkram01.github.io/EPI563-SpatialEPI/index.html">Spatial Epidemiology</a>” from M. Kramer from which the statistical analysis of his section were adapted.</p>
 <section id="import-and-visualize-epidemiological-data" class="level2" data-number="7.1">
 <h2 data-number="7.1" class="anchored" data-anchor-id="import-and-visualize-epidemiological-data"><span class="header-section-number">7.1</span> Import and visualize epidemiological data</h2>
 <p>In this section, we load data that reference the cases of an imaginary disease throughout Cambodia. Each point correspond to the geolocalisation of a case.</p>
@@ -464,7 +464,7 @@ Moran’s I test
 </ul>
 </div>
 </div>
-<p>We will compute the Moran’s statistics using <code>spdep</code><span class="citation" data-cites="spdep">(<a href="references.html#ref-spdep" role="doc-biblioref">Bivand et al. 2015</a>)</span> and <code>Dcluster</code><span class="citation" data-cites="DCluster">(<a href="references.html#ref-DCluster" role="doc-biblioref">Gómez-Rubio et al. 2015</a>)</span> packages. <code>spdep</code> package provides a collection of functions to analyze spatial correlations of polygons and works with sp objects. In this example, we use <code>poly2nb()</code> and <code>nb2listw()</code>. These function respectively detect the neighboring polygons and assign weight corresponding to <span class="math inline">\(1/\#\ of\ neighbors\)</span>. <code>Dcluster</code> package provides a set of functions for the detection of spatial clusters of disease using count data.</p>
+<p>We will compute the Moran’s statistics using <code>spdep</code><span class="citation" data-cites="spdep">(<a href="references.html#ref-spdep" role="doc-biblioref">R. Bivand et al. 2015</a>)</span> and <code>Dcluster</code><span class="citation" data-cites="DCluster">(<a href="references.html#ref-DCluster" role="doc-biblioref">Gómez-Rubio et al. 2015</a>)</span> packages. <code>spdep</code> package provides a collection of functions to analyze spatial correlations of polygons and works with sp objects. In this example, we use <code>poly2nb()</code> and <code>nb2listw()</code>. These function respectively detect the neighboring polygons and assign weight corresponding to <span class="math inline">\(1/\#\ of\ neighbors\)</span>. <code>Dcluster</code> package provides a set of functions for the detection of spatial clusters of disease using count data.</p>
 <div class="cell" data-nm="true">
 <div class="sourceCode cell-code" id="cb9"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(spdep) <span class="co"># Functions for creating spatial weight, spatial analysis</span></span>
 <span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(DCluster)  <span class="co"># Package with functions for spatial cluster analysis</span></span>
@@ -488,14 +488,14 @@ Moran’s I test
     Model used when sampling: Poisson 
     Number of simulations: 499 
     Statistic:  0.1566449 
-    p-value :  0.012 </code></pre>
+    p-value :  0.014 </code></pre>
 </div>
 <div class="sourceCode cell-code" id="cb11"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(m_test)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
 <div class="cell-output-display">
 <p><img src="07-basic_statistics_files/figure-html/MoransI-1.png" class="img-fluid" width="768"></p>
 </div>
 </div>
-<p>The Moran’s statistics is here <span class="math inline">\(I =\)</span> 0.16. When comparing its value to the H0 distribution (built under 499 simulations), the probability of observing such a I value under the null hypothesis, i.e.&nbsp;the distribution of cases is spatially independent, is <span class="math inline">\(p_{value} =\)</span> 0.012. We therefore reject H0 with error risk of <span class="math inline">\(\alpha = 5\%\)</span>. The distribution of cases is therefore autocorrelated across districts in Cambodia.</p>
+<p>The Moran’s statistics is here <span class="math inline">\(I =\)</span> 0.16. When comparing its value to the H0 distribution (built under 499 simulations), the probability of observing such a I value under the null hypothesis, i.e.&nbsp;the distribution of cases is spatially independent, is <span class="math inline">\(p_{value} =\)</span> 0.014. We therefore reject H0 with error risk of <span class="math inline">\(\alpha = 5\%\)</span>. The distribution of cases is therefore autocorrelated across districts in Cambodia.</p>
 </section>
 <section id="morans-i-local-test" class="level4" data-number="7.2.2.2">
 <h4 data-number="7.2.2.2" class="anchored" data-anchor-id="morans-i-local-test"><span class="header-section-number">7.2.2.2</span> Moran’s I local test</h4>
@@ -514,31 +514,53 @@ Statistical test
 <p><span class="math display">\[I_i = \frac{(Y_i-\bar{Y})}{\sum_{i=1}^N(Y_i-\bar{Y})^2}\sum_{j=1}^Nw_{ij}(Y_j - \bar{Y}) \text{ with }  I = \sum_{i=1}^NI_i/N\]</span></p>
 </div>
 </div>
-<p>The <code>localmoran()</code>function from the package <code>spdep</code> treats the variable of interest as if it was normally distributed. In some cases, this assumption could be reasonable for incidence rate, especially when the areal units of analysis have sufficiently large population count suggesting that the values have similar level of variances.</p>
+<p>The <code>localmoran()</code>function from the package <code>spdep</code> treats the variable of interest as if it was normally distributed. In some cases, this assumption could be reasonable for incidence rate, especially when the areal units of analysis have sufficiently large population count suggesting that the values have similar level of variances. Unfortunately, the local moran’s test has not been implemented for poisson distribution (population not large enough in some districts) in <code>spdep</code> package. However Bivand <strong>et al.</strong> <span class="citation" data-cites="bivand2008applied">(<a href="references.html#ref-bivand2008applied" role="doc-biblioref">R. S. Bivand et al. 2008</a>)</span> provided some code to manual perform the analysis using poisson distribution and was further implemented in the course “<a href="https://mkram01.github.io/EPI563-SpatialEPI/index.html">Spatial Epidemiology</a>” .</p>
 <div class="cell" data-nm="true">
-<div class="sourceCode cell-code" id="cb12"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a>lm_test <span class="ot">&lt;-</span> <span class="fu">localmoran</span>(<span class="at">x =</span> district<span class="sc">$</span>incidence,</span>
-<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a>                  <span class="at">listw =</span> q_listw) </span>
+<div class="sourceCode cell-code" id="cb12"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Step 1 - Create the standardized deviation of observed from expected</span></span>
+<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a>sd_lm <span class="ot">&lt;-</span> (district<span class="sc">$</span>cases <span class="sc">-</span> district<span class="sc">$</span>expected) <span class="sc">/</span> <span class="fu">sqrt</span>(district<span class="sc">$</span>expected)</span>
 <span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a></span>
-<span id="cb12-4"><a href="#cb12-4" aria-hidden="true" tabindex="-1"></a><span class="fu">summary</span>(lm_test)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
-<div class="cell-output cell-output-stdout">
-<pre class="code-out"><code>       Ii                E.Ii                Var.Ii              Z.Ii        
- Min.   :-2.23556   Min.   :-8.892e-02   Min.   :0.000008   Min.   :-4.0207  
- 1st Qu.:-0.04241   1st Qu.:-3.153e-03   1st Qu.:0.015478   1st Qu.:-0.3209  
- Median : 0.07664   Median :-2.853e-03   Median :0.085746   Median : 0.4380  
- Mean   : 0.15664   Mean   :-5.102e-03   Mean   :0.256203   Mean   : 0.3632  
- 3rd Qu.: 0.28011   3rd Qu.:-4.032e-04   3rd Qu.:0.152437   3rd Qu.: 1.0690  
- Max.   : 3.04441   Max.   :-2.400e-07   Max.   :5.265316   Max.   : 4.7356  
- Pr(z != E(Ii))     
- Min.   :0.0000022  
- 1st Qu.:0.2244163  
- Median :0.4315420  
- Mean   :0.4601943  
- 3rd Qu.:0.6979413  
- Max.   :0.9939022  </code></pre>
-</div>
-</div>
-<p><code>localmoran()</code>returns for each district fives outputs : the local moran indice <span class="math inline">\(I_i\)</span>, the is the expected value of the Moran’s I statistic under the null hypothesis <span class="math inline">\(E_i\)</span>, the variance of each local moran’s I statistics Var.Ii, the standardized deviation of the local Moran’s I statistic Z.Ii and Pr(Z&gt;0) is the p-value.</p>
-<p>A conventional way of plotting these results is to classify the district into 5 classes based on local Moran’s I outputs. Classification is performed based on a comparison of the scaled incidence in the district compared to the scaled weighted averaged incidence of it neighboring districts (computed with <code>lag.listw()</code>) :</p>
+<span id="cb12-4"><a href="#cb12-4" aria-hidden="true" tabindex="-1"></a><span class="co"># Step 2 - Create a spatially lagged version of standardized deviation of neighbors</span></span>
+<span id="cb12-5"><a href="#cb12-5" aria-hidden="true" tabindex="-1"></a>wsd_lm <span class="ot">&lt;-</span> <span class="fu">lag.listw</span>(q_listw, sd_lm)</span>
+<span id="cb12-6"><a href="#cb12-6" aria-hidden="true" tabindex="-1"></a></span>
+<span id="cb12-7"><a href="#cb12-7" aria-hidden="true" tabindex="-1"></a><span class="co"># Step 3 - the local Moran's I is the product of step 1 and step 2</span></span>
+<span id="cb12-8"><a href="#cb12-8" aria-hidden="true" tabindex="-1"></a>district<span class="sc">$</span>I_lm <span class="ot">&lt;-</span> sd_lm <span class="sc">*</span> wsd_lm</span>
+<span id="cb12-9"><a href="#cb12-9" aria-hidden="true" tabindex="-1"></a></span>
+<span id="cb12-10"><a href="#cb12-10" aria-hidden="true" tabindex="-1"></a><span class="co"># Step 4 - setup parameters for simulation of the null distribution</span></span>
+<span id="cb12-11"><a href="#cb12-11" aria-hidden="true" tabindex="-1"></a></span>
+<span id="cb12-12"><a href="#cb12-12" aria-hidden="true" tabindex="-1"></a><span class="co"># Specify number of simulations to run</span></span>
+<span id="cb12-13"><a href="#cb12-13" aria-hidden="true" tabindex="-1"></a>nsim <span class="ot">&lt;-</span> <span class="dv">499</span></span>
+<span id="cb12-14"><a href="#cb12-14" aria-hidden="true" tabindex="-1"></a></span>
+<span id="cb12-15"><a href="#cb12-15" aria-hidden="true" tabindex="-1"></a><span class="co"># Specify dimensions of result based on number of regions</span></span>
+<span id="cb12-16"><a href="#cb12-16" aria-hidden="true" tabindex="-1"></a>N <span class="ot">&lt;-</span> <span class="fu">length</span>(district<span class="sc">$</span>expected)</span>
+<span id="cb12-17"><a href="#cb12-17" aria-hidden="true" tabindex="-1"></a></span>
+<span id="cb12-18"><a href="#cb12-18" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a matrix of zeros to hold results, with a row for each county, and a column for each simulation</span></span>
+<span id="cb12-19"><a href="#cb12-19" aria-hidden="true" tabindex="-1"></a>sims <span class="ot">&lt;-</span> <span class="fu">matrix</span>(<span class="dv">0</span>, <span class="at">ncol =</span> nsim, <span class="at">nrow =</span> N)</span>
+<span id="cb12-20"><a href="#cb12-20" aria-hidden="true" tabindex="-1"></a></span>
+<span id="cb12-21"><a href="#cb12-21" aria-hidden="true" tabindex="-1"></a><span class="co"># Step 5 - Start a for-loop to iterate over simulation columns</span></span>
+<span id="cb12-22"><a href="#cb12-22" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span>(i <span class="cf">in</span> <span class="dv">1</span><span class="sc">:</span>nsim){</span>
+<span id="cb12-23"><a href="#cb12-23" aria-hidden="true" tabindex="-1"></a>  y <span class="ot">&lt;-</span> <span class="fu">rpois</span>(N, <span class="at">lambda =</span> district<span class="sc">$</span>expected) <span class="co"># generate a random event count, given expected</span></span>
+<span id="cb12-24"><a href="#cb12-24" aria-hidden="true" tabindex="-1"></a>  sd_lmi <span class="ot">&lt;-</span> (y <span class="sc">-</span> district<span class="sc">$</span>expected) <span class="sc">/</span> <span class="fu">sqrt</span>(district<span class="sc">$</span>expected) <span class="co"># standardized local measure</span></span>
+<span id="cb12-25"><a href="#cb12-25" aria-hidden="true" tabindex="-1"></a>  wsd_lmi <span class="ot">&lt;-</span> <span class="fu">lag.listw</span>(q_listw, sd_lmi) <span class="co"># standardized spatially lagged measure</span></span>
+<span id="cb12-26"><a href="#cb12-26" aria-hidden="true" tabindex="-1"></a>  sims[, i] <span class="ot">&lt;-</span> sd_lmi <span class="sc">*</span> wsd_lmi <span class="co"># this is the I(i) statistic under this iteration of null</span></span>
+<span id="cb12-27"><a href="#cb12-27" aria-hidden="true" tabindex="-1"></a>}</span>
+<span id="cb12-28"><a href="#cb12-28" aria-hidden="true" tabindex="-1"></a></span>
+<span id="cb12-29"><a href="#cb12-29" aria-hidden="true" tabindex="-1"></a><span class="fu">hist</span>(sims[<span class="dv">1</span>,])</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
+<div class="cell-output-display">
+<p><img src="07-basic_statistics_files/figure-html/LocalMoransI-1.png" class="img-fluid" width="768"></p>
+</div>
+<div class="sourceCode cell-code" id="cb13"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Step 6 - For each county, test where the observed value ranks with respect to the null simulations</span></span>
+<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a>xrank <span class="ot">&lt;-</span> <span class="fu">apply</span>(<span class="fu">cbind</span>(district<span class="sc">$</span>I_lm, sims), <span class="dv">1</span>, <span class="cf">function</span>(x) <span class="fu">rank</span>(x)[<span class="dv">1</span>])</span>
+<span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a></span>
+<span id="cb13-4"><a href="#cb13-4" aria-hidden="true" tabindex="-1"></a><span class="co"># Step 7 - Calculate the difference between observed rank and total possible (nsim)</span></span>
+<span id="cb13-5"><a href="#cb13-5" aria-hidden="true" tabindex="-1"></a>diff <span class="ot">&lt;-</span> nsim <span class="sc">-</span> xrank</span>
+<span id="cb13-6"><a href="#cb13-6" aria-hidden="true" tabindex="-1"></a>diff <span class="ot">&lt;-</span> <span class="fu">ifelse</span>(diff <span class="sc">&gt;</span> <span class="dv">0</span>, diff, <span class="dv">0</span>)</span>
+<span id="cb13-7"><a href="#cb13-7" aria-hidden="true" tabindex="-1"></a></span>
+<span id="cb13-8"><a href="#cb13-8" aria-hidden="true" tabindex="-1"></a><span class="co"># Step 8 - Assuming a uniform distribution of ranks, calculate p-value for observed</span></span>
+<span id="cb13-9"><a href="#cb13-9" aria-hidden="true" tabindex="-1"></a><span class="co"># given the null distribution generate from simulations</span></span>
+<span id="cb13-10"><a href="#cb13-10" aria-hidden="true" tabindex="-1"></a>district<span class="sc">$</span>pval_lm <span class="ot">&lt;-</span> <span class="fu">punif</span>((diff <span class="sc">+</span> <span class="dv">1</span>) <span class="sc">/</span> (nsim <span class="sc">+</span> <span class="dv">1</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
+</div>
+<p>For each district, we obtain a p-value based on permutations process</p>
+<p>A conventional way of plotting these results is to classify the districts into 5 classes based on local Moran’s I outputs. The classification of cluster that are significantly autocorrelated to their neighbors is performed based on a comparison of the scaled incidence in the district compared to the scaled weighted averaged incidence of it neighboring districts (computed with <code>lag.listw()</code>) :</p>
 <ul>
 <li><p>Districts that have higher-than-average rates in both index regions and their neighbors and showing statistically significant positive values for the local <span class="math inline">\(I_i\)</span> statistic are defined as <strong>High-High</strong> (hotspot of the disease)</p></li>
 <li><p>Districts that have lower-than-average rates in both index regions and their neighbors adn showing statistically significant positive values for the local <span class="math inline">\(I_i\)</span> statistic are defined as <strong>Low-Low</strong> (coldspot of the disease).</p></li>
@@ -546,15 +568,14 @@ Statistical test
 <li><p>Districts that have lower-than-average rates in the index regions and higher-than-average rates in their neighbors, and showing statistically significant negative values for the local <span class="math inline">\(I_i\)</span> statistic are defined as <strong>Low-High</strong>(outlier of low incidence in area with high incidence).</p></li>
 <li><p>Districts with non-significant values for the <span class="math inline">\(I_i\)</span> statistic are defined as <strong>Non-significant</strong>.</p></li>
 </ul>
-<p>In this example, we adjusted for multiple testing using bonferroni correction, i.e.&nbsp;the p-value are multiplied by the number of tests.</p>
 <div class="cell" data-nm="true">
 <div class="sourceCode cell-code" id="cb14"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="co"># create lagged local raw_rate - in other words the average of the queen neighbors value</span></span>
 <span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a><span class="co"># values are scaled (centered and reduced) to be compared to average</span></span>
 <span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a>district<span class="sc">$</span>lag_std   <span class="ot">&lt;-</span> <span class="fu">scale</span>(<span class="fu">lag.listw</span>(q_listw, <span class="at">var =</span> district<span class="sc">$</span>incidence))</span>
 <span id="cb14-4"><a href="#cb14-4" aria-hidden="true" tabindex="-1"></a>district<span class="sc">$</span>incidence_std <span class="ot">&lt;-</span> <span class="fu">scale</span>(district<span class="sc">$</span>incidence)</span>
 <span id="cb14-5"><a href="#cb14-5" aria-hidden="true" tabindex="-1"></a></span>
-<span id="cb14-6"><a href="#cb14-6" aria-hidden="true" tabindex="-1"></a><span class="co"># adjust for pvalues</span></span>
-<span id="cb14-7"><a href="#cb14-7" aria-hidden="true" tabindex="-1"></a>district<span class="sc">$</span>lm_pv <span class="ot">&lt;-</span> <span class="fu">p.adjust</span>(lm_test[,<span class="dv">5</span>], <span class="st">"bonferroni"</span>)</span>
+<span id="cb14-6"><a href="#cb14-6" aria-hidden="true" tabindex="-1"></a><span class="co"># extract pvalues</span></span>
+<span id="cb14-7"><a href="#cb14-7" aria-hidden="true" tabindex="-1"></a><span class="co"># district$lm_pv &lt;- lm_test[,5]</span></span>
 <span id="cb14-8"><a href="#cb14-8" aria-hidden="true" tabindex="-1"></a></span>
 <span id="cb14-9"><a href="#cb14-9" aria-hidden="true" tabindex="-1"></a><span class="co"># Classify local moran's outputs</span></span>
 <span id="cb14-10"><a href="#cb14-10" aria-hidden="true" tabindex="-1"></a>district<span class="sc">$</span>lm_class <span class="ot">&lt;-</span> <span class="cn">NA</span></span>
@@ -562,7 +583,7 @@ Statistical test
 <span id="cb14-12"><a href="#cb14-12" aria-hidden="true" tabindex="-1"></a>district<span class="sc">$</span>lm_class[district<span class="sc">$</span>incidence_std <span class="sc">&lt;=</span><span class="dv">0</span> <span class="sc">&amp;</span> district<span class="sc">$</span>lag_std <span class="sc">&lt;=</span><span class="dv">0</span>] <span class="ot">&lt;-</span> <span class="st">'Low-Low'</span></span>
 <span id="cb14-13"><a href="#cb14-13" aria-hidden="true" tabindex="-1"></a>district<span class="sc">$</span>lm_class[district<span class="sc">$</span>incidence_std <span class="sc">&lt;=</span><span class="dv">0</span> <span class="sc">&amp;</span> district<span class="sc">$</span>lag_std <span class="sc">&gt;=</span><span class="dv">0</span>] <span class="ot">&lt;-</span> <span class="st">'Low-High'</span></span>
 <span id="cb14-14"><a href="#cb14-14" aria-hidden="true" tabindex="-1"></a>district<span class="sc">$</span>lm_class[district<span class="sc">$</span>incidence_std <span class="sc">&gt;=</span><span class="dv">0</span> <span class="sc">&amp;</span> district<span class="sc">$</span>lag_std <span class="sc">&lt;=</span><span class="dv">0</span>] <span class="ot">&lt;-</span> <span class="st">'High-Low'</span></span>
-<span id="cb14-15"><a href="#cb14-15" aria-hidden="true" tabindex="-1"></a>district<span class="sc">$</span>lm_class[district<span class="sc">$</span>lm_pv <span class="sc">&gt;=</span> <span class="fl">0.5</span>] <span class="ot">&lt;-</span> <span class="st">'Non-significant'</span></span>
+<span id="cb14-15"><a href="#cb14-15" aria-hidden="true" tabindex="-1"></a>district<span class="sc">$</span>lm_class[district<span class="sc">$</span>pval_lm <span class="sc">&gt;=</span> <span class="fl">0.05</span>] <span class="ot">&lt;-</span> <span class="st">'Non-significant'</span></span>
 <span id="cb14-16"><a href="#cb14-16" aria-hidden="true" tabindex="-1"></a></span>
 <span id="cb14-17"><a href="#cb14-17" aria-hidden="true" tabindex="-1"></a>district<span class="sc">$</span>lm_class <span class="ot">&lt;-</span> <span class="fu">factor</span>(district<span class="sc">$</span>lm_class, <span class="at">levels=</span><span class="fu">c</span>(<span class="st">"High-High"</span>, <span class="st">"Low-Low"</span>, <span class="st">"High-Low"</span>,  <span class="st">"Low-High"</span>, <span class="st">"Non-significant"</span>) )</span>
 <span id="cb14-18"><a href="#cb14-18" aria-hidden="true" tabindex="-1"></a></span>
@@ -573,7 +594,7 @@ Statistical test
 <span id="cb14-23"><a href="#cb14-23" aria-hidden="true" tabindex="-1"></a>       <span class="at">cex =</span> <span class="dv">2</span>,</span>
 <span id="cb14-24"><a href="#cb14-24" aria-hidden="true" tabindex="-1"></a>       <span class="at">col_na =</span> <span class="st">"white"</span>,</span>
 <span id="cb14-25"><a href="#cb14-25" aria-hidden="true" tabindex="-1"></a>       <span class="co">#val_order = c("High-High", "Low-Low", "High-Low",  "Low-High", "Non-significant") ,</span></span>
-<span id="cb14-26"><a href="#cb14-26" aria-hidden="true" tabindex="-1"></a>       <span class="at">pal =</span> <span class="fu">c</span>(<span class="st">"#6D0026"</span> , <span class="st">"#7FABD3"</span> , <span class="st">"white"</span>) , <span class="co"># "blue", "#FF755F",</span></span>
+<span id="cb14-26"><a href="#cb14-26" aria-hidden="true" tabindex="-1"></a>       <span class="at">pal =</span> <span class="fu">c</span>(<span class="st">"#6D0026"</span> , <span class="st">"blue"</span>,  <span class="st">"white"</span>) , <span class="co"># "#FF755F","#7FABD3" ,</span></span>
 <span id="cb14-27"><a href="#cb14-27" aria-hidden="true" tabindex="-1"></a>       <span class="at">leg_title =</span> <span class="st">"Clusters"</span>)</span>
 <span id="cb14-28"><a href="#cb14-28" aria-hidden="true" tabindex="-1"></a></span>
 <span id="cb14-29"><a href="#cb14-29" aria-hidden="true" tabindex="-1"></a><span class="fu">mf_layout</span>(<span class="at">title =</span> <span class="st">"Cluster using Local moran'I statistic"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
@@ -672,7 +693,7 @@ Statistical test
 <span id="cb31-7"><a href="#cb31-7" aria-hidden="true" tabindex="-1"></a><span class="fu">print</span>(df_secondary_clusters)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
 <div class="cell-output cell-output-stdout">
 <pre class="code-out"><code>       SMR number.of.cases expected.cases p.value
-1 3.767698              16       4.246625   0.016</code></pre>
+1 3.767698              16       4.246625   0.004</code></pre>
 </div>
 </div>
 <p>We only have one secondary cluster composed of one district.</p>
@@ -725,6 +746,9 @@ To go futher …
 <div id="ref-scanstatistics" class="csl-entry" role="doc-biblioentry">
 Allévius, Benjamin. 2018. <span>“Scanstatistics: Space-Time Anomaly Detection Using Scan Statistics.”</span> <em>Journal of Open Source Software</em> 3 (25): 515.
 </div>
+<div id="ref-bivand2008applied" class="csl-entry" role="doc-biblioentry">
+Bivand, Roger S, Edzer J Pebesma, Virgilio Gómez-Rubio, and Edzer Jan Pebesma. 2008. <em>Applied Spatial Data Analysis with r</em>. Vol. 747248717. Springer.
+</div>
 <div id="ref-spdep" class="csl-entry" role="doc-biblioentry">
 Bivand, Roger, Micah Altman, Luc Anselin, Renato Assunção, Olaf Berke, Andrew Bernat, and Guillaume Blanchet. 2015. <span>“Package <span>‘Spdep’</span>.”</span> <em>The Comprehensive R Archive Network</em>.
 </div>
@@ -874,4 +898,4 @@ window.document.addEventListener("DOMContentLoaded", function (event) {
 
 
 <script src="site_libs/quarto-html/zenscroll-min.js"></script>
-</body></html>
+</body></html>
\ No newline at end of file
diff --git a/public/07-basic_statistics_files/figure-html/LocalMoransI-1.png b/public/07-basic_statistics_files/figure-html/LocalMoransI-1.png
new file mode 100644
index 0000000000000000000000000000000000000000..f93e192f62002be37a8c8d480133e26a96891cba
Binary files /dev/null and b/public/07-basic_statistics_files/figure-html/LocalMoransI-1.png differ
diff --git a/public/07-basic_statistics_files/figure-html/LocalMoransI_plt-1.png b/public/07-basic_statistics_files/figure-html/LocalMoransI_plt-1.png
index fc5fae66a1fb11672b172de51eb5986d7b3ab237..567565cfa7861893745dec4daac1580ed2f18485 100644
Binary files a/public/07-basic_statistics_files/figure-html/LocalMoransI_plt-1.png and b/public/07-basic_statistics_files/figure-html/LocalMoransI_plt-1.png differ
diff --git a/public/07-basic_statistics_files/figure-html/MoransI-1.png b/public/07-basic_statistics_files/figure-html/MoransI-1.png
index 8ca1b4b15f5058403667087320e25260ceaeec97..6fe0c65fb8d1606dfd85e49e73a29cdcc7723d3b 100644
Binary files a/public/07-basic_statistics_files/figure-html/MoransI-1.png and b/public/07-basic_statistics_files/figure-html/MoransI-1.png differ
diff --git a/public/07-basic_statistics_files/figure-html/inc_visualization-1.png b/public/07-basic_statistics_files/figure-html/inc_visualization-1.png
index a68880002f5f61cc0057c8dcbd670a3ce2e6d6e7..f51d9d8ad227415eba0b327eb30d51e5bbb0ca9c 100644
Binary files a/public/07-basic_statistics_files/figure-html/inc_visualization-1.png and b/public/07-basic_statistics_files/figure-html/inc_visualization-1.png differ
diff --git a/public/07-basic_statistics_files/figure-html/kd_test-1.png b/public/07-basic_statistics_files/figure-html/kd_test-1.png
index 452a64ae523adc6ac1b80cac6900e0c8f4854dcf..5f7ec7926a8c35a0e5abeb86280e58b47ec40142 100644
Binary files a/public/07-basic_statistics_files/figure-html/kd_test-1.png and b/public/07-basic_statistics_files/figure-html/kd_test-1.png differ
diff --git a/public/search.json b/public/search.json
index af1b001eac8b7fa1bcb6da5c2f3313871ef0b560..51a756ffdb7bced48902b63c174529172cb259b1 100644
--- a/public/search.json
+++ b/public/search.json
@@ -18,7 +18,7 @@
     "href": "07-basic_statistics.html#cluster-analysis",
     "title": "7  Basic statistics for spatial analysis",
     "section": "7.2 Cluster analysis",
-    "text": "7.2 Cluster analysis\n\n7.2.1 General introduction\nWhy studying clusters in epidemiology ? Cluster analysis help identifying unusual patterns that occurs during a given period of time. The underlying ultimate goal of such analysis is to explain the observation of such patterns. In epidemiology, we can distinguish two types of process that would explain heterogeneity in case distribution :\n\nThe 1st order effects are the spatial variations of cases distribution caused by underlying properties of environment or the population structure itself. In such process individual get infected independently from the rest of the population. Such process includes the infection through a environment at risk as, for example, air pollution, contaminated waters or soils and UV exposition. This effect assume that the observed pattern are caused by a difference in risk intensity.\nThe 2nd order effects describes process of spread, contagion and diffusion of diseases caused by interactions between individuals. This includes transmission of infectious disease by proximity, but also the transmission of non-infectious disease, for example, with the diffusion of social norms within networks. This effect assume that the observed pattern are caused by correlations or co-variations.\n\nNo statistical methods could distinguish between these competing processes since their outcome results in similar pattern of points. The cluster analysis help describing the magnitude and the location of pattern but in no way could answer the question of why such patterns occurs. It is therefore a step that help detecting cluster for description and surveillance purpose and rising hypothesis on the underlying process that will lead further investigations.\nKnowledge about the disease and its transmission process could orientate the choice of the methods of study. We presented in this brief tutorial two methods of cluster detection, the Moran’s I test that test for spatial independence (likely related to 2nd order effects) and the scan statistics that test for homogeneous distribution (likely related 1st order effects). It relies on epidemiologist to select the tools that best serve the studied question.\n\n\n\n\n\n\nStatistic tests and distributions\n\n\n\nIn statistics, problems are usually expressed by defining two hypothesis : the null hypothesis (H0), i.e. an a priori hypothesis of the studied phenomenon (e.g. the situation is a random) and the alternative hypothesis (HA), e.g. the situation is not random. The main principle is to measure how likely the observed situation belong to the ensemble of situation that are possible under the H0 hypothesis.\nIn mathematics, a probability distribution is a mathematical expression that represents what we would expect due to random chance. The choice of the probability distribution relies on the type of data you use (continuous, count, binary). In general, three distribution a used while studying disease rates, the Binomial, the Poisson and the Poisson-gamma mixture (a.k.a negative binomial) distributions.\nMany the statistical tests assume by default that data are normally distributed. It implies that your variable is continuous and that all data could easily be represented by two parameters, the mean and the variance, i.e. each value have the same level of certainty. If many measure can be assessed under the normality assumption, this is usually not the case in epidemiology with strictly positives rates and count values that 1) does not fit the normal distribution and 2) does not provide with the same degree of certainty since variances likely differ between district due to different population size, i.e. some district have very sparse data (with high variance) while other have adequate data (with lower variance).\n\n# dataset statistics\nm_cases <- mean(district$incidence)\nsd_cases <- sd(district$incidence)\n\nhist(district$incidence, probability = TRUE, ylim = c(0, 0.4), xlim = c(-5, 16), xlab = \"Number of cases\", ylab = \"Probability\", main = \"Histogram of observed incidence compared\\nto Normal and Poisson distributions\")\ncurve(dnorm(x, m_cases, sd_cases),col = \"blue\",  lwd = 1, add = TRUE)\npoints(0:max(district$incidence), dpois(0:max(district$incidence), m_cases),type = 'b', pch = 20, col = \"red\", ylim = c(0, 0.6), lty = 2)\n\nlegend(\"topright\", legend = c(\"Normal distribution\", \"Poisson distribution\", \"Observed distribution\"), col = c(\"blue\", \"red\", \"black\"),pch = c(NA, 20, NA), lty = c(1, 2, 1))\n\n\n\n\nIn this tutorial, we used the poisson distribution in our statistical tests.\n\n\n\n\n7.2.2 Test for spatial autocorrelation (Moran’s I test)\n\n7.2.2.1 The global Moran’s I test\nA popular test for spatial autocorrelation is the Moran’s test. This test tells us whether nearby units tend to exhibit similar incidences. It ranges from -1 to +1. A value of -1 denote that units with low rates are located near other units with high rates, while a Moran’s I value of +1 indicates a concentration of spatial units exhibiting similar rates.\n\n\n\n\n\n\nMoran’s I test\n\n\n\nThe Moran’s statistics is :\n\\[I = \\frac{N}{\\sum_{i=1}^N\\sum_{j=1}^Nw_{ij}}\\frac{\\sum_{i=1}^N\\sum_{j=1}^Nw_{ij}(Y_i-\\bar{Y})(Y_j - \\bar{Y})}{\\sum_{i=1}^N(Y_i-\\bar{Y})^2}\\] with :\n\n\\(N\\): the number of polygons,\n\\(w_{ij}\\): is a matrix of spatial weight with zeroes on the diagonal (i.e., \\(w_{ii}=0\\)). For example, if polygons are neighbors, the weight takes the value \\(1\\) otherwise it take the value \\(0\\).\n\\(Y_i\\): the variable of interest,\n\\(\\bar{Y}\\): the mean value of \\(Y\\).\n\nUnder the Moran’s test, the statistics hypothesis are :\n\nH0 : the distribution of cases is spatially independent, i.e. \\(I=0\\).\nH1: the distribution of cases is spatially autocorrelated, i.e. \\(I\\ne0\\).\n\n\n\nWe will compute the Moran’s statistics using spdep(Bivand et al. 2015) and Dcluster(Gómez-Rubio et al. 2015) packages. spdep package provides a collection of functions to analyze spatial correlations of polygons and works with sp objects. In this example, we use poly2nb() and nb2listw(). These function respectively detect the neighboring polygons and assign weight corresponding to \\(1/\\#\\ of\\ neighbors\\). Dcluster package provides a set of functions for the detection of spatial clusters of disease using count data.\n\nlibrary(spdep) # Functions for creating spatial weight, spatial analysis\nlibrary(DCluster)  # Package with functions for spatial cluster analysis\n\nqueen_nb <- poly2nb(district) # Neighbors according to queen case\nq_listw <- nb2listw(queen_nb, style = 'W') # row-standardized weights\n\n# Moran's I test\nm_test <- moranI.test(cases ~ offset(log(expected)), \n                  data = district,\n                  model = 'poisson',\n                  R = 499,\n                  listw = q_listw,\n                  n = length(district$cases), # number of regions\n                  S0 = Szero(q_listw)) # Global sum of weights\nprint(m_test)\n\nMoran's I test of spatial autocorrelation \n\n    Type of boots.: parametric \n    Model used when sampling: Poisson \n    Number of simulations: 499 \n    Statistic:  0.1566449 \n    p-value :  0.012 \n\nplot(m_test)\n\n\n\n\nThe Moran’s statistics is here \\(I =\\) 0.16. When comparing its value to the H0 distribution (built under 499 simulations), the probability of observing such a I value under the null hypothesis, i.e. the distribution of cases is spatially independent, is \\(p_{value} =\\) 0.012. We therefore reject H0 with error risk of \\(\\alpha = 5\\%\\). The distribution of cases is therefore autocorrelated across districts in Cambodia.\n\n\n7.2.2.2 Moran’s I local test\nThe global Moran’s test provides us a global statistical value informing whether autocorrelation occurs over the territory but does not inform on where does these correlation occurs, i.e. what is the locations of the clusters. To identify such cluster we can decompose the Moran’s I statistic to extract local informations of the level of correlation of each district and its neighbors. This is called the Local Moran’s I LISA statistic. Because the Local Moran’s I LISA statistic test each district for autocorrelation independently, concern are raised about multiple testing limitations that increase the Type I error (\\(\\alpha\\)) of the statistical tests. The use of local test should therefore be study in light of explore and describes clusters once the global test detected autocorrelation.\n\n\n\n\n\n\nStatistical test\n\n\n\nFor each district \\(i\\), the Moran’s statistics is :\n\\[I_i = \\frac{(Y_i-\\bar{Y})}{\\sum_{i=1}^N(Y_i-\\bar{Y})^2}\\sum_{j=1}^Nw_{ij}(Y_j - \\bar{Y}) \\text{ with }  I = \\sum_{i=1}^NI_i/N\\]\n\n\nThe localmoran()function from the package spdep treats the variable of interest as if it was normally distributed. In some cases, this assumption could be reasonable for incidence rate, especially when the areal units of analysis have sufficiently large population count suggesting that the values have similar level of variances.\n\nlm_test <- localmoran(x = district$incidence,\n                  listw = q_listw) \n\nsummary(lm_test)\n\n       Ii                E.Ii                Var.Ii              Z.Ii        \n Min.   :-2.23556   Min.   :-8.892e-02   Min.   :0.000008   Min.   :-4.0207  \n 1st Qu.:-0.04241   1st Qu.:-3.153e-03   1st Qu.:0.015478   1st Qu.:-0.3209  \n Median : 0.07664   Median :-2.853e-03   Median :0.085746   Median : 0.4380  \n Mean   : 0.15664   Mean   :-5.102e-03   Mean   :0.256203   Mean   : 0.3632  \n 3rd Qu.: 0.28011   3rd Qu.:-4.032e-04   3rd Qu.:0.152437   3rd Qu.: 1.0690  \n Max.   : 3.04441   Max.   :-2.400e-07   Max.   :5.265316   Max.   : 4.7356  \n Pr(z != E(Ii))     \n Min.   :0.0000022  \n 1st Qu.:0.2244163  \n Median :0.4315420  \n Mean   :0.4601943  \n 3rd Qu.:0.6979413  \n Max.   :0.9939022  \n\n\nlocalmoran()returns for each district fives outputs : the local moran indice \\(I_i\\), the is the expected value of the Moran’s I statistic under the null hypothesis \\(E_i\\), the variance of each local moran’s I statistics Var.Ii, the standardized deviation of the local Moran’s I statistic Z.Ii and Pr(Z>0) is the p-value.\nA conventional way of plotting these results is to classify the district into 5 classes based on local Moran’s I outputs. Classification is performed based on a comparison of the scaled incidence in the district compared to the scaled weighted averaged incidence of it neighboring districts (computed with lag.listw()) :\n\nDistricts that have higher-than-average rates in both index regions and their neighbors and showing statistically significant positive values for the local \\(I_i\\) statistic are defined as High-High (hotspot of the disease)\nDistricts that have lower-than-average rates in both index regions and their neighbors adn showing statistically significant positive values for the local \\(I_i\\) statistic are defined as Low-Low (coldspot of the disease).\nDistricts that have higher-than-average rates in the index regions and lower-than-average rates in their neighbors, and showing statistically significant negative values for the local \\(I_i\\) statistic are defined as High-Low(outlier with high incidence in an area with low incidence).\nDistricts that have lower-than-average rates in the index regions and higher-than-average rates in their neighbors, and showing statistically significant negative values for the local \\(I_i\\) statistic are defined as Low-High(outlier of low incidence in area with high incidence).\nDistricts with non-significant values for the \\(I_i\\) statistic are defined as Non-significant.\n\nIn this example, we adjusted for multiple testing using bonferroni correction, i.e. the p-value are multiplied by the number of tests.\n\n# create lagged local raw_rate - in other words the average of the queen neighbors value\n# values are scaled (centered and reduced) to be compared to average\ndistrict$lag_std   <- scale(lag.listw(q_listw, var = district$incidence))\ndistrict$incidence_std <- scale(district$incidence)\n\n# adjust for pvalues\ndistrict$lm_pv <- p.adjust(lm_test[,5], \"bonferroni\")\n\n# Classify local moran's outputs\ndistrict$lm_class <- NA\ndistrict$lm_class[district$incidence_std >=0 & district$lag_std >=0] <- 'High-High'\ndistrict$lm_class[district$incidence_std <=0 & district$lag_std <=0] <- 'Low-Low'\ndistrict$lm_class[district$incidence_std <=0 & district$lag_std >=0] <- 'Low-High'\ndistrict$lm_class[district$incidence_std >=0 & district$lag_std <=0] <- 'High-Low'\ndistrict$lm_class[district$lm_pv >= 0.5] <- 'Non-significant'\n\ndistrict$lm_class <- factor(district$lm_class, levels=c(\"High-High\", \"Low-Low\", \"High-Low\",  \"Low-High\", \"Non-significant\") )\n\n# create map\nmf_map(x = district,\n       var = \"lm_class\",\n       type = \"typo\",\n       cex = 2,\n       col_na = \"white\",\n       #val_order = c(\"High-High\", \"Low-Low\", \"High-Low\",  \"Low-High\", \"Non-significant\") ,\n       pal = c(\"#6D0026\" , \"#7FABD3\" , \"white\") , # \"blue\", \"#FF755F\",\n       leg_title = \"Clusters\")\n\nmf_layout(title = \"Cluster using Local moran'I statistic\")\n\n\n\n\n\n\n\n7.2.3 Spatial scan statistics\nWhile Moran’s indice focuses on testing for autocorrelation between neighboring polygons (under the null assumption of spatial independance), the spatial scan statistic aims at identifying an abnormal higher risk in a given region compared to the risk outside of this region (under the null assumption of homogeneous distribution). The conception of a cluster is therefore different between the two methods.\nThe function kulldorff from the package SpatialEpi (Kim and Wakefield 2010) is a simple tool to implement spatial-only scan statistics. Briefly, the kulldorff scan statistics scan the area for clusters using several steps:\n\nIt create a circular window of observation by defining a single location and an associated radius of the windows varying from 0 to a large number that depends on population distribution (largest radius could includes 50% of the population).\nIt aggregates the count of events and the population at risk (or an expected count of events) inside and outside the window of observation.\nFinally, it computes the likelihood ratio to test whether the risk is equal inside versus outside the windows (H0) or greater inside the observed window\nThese 3 steps are repeted for each location and each possible windows-radii.\n\n\nlibrary(\"SpatialEpi\")\n\nThe use of R spatial object is not implementes in kulldorff() function. It uses instead matrix of xy coordinates that represents the centroids of the districts. A given district is included into the observed circular window if its centroids falls into the circle.\n\ndistrict_xy <- st_centroid(district) %>% \n  st_coordinates()\n\nhead(district_xy)\n\n         X       Y\n1 330823.3 1464560\n2 749758.3 1541787\n3 468384.0 1277007\n4 494548.2 1215261\n5 459644.2 1194615\n6 360528.3 1516339\n\n\nWe can then call kulldorff function (you are strongly encourage to call ?kulldorff to properly call the function). The alpha.level threshold filter for the secondary clusters that will be retained. The most-likely cluster will be saved whatever its significance.\n\nkd_Wfever <- kulldorff(district_xy, \n                cases = district$cases,\n                population = district$T_POP,\n                expected.cases = district$expected,\n                pop.upper.bound = 0.5, # include maximum 50% of the population in a windows\n                n.simulations = 499,\n                alpha.level = 0.2)\n\n\n\n\nAll outputs are saved into an R object, here called kd_Wfever. Unfortunately the package did not developed any summary and visualization of the results but we can explore the output object.\n\nnames(kd_Wfever)\n\n[1] \"most.likely.cluster\" \"secondary.clusters\"  \"type\"               \n[4] \"log.lkhd\"            \"simulated.log.lkhd\" \n\n\nFirst, we can focus on the most likely cluster and explore its characteristics.\n\n# We can see which districts (r number) belong to this cluster\nkd_Wfever$most.likely.cluster$location.IDs.included\n\n [1]  48  93  66 180 133  29 194 118  50 144  31 141   3 117  22  43 142\n\n# standardized incidence ratio\nkd_Wfever$most.likely.cluster$SMR\n\n[1] 2.303106\n\n# number of observed and expected cases in this cluster\nkd_Wfever$most.likely.cluster$number.of.cases\n\n[1] 122\n\nkd_Wfever$most.likely.cluster$expected.cases\n\n[1] 52.97195\n\n\n17 districts belong to the cluster and its number of cases is 2.3 times higher than the expected number of case.\nSimilarly, we could study the secondary clusters. Results are saved in a list.\n\n# We can see which districts (r number) belong to this cluster\nlength(kd_Wfever$secondary.clusters)\n\n[1] 1\n\n# retrieve data for all secondary clusters into a table\ndf_secondary_clusters <- data.frame(SMR = sapply(kd_Wfever$secondary.clusters, '[[', 5),  \n                          number.of.cases = sapply(kd_Wfever$secondary.clusters, '[[', 3),\n                          expected.cases = sapply(kd_Wfever$secondary.clusters, '[[', 4),\n                          p.value = sapply(kd_Wfever$secondary.clusters, '[[', 8))\n\nprint(df_secondary_clusters)\n\n       SMR number.of.cases expected.cases p.value\n1 3.767698              16       4.246625   0.016\n\n\nWe only have one secondary cluster composed of one district.\n\n# create empty column to store cluster informations\ndistrict$k_cluster <- NA\n\n# save cluster informations from kulldorff outputs\ndistrict$k_cluster[kd_Wfever$most.likely.cluster$location.IDs.included] <- 'Most likely cluster'\n\nfor(i in 1:length(kd_Wfever$secondary.clusters)){\ndistrict$k_cluster[kd_Wfever$secondary.clusters[[i]]$location.IDs.included] <- paste(\n  'Secondary cluster', i, sep = '')\n}\n\n#district$k_cluster[is.na(district$k_cluster)] <- \"No cluster\"\n\n\n# create map\nmf_map(x = district,\n       var = \"k_cluster\",\n       type = \"typo\",\n       cex = 2,\n       col_na = \"white\",\n       pal = mf_get_pal(palette = \"Reds\", n = 3)[1:2],\n       leg_title = \"Clusters\")\n\nmf_layout(title = \"Cluster using kulldorf scan statistic\")\n\n\n\n\n\n\n\n\n\n\nTo go futher …\n\n\n\nIn this example, the expected number of cases was defined using the population count but note that standardization over other variables as age could also be implemented with the strata parameter in the kulldorff() function.\nIn addition, this cluster analysis was performed solely using the spatial scan but you should keep in mind that this method of cluster detection can be implemented for spatio-temporal data as well where the cluster definition is an abnormal number of cases in a delimited spatial area and during a given period of time. The windows of observation are therefore defined for a different center, radius and period of time. You should look at the function scan_ep_poisson() function in the package scanstatistic (Allévius 2018) for this analysis.\n\n\n\n\n\n\nAllévius, Benjamin. 2018. “Scanstatistics: Space-Time Anomaly Detection Using Scan Statistics.” Journal of Open Source Software 3 (25): 515.\n\n\nBivand, Roger, Micah Altman, Luc Anselin, Renato Assunção, Olaf Berke, Andrew Bernat, and Guillaume Blanchet. 2015. “Package ‘Spdep’.” The Comprehensive R Archive Network.\n\n\nGómez-Rubio, Virgilio, Juan Ferrándiz-Ferragud, Antonio López-Quı́lez, et al. 2015. “Package ‘DCluster’.”\n\n\nKim, Albert Y, and Jon Wakefield. 2010. “R Data and Methods for Spatial Epidemiology: The SpatialEpi Package.” Dept of Statistics, University of Washington."
+    "text": "7.2 Cluster analysis\n\n7.2.1 General introduction\nWhy studying clusters in epidemiology ? Cluster analysis help identifying unusual patterns that occurs during a given period of time. The underlying ultimate goal of such analysis is to explain the observation of such patterns. In epidemiology, we can distinguish two types of process that would explain heterogeneity in case distribution :\n\nThe 1st order effects are the spatial variations of cases distribution caused by underlying properties of environment or the population structure itself. In such process individual get infected independently from the rest of the population. Such process includes the infection through a environment at risk as, for example, air pollution, contaminated waters or soils and UV exposition. This effect assume that the observed pattern are caused by a difference in risk intensity.\nThe 2nd order effects describes process of spread, contagion and diffusion of diseases caused by interactions between individuals. This includes transmission of infectious disease by proximity, but also the transmission of non-infectious disease, for example, with the diffusion of social norms within networks. This effect assume that the observed pattern are caused by correlations or co-variations.\n\nNo statistical methods could distinguish between these competing processes since their outcome results in similar pattern of points. The cluster analysis help describing the magnitude and the location of pattern but in no way could answer the question of why such patterns occurs. It is therefore a step that help detecting cluster for description and surveillance purpose and rising hypothesis on the underlying process that will lead further investigations.\nKnowledge about the disease and its transmission process could orientate the choice of the methods of study. We presented in this brief tutorial two methods of cluster detection, the Moran’s I test that test for spatial independence (likely related to 2nd order effects) and the scan statistics that test for homogeneous distribution (likely related 1st order effects). It relies on epidemiologist to select the tools that best serve the studied question.\n\n\n\n\n\n\nStatistic tests and distributions\n\n\n\nIn statistics, problems are usually expressed by defining two hypothesis : the null hypothesis (H0), i.e. an a priori hypothesis of the studied phenomenon (e.g. the situation is a random) and the alternative hypothesis (HA), e.g. the situation is not random. The main principle is to measure how likely the observed situation belong to the ensemble of situation that are possible under the H0 hypothesis.\nIn mathematics, a probability distribution is a mathematical expression that represents what we would expect due to random chance. The choice of the probability distribution relies on the type of data you use (continuous, count, binary). In general, three distribution a used while studying disease rates, the Binomial, the Poisson and the Poisson-gamma mixture (a.k.a negative binomial) distributions.\nMany the statistical tests assume by default that data are normally distributed. It implies that your variable is continuous and that all data could easily be represented by two parameters, the mean and the variance, i.e. each value have the same level of certainty. If many measure can be assessed under the normality assumption, this is usually not the case in epidemiology with strictly positives rates and count values that 1) does not fit the normal distribution and 2) does not provide with the same degree of certainty since variances likely differ between district due to different population size, i.e. some district have very sparse data (with high variance) while other have adequate data (with lower variance).\n\n# dataset statistics\nm_cases <- mean(district$incidence)\nsd_cases <- sd(district$incidence)\n\nhist(district$incidence, probability = TRUE, ylim = c(0, 0.4), xlim = c(-5, 16), xlab = \"Number of cases\", ylab = \"Probability\", main = \"Histogram of observed incidence compared\\nto Normal and Poisson distributions\")\ncurve(dnorm(x, m_cases, sd_cases),col = \"blue\",  lwd = 1, add = TRUE)\npoints(0:max(district$incidence), dpois(0:max(district$incidence), m_cases),type = 'b', pch = 20, col = \"red\", ylim = c(0, 0.6), lty = 2)\n\nlegend(\"topright\", legend = c(\"Normal distribution\", \"Poisson distribution\", \"Observed distribution\"), col = c(\"blue\", \"red\", \"black\"),pch = c(NA, 20, NA), lty = c(1, 2, 1))\n\n\n\n\nIn this tutorial, we used the poisson distribution in our statistical tests.\n\n\n\n\n7.2.2 Test for spatial autocorrelation (Moran’s I test)\n\n7.2.2.1 The global Moran’s I test\nA popular test for spatial autocorrelation is the Moran’s test. This test tells us whether nearby units tend to exhibit similar incidences. It ranges from -1 to +1. A value of -1 denote that units with low rates are located near other units with high rates, while a Moran’s I value of +1 indicates a concentration of spatial units exhibiting similar rates.\n\n\n\n\n\n\nMoran’s I test\n\n\n\nThe Moran’s statistics is :\n\\[I = \\frac{N}{\\sum_{i=1}^N\\sum_{j=1}^Nw_{ij}}\\frac{\\sum_{i=1}^N\\sum_{j=1}^Nw_{ij}(Y_i-\\bar{Y})(Y_j - \\bar{Y})}{\\sum_{i=1}^N(Y_i-\\bar{Y})^2}\\] with :\n\n\\(N\\): the number of polygons,\n\\(w_{ij}\\): is a matrix of spatial weight with zeroes on the diagonal (i.e., \\(w_{ii}=0\\)). For example, if polygons are neighbors, the weight takes the value \\(1\\) otherwise it take the value \\(0\\).\n\\(Y_i\\): the variable of interest,\n\\(\\bar{Y}\\): the mean value of \\(Y\\).\n\nUnder the Moran’s test, the statistics hypothesis are :\n\nH0 : the distribution of cases is spatially independent, i.e. \\(I=0\\).\nH1: the distribution of cases is spatially autocorrelated, i.e. \\(I\\ne0\\).\n\n\n\nWe will compute the Moran’s statistics using spdep(R. Bivand et al. 2015) and Dcluster(Gómez-Rubio et al. 2015) packages. spdep package provides a collection of functions to analyze spatial correlations of polygons and works with sp objects. In this example, we use poly2nb() and nb2listw(). These function respectively detect the neighboring polygons and assign weight corresponding to \\(1/\\#\\ of\\ neighbors\\). Dcluster package provides a set of functions for the detection of spatial clusters of disease using count data.\n\nlibrary(spdep) # Functions for creating spatial weight, spatial analysis\nlibrary(DCluster)  # Package with functions for spatial cluster analysis\n\nqueen_nb <- poly2nb(district) # Neighbors according to queen case\nq_listw <- nb2listw(queen_nb, style = 'W') # row-standardized weights\n\n# Moran's I test\nm_test <- moranI.test(cases ~ offset(log(expected)), \n                  data = district,\n                  model = 'poisson',\n                  R = 499,\n                  listw = q_listw,\n                  n = length(district$cases), # number of regions\n                  S0 = Szero(q_listw)) # Global sum of weights\nprint(m_test)\n\nMoran's I test of spatial autocorrelation \n\n    Type of boots.: parametric \n    Model used when sampling: Poisson \n    Number of simulations: 499 \n    Statistic:  0.1566449 \n    p-value :  0.014 \n\nplot(m_test)\n\n\n\n\nThe Moran’s statistics is here \\(I =\\) 0.16. When comparing its value to the H0 distribution (built under 499 simulations), the probability of observing such a I value under the null hypothesis, i.e. the distribution of cases is spatially independent, is \\(p_{value} =\\) 0.014. We therefore reject H0 with error risk of \\(\\alpha = 5\\%\\). The distribution of cases is therefore autocorrelated across districts in Cambodia.\n\n\n7.2.2.2 Moran’s I local test\nThe global Moran’s test provides us a global statistical value informing whether autocorrelation occurs over the territory but does not inform on where does these correlation occurs, i.e. what is the locations of the clusters. To identify such cluster we can decompose the Moran’s I statistic to extract local informations of the level of correlation of each district and its neighbors. This is called the Local Moran’s I LISA statistic. Because the Local Moran’s I LISA statistic test each district for autocorrelation independently, concern are raised about multiple testing limitations that increase the Type I error (\\(\\alpha\\)) of the statistical tests. The use of local test should therefore be study in light of explore and describes clusters once the global test detected autocorrelation.\n\n\n\n\n\n\nStatistical test\n\n\n\nFor each district \\(i\\), the Moran’s statistics is :\n\\[I_i = \\frac{(Y_i-\\bar{Y})}{\\sum_{i=1}^N(Y_i-\\bar{Y})^2}\\sum_{j=1}^Nw_{ij}(Y_j - \\bar{Y}) \\text{ with }  I = \\sum_{i=1}^NI_i/N\\]\n\n\nThe localmoran()function from the package spdep treats the variable of interest as if it was normally distributed. In some cases, this assumption could be reasonable for incidence rate, especially when the areal units of analysis have sufficiently large population count suggesting that the values have similar level of variances. Unfortunately, the local moran’s test has not been implemented for poisson distribution (population not large enough in some districts) in spdep package. However Bivand et al. (R. S. Bivand et al. 2008) provided some code to manual perform the analysis using poisson distribution and was further implemented in the course “Spatial Epidemiology” .\n\n# Step 1 - Create the standardized deviation of observed from expected\nsd_lm <- (district$cases - district$expected) / sqrt(district$expected)\n\n# Step 2 - Create a spatially lagged version of standardized deviation of neighbors\nwsd_lm <- lag.listw(q_listw, sd_lm)\n\n# Step 3 - the local Moran's I is the product of step 1 and step 2\ndistrict$I_lm <- sd_lm * wsd_lm\n\n# Step 4 - setup parameters for simulation of the null distribution\n\n# Specify number of simulations to run\nnsim <- 499\n\n# Specify dimensions of result based on number of regions\nN <- length(district$expected)\n\n# Create a matrix of zeros to hold results, with a row for each county, and a column for each simulation\nsims <- matrix(0, ncol = nsim, nrow = N)\n\n# Step 5 - Start a for-loop to iterate over simulation columns\nfor(i in 1:nsim){\n  y <- rpois(N, lambda = district$expected) # generate a random event count, given expected\n  sd_lmi <- (y - district$expected) / sqrt(district$expected) # standardized local measure\n  wsd_lmi <- lag.listw(q_listw, sd_lmi) # standardized spatially lagged measure\n  sims[, i] <- sd_lmi * wsd_lmi # this is the I(i) statistic under this iteration of null\n}\n\nhist(sims[1,])\n\n\n\n# Step 6 - For each county, test where the observed value ranks with respect to the null simulations\nxrank <- apply(cbind(district$I_lm, sims), 1, function(x) rank(x)[1])\n\n# Step 7 - Calculate the difference between observed rank and total possible (nsim)\ndiff <- nsim - xrank\ndiff <- ifelse(diff > 0, diff, 0)\n\n# Step 8 - Assuming a uniform distribution of ranks, calculate p-value for observed\n# given the null distribution generate from simulations\ndistrict$pval_lm <- punif((diff + 1) / (nsim + 1))\n\nFor each district, we obtain a p-value based on permutations process\nA conventional way of plotting these results is to classify the districts into 5 classes based on local Moran’s I outputs. The classification of cluster that are significantly autocorrelated to their neighbors is performed based on a comparison of the scaled incidence in the district compared to the scaled weighted averaged incidence of it neighboring districts (computed with lag.listw()) :\n\nDistricts that have higher-than-average rates in both index regions and their neighbors and showing statistically significant positive values for the local \\(I_i\\) statistic are defined as High-High (hotspot of the disease)\nDistricts that have lower-than-average rates in both index regions and their neighbors adn showing statistically significant positive values for the local \\(I_i\\) statistic are defined as Low-Low (coldspot of the disease).\nDistricts that have higher-than-average rates in the index regions and lower-than-average rates in their neighbors, and showing statistically significant negative values for the local \\(I_i\\) statistic are defined as High-Low(outlier with high incidence in an area with low incidence).\nDistricts that have lower-than-average rates in the index regions and higher-than-average rates in their neighbors, and showing statistically significant negative values for the local \\(I_i\\) statistic are defined as Low-High(outlier of low incidence in area with high incidence).\nDistricts with non-significant values for the \\(I_i\\) statistic are defined as Non-significant.\n\n\n# create lagged local raw_rate - in other words the average of the queen neighbors value\n# values are scaled (centered and reduced) to be compared to average\ndistrict$lag_std   <- scale(lag.listw(q_listw, var = district$incidence))\ndistrict$incidence_std <- scale(district$incidence)\n\n# extract pvalues\n# district$lm_pv <- lm_test[,5]\n\n# Classify local moran's outputs\ndistrict$lm_class <- NA\ndistrict$lm_class[district$incidence_std >=0 & district$lag_std >=0] <- 'High-High'\ndistrict$lm_class[district$incidence_std <=0 & district$lag_std <=0] <- 'Low-Low'\ndistrict$lm_class[district$incidence_std <=0 & district$lag_std >=0] <- 'Low-High'\ndistrict$lm_class[district$incidence_std >=0 & district$lag_std <=0] <- 'High-Low'\ndistrict$lm_class[district$pval_lm >= 0.05] <- 'Non-significant'\n\ndistrict$lm_class <- factor(district$lm_class, levels=c(\"High-High\", \"Low-Low\", \"High-Low\",  \"Low-High\", \"Non-significant\") )\n\n# create map\nmf_map(x = district,\n       var = \"lm_class\",\n       type = \"typo\",\n       cex = 2,\n       col_na = \"white\",\n       #val_order = c(\"High-High\", \"Low-Low\", \"High-Low\",  \"Low-High\", \"Non-significant\") ,\n       pal = c(\"#6D0026\" , \"blue\",  \"white\") , # \"#FF755F\",\"#7FABD3\" ,\n       leg_title = \"Clusters\")\n\nmf_layout(title = \"Cluster using Local moran'I statistic\")\n\n\n\n\n\n\n\n7.2.3 Spatial scan statistics\nWhile Moran’s indice focuses on testing for autocorrelation between neighboring polygons (under the null assumption of spatial independance), the spatial scan statistic aims at identifying an abnormal higher risk in a given region compared to the risk outside of this region (under the null assumption of homogeneous distribution). The conception of a cluster is therefore different between the two methods.\nThe function kulldorff from the package SpatialEpi (Kim and Wakefield 2010) is a simple tool to implement spatial-only scan statistics. Briefly, the kulldorff scan statistics scan the area for clusters using several steps:\n\nIt create a circular window of observation by defining a single location and an associated radius of the windows varying from 0 to a large number that depends on population distribution (largest radius could includes 50% of the population).\nIt aggregates the count of events and the population at risk (or an expected count of events) inside and outside the window of observation.\nFinally, it computes the likelihood ratio to test whether the risk is equal inside versus outside the windows (H0) or greater inside the observed window\nThese 3 steps are repeted for each location and each possible windows-radii.\n\n\nlibrary(\"SpatialEpi\")\n\nThe use of R spatial object is not implementes in kulldorff() function. It uses instead matrix of xy coordinates that represents the centroids of the districts. A given district is included into the observed circular window if its centroids falls into the circle.\n\ndistrict_xy <- st_centroid(district) %>% \n  st_coordinates()\n\nhead(district_xy)\n\n         X       Y\n1 330823.3 1464560\n2 749758.3 1541787\n3 468384.0 1277007\n4 494548.2 1215261\n5 459644.2 1194615\n6 360528.3 1516339\n\n\nWe can then call kulldorff function (you are strongly encourage to call ?kulldorff to properly call the function). The alpha.level threshold filter for the secondary clusters that will be retained. The most-likely cluster will be saved whatever its significance.\n\nkd_Wfever <- kulldorff(district_xy, \n                cases = district$cases,\n                population = district$T_POP,\n                expected.cases = district$expected,\n                pop.upper.bound = 0.5, # include maximum 50% of the population in a windows\n                n.simulations = 499,\n                alpha.level = 0.2)\n\n\n\n\nAll outputs are saved into an R object, here called kd_Wfever. Unfortunately the package did not developed any summary and visualization of the results but we can explore the output object.\n\nnames(kd_Wfever)\n\n[1] \"most.likely.cluster\" \"secondary.clusters\"  \"type\"               \n[4] \"log.lkhd\"            \"simulated.log.lkhd\" \n\n\nFirst, we can focus on the most likely cluster and explore its characteristics.\n\n# We can see which districts (r number) belong to this cluster\nkd_Wfever$most.likely.cluster$location.IDs.included\n\n [1]  48  93  66 180 133  29 194 118  50 144  31 141   3 117  22  43 142\n\n# standardized incidence ratio\nkd_Wfever$most.likely.cluster$SMR\n\n[1] 2.303106\n\n# number of observed and expected cases in this cluster\nkd_Wfever$most.likely.cluster$number.of.cases\n\n[1] 122\n\nkd_Wfever$most.likely.cluster$expected.cases\n\n[1] 52.97195\n\n\n17 districts belong to the cluster and its number of cases is 2.3 times higher than the expected number of case.\nSimilarly, we could study the secondary clusters. Results are saved in a list.\n\n# We can see which districts (r number) belong to this cluster\nlength(kd_Wfever$secondary.clusters)\n\n[1] 1\n\n# retrieve data for all secondary clusters into a table\ndf_secondary_clusters <- data.frame(SMR = sapply(kd_Wfever$secondary.clusters, '[[', 5),  \n                          number.of.cases = sapply(kd_Wfever$secondary.clusters, '[[', 3),\n                          expected.cases = sapply(kd_Wfever$secondary.clusters, '[[', 4),\n                          p.value = sapply(kd_Wfever$secondary.clusters, '[[', 8))\n\nprint(df_secondary_clusters)\n\n       SMR number.of.cases expected.cases p.value\n1 3.767698              16       4.246625   0.004\n\n\nWe only have one secondary cluster composed of one district.\n\n# create empty column to store cluster informations\ndistrict$k_cluster <- NA\n\n# save cluster informations from kulldorff outputs\ndistrict$k_cluster[kd_Wfever$most.likely.cluster$location.IDs.included] <- 'Most likely cluster'\n\nfor(i in 1:length(kd_Wfever$secondary.clusters)){\ndistrict$k_cluster[kd_Wfever$secondary.clusters[[i]]$location.IDs.included] <- paste(\n  'Secondary cluster', i, sep = '')\n}\n\n#district$k_cluster[is.na(district$k_cluster)] <- \"No cluster\"\n\n\n# create map\nmf_map(x = district,\n       var = \"k_cluster\",\n       type = \"typo\",\n       cex = 2,\n       col_na = \"white\",\n       pal = mf_get_pal(palette = \"Reds\", n = 3)[1:2],\n       leg_title = \"Clusters\")\n\nmf_layout(title = \"Cluster using kulldorf scan statistic\")\n\n\n\n\n\n\n\n\n\n\nTo go futher …\n\n\n\nIn this example, the expected number of cases was defined using the population count but note that standardization over other variables as age could also be implemented with the strata parameter in the kulldorff() function.\nIn addition, this cluster analysis was performed solely using the spatial scan but you should keep in mind that this method of cluster detection can be implemented for spatio-temporal data as well where the cluster definition is an abnormal number of cases in a delimited spatial area and during a given period of time. The windows of observation are therefore defined for a different center, radius and period of time. You should look at the function scan_ep_poisson() function in the package scanstatistic (Allévius 2018) for this analysis.\n\n\n\n\n\n\nAllévius, Benjamin. 2018. “Scanstatistics: Space-Time Anomaly Detection Using Scan Statistics.” Journal of Open Source Software 3 (25): 515.\n\n\nBivand, Roger S, Edzer J Pebesma, Virgilio Gómez-Rubio, and Edzer Jan Pebesma. 2008. Applied Spatial Data Analysis with r. Vol. 747248717. Springer.\n\n\nBivand, Roger, Micah Altman, Luc Anselin, Renato Assunção, Olaf Berke, Andrew Bernat, and Guillaume Blanchet. 2015. “Package ‘Spdep’.” The Comprehensive R Archive Network.\n\n\nGómez-Rubio, Virgilio, Juan Ferrándiz-Ferragud, Antonio López-Quı́lez, et al. 2015. “Package ‘DCluster’.”\n\n\nKim, Albert Y, and Jon Wakefield. 2010. “R Data and Methods for Spatial Epidemiology: The SpatialEpi Package.” Dept of Statistics, University of Washington."
   },
   {
     "objectID": "01-introduction.html",
@@ -235,7 +235,7 @@
     "href": "07-basic_statistics.html",
     "title": "7  Basic statistics for spatial analysis",
     "section": "",
-    "text": "This section aims at providing some basic statistical tools to study the spatial distribution of epidemiological data."
+    "text": "This section aims at providing some basic statistical tools to study the spatial distribution of epidemiological data. If you wish to go further into these analysis and their limitations you can consult the tutorial “Spatial Epidemiology” from M. Kramer from which the statistical analysis of his section were adapted."
   },
   {
     "objectID": "07-basic_statistics.html#import-and-visualize-epidemiological-data",
@@ -258,4 +258,4 @@
     "section": "",
     "text": "Agafonkin, Vladimir. 2015. “Leaflet Javascript Libary.”\n\n\nAppelhans, Tim, Florian Detsch, Christoph Reudenbach, and Stefan\nWoellauer. 2022. “Mapview: Interactive Viewing of Spatial Data in\nr.” https://CRAN.R-project.org/package=mapview.\n\n\nAppelhans, Tim, Kenton Russell, and Lorenzo Busetto. 2020.\n“Mapedit: Interactive Editing of Spatial Data in r.” https://CRAN.R-project.org/package=mapedit.\n\n\nBivand, Roger, Tim Keitt, and Barry Rowlingson. 2022. “Rgdal:\nBindings for the ’Geospatial’ Data Abstraction Library.” https://CRAN.R-project.org/package=rgdal.\n\n\nBivand, Roger, and Colin Rundel. 2021. “Rgeos: Interface to\nGeometry Engine - Open Source (’GEOS’).” https://CRAN.R-project.org/package=rgeos.\n\n\nBrunet, Roger, Robert Ferras, and Hervé Théry. 1993. Les Mots de La\ngéographie: Dictionnaire Critique. 03) 911 BRU.\n\n\nCambon, Jesse, Diego Hernangómez, Christopher Belanger, and Daniel\nPossenriede. 2021. “Tidygeocoder: An r Package for\nGeocoding” 6: 3544. https://doi.org/10.21105/joss.03544.\n\n\nCauvin, Colette, Francisco Escobar, and Aziz Serradj. 2013. Thematic\nCartography, Cartography and the Impact of the Quantitative\nRevolution. Vol. 2. John Wiley & Sons.\n\n\nCheng, Joe, Bhaskar Karambelkar, and Yihui Xie. 2022. “Leaflet:\nCreate Interactive Web Maps with the JavaScript ’Leaflet’\nLibrary.” https://CRAN.R-project.org/package=leaflet.\n\n\nDorling, Daniel. 1996. Area Cartograms: Their Use and Creation,\nConcepts and Techniques in Modern Geography. Vol. 59. CATMOG:\nConcepts and Techniques in Modern Geography. Institute of British\nGeographers.\n\n\nDougenik, James A, Nicholas R Chrisman, and Duane R Niemeyer. 1985.\n“An Algorithm to Construct Continuous Area Cartograms.”\nThe Professional Geographer 37 (1): 75–81.\n\n\nDunnington, Dewey. 2021. “Ggspatial: Spatial Data Framework for\nGgplot2.” https://CRAN.R-project.org/package=ggspatial.\n\n\nGDAL/OGR contributors. n.d. GDAL/OGR Geospatial Data\nAbstraction Software Library. Open Source Geospatial Foundation. https://gdal.org.\n\n\nGilardi, Andrea, and Robin Lovelace. 2021. “Osmextract: Download\nand Import Open Street Map Data Extracts.” https://CRAN.R-project.org/package=osmextract.\n\n\nGiraud, Timothée. 2021a. “Linemap: Line Maps.” https://CRAN.R-project.org/package=linemap.\n\n\n———. 2021b. “Maptiles: Download and Display Map Tiles.” https://CRAN.R-project.org/package=maptiles.\n\n\n———. 2022a. “Mapsf: Thematic Cartography.” https://CRAN.R-project.org/package=mapsf.\n\n\n———. 2022b. “Tanaka: Design Shaded Contour Lines (or Tanaka)\nMaps.” https://CRAN.R-project.org/package=tanaka.\n\n\nGiraud, Timothée, and Nicolas Lambert. 2016. “Cartography: Create\nand Integrate Maps in Your r Workflow” 1. https://doi.org/10.21105/joss.00054.\n\n\nGombin, Joel, and Paul-Antoine Chevalier. 2022. “banR: R Client\nfor the BAN API.”\n\n\nHerbreteau, Vincent, Christophe Révillion, and Etienne Trimaille. 2018.\n“GeoHealth and QuickOSM, two QGIS plugins for\nhealth applications.” In Earth\nSystems - Environmental Sciences : QGIS in Remote Sensing\nSet, edited by Nicolas Baghdadi, Clément Mallet, and Mehrez\nZribi, 1:257–86. QGIS and Generic Tools. ISTE. https://hal.archives-ouvertes.fr/hal-01787435.\n\n\nHijmans, Robert J. 2022a. “Raster: Geographic Data Analysis and\nModeling.” https://CRAN.R-project.org/package=raster.\n\n\n———. 2022b. “Terra: Spatial Data Analysis.” https://CRAN.R-project.org/package=terra.\n\n\nJeworutzki, Sebastian. 2020. “Cartogram: Create Cartograms with\nr.” https://CRAN.R-project.org/package=cartogram.\n\n\nLambert, Nicolas. 2015. “Les Anamorphoses Cartographiques.”\nBlog. Carnet Néocartographique. https://neocarto.hypotheses.org/366.\n\n\nLi, Xingong. 2009. “Map Algebra and Beyond : 1. Map Algebra for\nScalar Fields.” https://slideplayer.com/slide/5822638/.\n\n\nMadelin, Malika. 2021. “Analyse d’images Raster (Et\nTélédétection).” https://mmadelin.github.io/sigr2021/SIGR2021_raster_MM.html.\n\n\nMennis, Jeremy. 2015. “Fundamentals of GIS : Raster\nOperations.” https://cupdf.com/document/gus-0262-fundamentals-of-gis-lecture-presentation-7-raster-operations-jeremy.html.\n\n\nNowosad, Jakub. 2021. “Image Processing and All Things\nRaster.” https://nowosad.github.io/SIGR2021/workshop2/workshop2.html.\n\n\nOlson, Judy M. 1976. “Noncontiguous Area Cartograms.”\nThe Professional Geographer 28 (4): 371–80.\n\n\nPadgham, Mark, Bob Rudis, Robin Lovelace, and Maëlle Salmon. 2017.\n“Osmdata” 2. https://doi.org/10.21105/joss.00305.\n\n\nPaull, John, and Benjamin Hennig. 2016. “Atlas of Organics: Four\nMaps of the World of Organic Agriculture.” Journal of\nOrganics 3 (1): 25–32.\n\n\nPebesma, Edzer. 2018b. “Simple Features for r:\nStandardized Support for Spatial Vector Data” 10. https://doi.org/10.32614/RJ-2018-009.\n\n\n———. 2018a. “Simple Features for R: Standardized Support for\nSpatial Vector Data.” The R Journal 10 (1): 439. https://doi.org/10.32614/rj-2018-009.\n\n\n———. 2021. “Stars: Spatiotemporal Arrays, Raster and Vector Data\nCubes.” https://CRAN.R-project.org/package=stars.\n\n\nPebesma, Edzer J., and Roger S. Bivand. 2005. “Classes and Methods\nfor Spatial Data in r” 5. https://CRAN.R-project.org/doc/Rnews/.\n\n\nPROJ contributors. 2021. PROJ Coordinate Transformation\nSoftware Library. Open Source Geospatial Foundation. https://proj.org/.\n\n\nRacine, Etienne B. 2016. “The Visual Raster Cheat Sheet.”\nhttps://rpubs.com/etiennebr/visualraster.\n\n\nTanaka, Kitiro. 1950. “The Relief Contour Method of Representing\nTopography on Maps.” Geographical Review 40 (3): 444. https://doi.org/10.2307/211219.\n\n\nTennekes, Martijn. 2018. “Tmap: Thematic\nMaps in r” 84. https://doi.org/10.18637/jss.v084.i06.\n\n\nTomlin, C. Dana. 1990. Geographic Information Systems and\nCartographic Modeling. Prentice Hall.\n\n\nWickham, Hadley. 2016. “Ggplot2: Elegant Graphics for Data\nAnalysis.” https://ggplot2.tidyverse.org."
   }
-]
+]
\ No newline at end of file
diff --git a/references.bib b/references.bib
index 1e7d46923c705ad632f09d97b8196615d2ca34c0..6b42d5ac1b9bfb18db4f9301bc0ad267ac60672f 100644
--- a/references.bib
+++ b/references.bib
@@ -443,4 +443,12 @@ Library},
 	year = {2017},
 	date = {2017},
 	url = {https://CRAN.R-project.org/package=rnaturalearth}
+}
+
+@book{bivand2008applied,
+  title={Applied spatial data analysis with R},
+  author={Bivand, Roger S and Pebesma, Edzer J and G{\'o}mez-Rubio, Virgilio and Pebesma, Edzer Jan},
+  volume={747248717},
+  year={2008},
+  publisher={Springer}
 }
\ No newline at end of file