<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/some-thoughts-about-bayesian-kriging-in-inla/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.seascapemodels.org/rstats/2017/09/07/bayesian-kriging-thoughts.html"> Bluecology blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<h1>Some thoughts about Bayesian Kriging in INLA</h1>
<p>I have been playing around with spatial modelling in the R <a rel="nofollow" href="http://www.r-inla.org/home" target="_blank">INLA</a> package. This blog just records a few thoughts I have had about using INLA for kriging (spatial interpolation). I am keen to discuss these ideas with others.</p>
<p>Kriging is super useful tool for ‘filling in the gaps’ between sampling sites. e.g. see <a rel="nofollow" href="http://www.seascapemodels.org/rstats/2017/02/22/spatial-statistics-photos.html" target="_blank">this map </a>. Handy if you want to make a map, or need to match up two spatial data sets that overlap in extent, but have samples at different locations.</p>
<p>You can do kriging the old fashioned way in R or even in ARC GIS. The advantage of using INLA though is that you can use Bayesian inference to do your kriging.</p>
<p>This means you can interpolate non-normal error structures (like counts or presence/absence data). You can also include other fixed covariates, like a spatial layer of temperatures. Or you can even include, other random effects. For instance, you could do spatio-temporal kriging if you had time-series at each of your sites.</p>
<p>For a simple tutorial on spatial modelling in INLA see <a rel="nofollow" href="https://www.math.ntnu.no/inla/r-inla.org/tutorials/spde/inla-spde-howto.pdf" target="_blank">here</a> or my <a rel="nofollow" href="http://www.seascapemodels.org/rstats/2017/02/22/spatial-statistics-photos.html" target="_blank">blog series on making maps from geotagged photos</a>.</p>
<p>Sorry, there will be no code or figures with this post. I can’t share the data for the example I am working on yet. Will post it in a few months if I can.</p>
<p>So here are some thoughts I have had while working with my latest INLA model.</p>
<h2>Grid scale for interpolations</h2>
<p>The standard advice, that I read somewhere on the INLA page was that the grid size or triangulation you use should have edges that are somewhat smaller than the spatial range parameter (as explained in my <a rel="nofollow" href="http://www.seascapemodels.org/rstats/2017/02/22/spatial-statistics-photos.html" target="_blank">blog</a>).</p>
<p>However, I have been finding that tweeking the edge size (e.g. making the <code>cutoff</code> parameer in <code>inla.mesh.2d</code> larger) can be useful for visualising spatial trends at different scales.</p>
<p><strong>If you make your grid size much larger than the distance between the closest sites, you get a much better picture of large scale spatial trends.</strong></p>
<p>Say you have highly clustered sampling and there is a large amount of variability within clusters that swamps large-scale trends. For instance you may be measuring stuff on coral reefs as you sail your boat around. It is likely you will hit up a bunch of sites nearby to each other, then sail off to another reef some distance away then survey another bunch of sites.</p>
<p>The end result will be lots of clusters of samples that have large distances between them. Coral reef data are typically highly variable, even at small spatial scales and large-scale (100s km) trends are often quite weak (though real!). Fish surveys are the worst, because fish swim around, often in schools, so often true ecological trends are well hidden under a stack load of observer error.</p>
<p>If you interpolate reef data with a very small grid, that matches the scale parameter, you end up with a very patchy looking map. Whereas, if you use a large grid, you get a much smoother looking map that just captures the weaker, but perhaps more important, broadscale trends.</p>
<p>This map will hide the considerable local scale variation, so it is worth plotting that as a separate map too.</p>
<p>Effectively, this is just like doing averages on a small vs large grid.</p>
<p>I can’t find it right now, but someone did write a guidance tutorial for setting up grids/triangulations for INLA. If you know where it is, let me know and I will post it.</p>
<h2>Smoothing parameter</h2>
<p>I hadn’t played around much with the <code>alpha</code> parameter in INLA’s Matern model before. You change it when specifying the matern mesh before fitting your model <code>inla.spde2.matern(mesh, alpha = 1.9)</code>.</p>
<p>Large values (approaching 2) give smoother trend, whereas values closer to zero will show more of the bumps in a spatial field. Of course, choice of this parameter will interact with how you define your grid.</p>
<p>It can make a big difference to your resulting interpolation. I am not sure much advice exists on how to choose it. I would be interested to hear from others what they think.</p>
<p>Two ways to choose this parameter would be based on aesthetics of the resulting map (if you are just making a map), or perhaps using cross-validation or information criteria to choose the parameter.</p>
<h2>Playing with priors to get shrinkage to a null hypothesis</h2>
<p>Some of the INLA developers and co recently published a <a rel="nofollow" href="https://projecteuclid.org/euclid.ss/1491465621" target="_blank">cool paper about choosing priors for hyperparameters</a>. The hyperpriors control how much your spatial surface can vary. They are quite hard to set based on true ‘prior evidence’, because they are abstract parameters.</p>
<p><a rel="nofollow" href="https://projecteuclid.org/euclid.ss/1491465621" target="_blank">Simpson and co</a> give an example of the variance parameter in a single dimensional model, but the same idea applies to spatial gradients too. (I also have a blog about hyperpriors for time-series <a rel="nofollow" href="http://www.seascapemodels.org/rstats/2017/06/21/bayesian-smoothing.html" target="_blank">here</a>).</p>
<p>If you make your hyperprior on spatial/temporal variance very peaked near zero with a long tail, then effectively it is like saying there is probably no spatial variance and a small chance of lots of spatial variance.</p>
<p>The effect in your model will be the spatial trend ‘shrinks’ toward a flat gradient, unless your data are strong enough to overcome the no gradient prior. This is like having a null hypothesis of no gradients.</p>
<p>e.g. see the last figure in my <a rel="nofollow" href="http://www.seascapemodels.org/rstats/2017/06/21/bayesian-smoothing.html" target="_blank">blog here</a> where a stronger prior effectively fits a model to a time-series with a slope of zero (ie no temporal trend).</p>
<p>An even more useful way of thinking about this is that you can play around with the priors to get the desired level of smoothing in your spatial (or temporal) model.</p>
<p>I think this idea is pretty radical. We are shifting away from thinking that priors should be unininformative if you have no prior data (like in the bad old days of the Winbugs <code>gamma(0.001, 0.001)</code> prior for variances), and towards a philosophy where some priors can be tuned and (specifically hyperpriors for variance parameters) should be very very informative.</p>
<p>This is a pretty powerful idea. In effect an informative prior can encode our null hypothesis and a stronger prior will require stronger trends in the data to ‘break away from’ the null hypothesis. If you really want to show your data contain a powerful trend, then try to smash it with a very informative prior that peaks near zero variance.</p>
<p>As a hint of a paper I want to work on soon, imagine you have super variable data that have stack loads of observer error and weak ecological trends (like surveys of schooling fish on coral reefs). You want to estimate the ecological gradient under all that noise. Well you could get prior information on the extent of spatial variation attributable to true ecological variable. You could then use that prior information to inform a variance prior that helps you estimate the latent spatial field for true ecological gradient. In effect, you are removing the observer signal.</p>
<p>That’s all for now. <a rel="nofollow" href="http://www.seascapemodels.org/people/Chris-Brown.html" target="_blank">Email me</a> or <a rel="nofollow" href="https://twitter.com/bluecology" target="_blank">tweet</a> me if you like this, or think I am talking rubbish.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.seascapemodels.org/rstats/2017/09/07/bayesian-kriging-thoughts.html"> Bluecology blog</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/XrB2g7NZnLE" height="1"></a></div>