<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="http://www.r-bloggers.com/spatio-temporal-point-pattern-analysis-in-arcgis-with-r/"></div></div><div><a data-url="http://www.r-bloggers.com/spatio-temporal-point-pattern-analysis-in-arcgis-with-r/" data-counturl="http://www.r-bloggers.com/spatio-temporal-point-pattern-analysis-in-arcgis-with-r/" data-count="horizontal" data-text="Spatio-Temporal Point Pattern Analysis in ArcGIS with R" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://r-video-tutorial.blogspot.com/2016/07/spatio-temporal-point-pattern-analysis.html"> R tutorial for Spatial Statistics</a></strong>, and kindly contributed to <a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>This post would probably be the last in my series about merging R and ArcGIS. In August unfortunately I would have to work for real and I will not have time to play with <a target="_blank" href="https://r-arcgis.github.io/">R-Bridge</a> any more.<br>In this post I would like to present a toolbox to perform some introductory point pattern analysis in R through ArcGIS. Basically, I developed a toolbox to perform the tests I presented in my previous post about <a target="_blank" href="http://r-video-tutorial.blogspot.ch/2015/05/introductory-point-pattern-analysis-of.html">point pattern analysis</a>. In there, you can find some theoretical concepts that you need to know to understand what this toolbox can do.<br>I will start by introducing the sample dataset we are going to use, and then simply show the packages available.</p>
<p><span>Dataset</span><br>For presenting this toolbox I am using the same dataset I used for my <a target="_blank" href="http://r-video-tutorial.blogspot.ch/2015/05/introductory-point-pattern-analysis-of.html">previous post</a>, namely the open crime data from the UK. For this post I downloaded crimes in the London area from the whole 2015. As you can see from the image below we are talking about more than 950’000 crimes of several categories, all across London.</p>
<div></div>
<div><a target="_blank" href="http://i0.wp.com/3.bp.blogspot.com/-6o477V_jY4s/V4zLvUXvXGI/AAAAAAAASE4/ajJ47eHPvZwZi2KxUdPFg1oJPqHhvXvNwCLcB/s1600/Fig1b.jpg?ssl=1"><img src="http://i2.wp.com/3.bp.blogspot.com/-6o477V_jY4s/V4zLvUXvXGI/AAAAAAAASE4/ajJ47eHPvZwZi2KxUdPFg1oJPqHhvXvNwCLcB/s640/Fig1b.jpg?resize=456%2C244&ssl=1" border="0" data-recalc-dims="1"></a></div>
<p>I also included a polygon shapefile with the area around London and all its boroughs, this should be visible as blue lines around the city. I included this because point pattern analysis requires the user to set the border of the study area, as I mentioned in my <a target="_blank" href="http://r-video-tutorial.blogspot.ch/2015/05/introductory-point-pattern-analysis-of.html">previous post</a>.</p>
<p><span>Spatio-Temporal Subset</span><br>The first package I would like to present is a simple spatio-temporal subsetting tool. This is completely based on R but it is basically a more flexible version of the selection tools available in ArcGIS.</p>
<div><a target="_blank" href="http://i2.wp.com/2.bp.blogspot.com/-lCrMZVAV8dg/V4zRlueR6KI/AAAAAAAASFI/JNPhOj6L1lAdzGhlOu42VXQEYua6l8IRwCLcB/s1600/Fig4.jpg?ssl=1"><img src="http://i1.wp.com/2.bp.blogspot.com/-lCrMZVAV8dg/V4zRlueR6KI/AAAAAAAASFI/JNPhOj6L1lAdzGhlOu42VXQEYua6l8IRwCLcB/s640/Fig4.jpg?resize=456%2C262&ssl=1" border="0" data-recalc-dims="1"></a></div>
<p>Here users can select points based on various parameters at once. For example, they can subset the polygon shapefile, for example here I’m extracting the borough of Ealing, and extract points only for this area. Then they can subset by time, with the same strings I presented in my previous post about a <a target="_blank" href="http://r-video-tutorial.blogspot.ch/2016/07/time-series-analysis-in-arcgis.html">toolbox for time series analysis</a>. Optionally, they can also subset the dataset itself based on some categories. In this example I’m extracting only the drug related crimes, committed in Ealing in May 2015.<br>It is important to point out that in this first version of the toolbox users can only select one element in the SQL statements. For example here I have “name” = ‘Ealing’. In ArcGIS users could also put an AND and then specify another option. However, in the R code I did not put a way to deal with multiple inputs and conditions (e.g. AND, OR) and therefore only one option can be specified.<br>The result is a new shapefile, plotted directly on the ArcGIS console with the required subset of the data, as shown below:</p>
<div><a target="_blank" href="http://i0.wp.com/2.bp.blogspot.com/-ZUAwY6sk4rs/V4zS-P9fC4I/AAAAAAAASFU/3OcNYKV886A_XJ102OZb_yAI5qyDcS3lgCLcB/s1600/Fig5.jpg?ssl=1"><img src="http://i2.wp.com/2.bp.blogspot.com/-ZUAwY6sk4rs/V4zS-P9fC4I/AAAAAAAASFU/3OcNYKV886A_XJ102OZb_yAI5qyDcS3lgCLcB/s640/Fig5.jpg?resize=456%2C266&ssl=1" border="0" data-recalc-dims="1"></a></div>
<p><span>Spatio-Temporal Centroid</span><br>As you may already know, ArcGIS provides a function to calculate the centroid of a point pattern. However, if we wanted to test for changes in the centroid location with time we would need to first subset our data and then compute the centroid. What I did in this package is merge these two actions into one. This package, presented in the image below, loops through the dataset, subsetting the point pattern by time (users can choose between daily, monthly and yearly subsets) and then calculates the centroid for each time unit. Moreover, I also added an option to select the statistics to use between mean, median and mode.</p>
<div><a target="_blank" href="http://i0.wp.com/1.bp.blogspot.com/-Xh3aAyC_I0E/V4zcIje4JBI/AAAAAAAASFk/C7eVLPIglW4hcdDjQcUZQQ6RSOmX9X0AACLcB/s1600/Fig2.jpg?ssl=1"><img src="http://i0.wp.com/1.bp.blogspot.com/-Xh3aAyC_I0E/V4zcIje4JBI/AAAAAAAASFk/C7eVLPIglW4hcdDjQcUZQQ6RSOmX9X0AACLcB/s640/Fig2.jpg?resize=456%2C247&ssl=1" border="0" data-recalc-dims="1"></a></div>
<p>The results for the three statistics are presented below:</p>
<div><a target="_blank" href="http://i0.wp.com/4.bp.blogspot.com/-TqXgBRTa5cg/V4zcRmciMlI/AAAAAAAASFo/9Oxtvtd-tL0DP9qEKXz9i_QQ4w-DIlE1ACLcB/s1600/Fig3.jpg?ssl=1"><img src="http://i0.wp.com/4.bp.blogspot.com/-TqXgBRTa5cg/V4zcRmciMlI/AAAAAAAASFo/9Oxtvtd-tL0DP9qEKXz9i_QQ4w-DIlE1ACLcB/s640/Fig3.jpg?resize=456%2C322&ssl=1" border="0" data-recalc-dims="1"></a></div>
<p><span>Spatio-Temporal Density</span><br>This tool calculates the point density for specific regions and time frames by subsetting your dataset. This is something that you may be able to obtain directly from ArcGIS, but users would need to first subset their data and then perform the density analysis, this tool groups those two things into one. Moreover, the package <i>spatstat</i>, which is used in R for point pattern analysis has some clear advantages compared to the tool available in ArcGIS. For example, as I mentioned in my post it provides ways to calculate the best bandwidth for the density estimation. In the script this is achieved using the function <a target="_blank" href="http://www.inside-r.org/packages/cran/spatstat/docs/bw.ppl">bw.ppl</a>, but this can be changed if you need a different method, you just need to replace this function with another. Moreover, as pointed out in this <a target="_blank" href="https://www.e-education.psu.edu/geog586/book/export/html/1734">tutorial</a>, ArcGIS does not correct for edge effects.<br>Working with this package is very similar to the others I presented before:</p>
<div><a target="_blank" href="http://i1.wp.com/1.bp.blogspot.com/-n-qkU-BTJ-A/V4zq7rPUe7I/AAAAAAAASF4/RBXQSgfl_xYGOFomeKeWvdt2IzFoK9HigCLcB/s1600/ST_Density1.jpg?ssl=1"><img src="http://i1.wp.com/1.bp.blogspot.com/-n-qkU-BTJ-A/V4zq7rPUe7I/AAAAAAAASF4/RBXQSgfl_xYGOFomeKeWvdt2IzFoK9HigCLcB/s640/ST_Density1.jpg?resize=456%2C262&ssl=1" border="0" data-recalc-dims="1"></a></div>
<p>Users need to specify the input point pattern, then a polygon shapefile for the study area, which can be subset to reduce the area under investigation. Then users can include a temporal subsetting (here I used the string “2015-10/” which means from October to the end of the year, please refer to this <a target="_blank" href="http://r-video-tutorial.blogspot.ch/2016/07/time-series-analysis-in-arcgis.html">post </a>for more info) and subset their data extracting a certain category of crimes. Again here the SQL statements cannot include more than one category.<br>Finally, users need to provide a raster dataset for saving the density result. This needs to be a .tif file, otherwise in my tests the result did not appear on screen. The output of this script is the image below, for the borough of Bromley and only for robberies:</p>
<div><a target="_blank" href="http://i0.wp.com/4.bp.blogspot.com/-6wo8-QtVv0o/V4zsIlOcJpI/AAAAAAAASGA/SG5Z03wGYnEN22nmHd2s0GeVdjiP96zqwCLcB/s1600/ST_Density2.jpg?ssl=1"><img src="http://i0.wp.com/4.bp.blogspot.com/-6wo8-QtVv0o/V4zsIlOcJpI/AAAAAAAASGA/SG5Z03wGYnEN22nmHd2s0GeVdjiP96zqwCLcB/s640/ST_Density2.jpg?resize=456%2C282&ssl=1" border="0" data-recalc-dims="1"></a></div>
<p><span>Spatio-Temporal Randomness</span><br>This is another tool to perform a test for spatial randomness, the G function I explained in my previous <a target="_blank" href="http://r-video-tutorial.blogspot.ch/2015/05/introductory-point-pattern-analysis-of.html">post</a>, but on a subset of the main dataset. In fact, this test is available in ArcGIS under “Multi-Distance Spatial Cluster Analysis (Ripleys K Function)”, but in this case we are again performing it on a particular subset of our data.<br>The GUI is very similar to the other I presented before:</p>
<div><a target="_blank" href="http://i0.wp.com/3.bp.blogspot.com/-YXJPS4pWjUY/V4z635-iEMI/AAAAAAAASGU/piK4lMHcb6oUT7fPo-sKU4B_dyIgGKswgCLcB/s1600/ST_Random1.jpg?ssl=1"><img src="http://i2.wp.com/3.bp.blogspot.com/-YXJPS4pWjUY/V4z635-iEMI/AAAAAAAASGU/piK4lMHcb6oUT7fPo-sKU4B_dyIgGKswgCLcB/s640/ST_Random1.jpg?resize=456%2C294&ssl=1" border="0" data-recalc-dims="1"></a></div>
<p>The only difference is that here users also need to provide an output folder, where the plot created by R will be saved in jpeg at 300 dpi. Moreover, this tool also provides users with the point shapefile created by subsetting the main dataset.<br>The output for the borough of Tower Hamlets and only for drug related crimes in March 2015 is the plot below:</p>
<div><a target="_blank" href="http://i1.wp.com/4.bp.blogspot.com/-VdX3f2axoG0/V4z7YaY7P7I/AAAAAAAASGc/Z7vKTyKXKQsT1t1Qh_8bCfWDteVgNmWZwCLcB/s1600/ST_Random2.jpg?ssl=1"><img src="http://i2.wp.com/4.bp.blogspot.com/-VdX3f2axoG0/V4z7YaY7P7I/AAAAAAAASGc/Z7vKTyKXKQsT1t1Qh_8bCfWDteVgNmWZwCLcB/s640/ST_Random2.jpg?resize=456%2C326&ssl=1" border="0" data-recalc-dims="1"></a></div>
<p><span>Spatio-Temporal Correlogram</span><br>As the name suggests I develop this tool to calculate and plot a correlogram on a spatio-temporal subset of my data. For this example I could not use the crime dataset, since I do not have a continuous variable in it. Therefore I loaded the dataset of ozone measurements from sensors installed on trams here in Zurich that I used for my post about <a target="_blank" href="http://r-video-tutorial.blogspot.hu/2015/08/spatio-temporal-kriging-in-r.html">spatio-temporal kriging</a>. This tool uses the function <a target="_blank" href="http://www.inside-r.org/packages/cran/ncf/docs/correlog">correlog </a>from the package <i>xts </i>to calculate the correlogram. This function takes several arguments among which an increment, the number of permutations and a TRUE/FALSE flag if data are unprojected or not. These are all data that users will need to input once they use the tool and are additional options in the GUI, which for the other points is more or less identical to what I presented before, except for the selection of the variable of interest:</p>
<div><a target="_blank" href="http://i2.wp.com/2.bp.blogspot.com/-Xr2iwE4_YGM/V40FAQM7MYI/AAAAAAAASGs/p6nN4KFeBIEgqE1tKtA0r5_543YjpY6kACLcB/s1600/CorrelogramGUI.jpg?ssl=1"><img src="http://i1.wp.com/2.bp.blogspot.com/-Xr2iwE4_YGM/V40FAQM7MYI/AAAAAAAASGs/p6nN4KFeBIEgqE1tKtA0r5_543YjpY6kACLcB/s640/CorrelogramGUI.jpg?resize=456%2C346&ssl=1" border="0" data-recalc-dims="1"></a></div>
<p>The result is the image below, which is again saved in jpeg at 300 dpi. As for the spatio-temporal randomness tool, a shapefile with the spatio-temporal subset used to calculate the correlogram is also saved and opened in ArcGIS directly.</p>
<div><a target="_blank" href="http://i2.wp.com/3.bp.blogspot.com/-ZhyY8ja4V1I/V40F1XSHMRI/AAAAAAAASGw/YchmWpizQd4KCpl-l8VY9duqOGt_dMwLQCLcB/s1600/Correlogram.jpg?ssl=1"><img src="http://i2.wp.com/3.bp.blogspot.com/-ZhyY8ja4V1I/V40F1XSHMRI/AAAAAAAASGw/YchmWpizQd4KCpl-l8VY9duqOGt_dMwLQCLcB/s640/Correlogram.jpg?resize=456%2C221&ssl=1" border="0" data-recalc-dims="1"></a></div>
<p><span><br></span><span>Download </span><br>The tool is available, along with the sample data, from my GitHub archive:<br><a target="_blank" href="https://github.com/fveronesi/Spatio-Temporal-Point-Pattern-Analysis/upload">https://github.com/fveronesi/Spatio-Temporal-Point-Pattern-Analysis/upload</a></p>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="http://www.r-bloggers.com/spatio-temporal-point-pattern-analysis-in-arcgis-with-r/"></div></div><div><a data-url="http://www.r-bloggers.com/spatio-temporal-point-pattern-analysis-in-arcgis-with-r/" data-counturl="http://www.r-bloggers.com/spatio-temporal-point-pattern-analysis-in-arcgis-with-r/" data-count="vertical" data-text="Spatio-Temporal Point Pattern Analysis in ArcGIS with R" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://r-video-tutorial.blogspot.com/2016/07/spatio-temporal-point-pattern-analysis.html"> R tutorial for Spatial Statistics</a></strong>.</div>
<hr>
<a rel="nofollow" href="http://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="http://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="http://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="http://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="http://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="http://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="http://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="http://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="http://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="http://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="http://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="http://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="http://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="http://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="http://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="http://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="http://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="http://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="http://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/lyZhTV1UZM8"></a></div>