user2221184
user2221184

Reputation: 153

Using INLA with raster in R

I've used INLA before with a SpatialPolygonsDataFrame before, but I have never used it with raster. I have been scouring the internet for many hours, reading vignettes and everything I can find, but still can't figure out how to use INLA with a raster. Below is just a simple example of what my data is like:

library("raster")
library("INLA")

lat = c(10, 10, 10, 10, 14, 14, 14, 14, 10, 10, 10, 10, 14, 14, 14, 14)
lon = c(20 ,24, 28, 32, 20, 24, 28, 32, 20, 24, 28, 32, 20, 24, 28, 32)
response = c(17.3, 17.4, 17.6, 17.9, 17.1, 17.0, 17.4, 17.5, 17.4, 17.4,
17.7, 17.8, 17.2, 17.1, 17.7, 17.9)
explan1 = c(31, 35, 33, 36, 32, 37, 36, 40, 32, 34, 33, 37, 35, 35, 39, 38)
explan2 = c(112, 116, 111, 114, 115, 117, 117, 112, 110, 114, 113, 117, 112,
113, 115, 116) 

data.df = data.frame(lat = lat, lon = lon, response = response, explan1 = 
explan1, explan2 = explan2)

myGrid = raster(ncol = 5, nrow = 5)

So I throw myself in front of all of you, begging for mercy and help in this manner.

Upvotes: 1

Views: 509

Answers (1)

HaakonNorwayMath
HaakonNorwayMath

Reputation: 21

For fitting the data, use your data.df (and your space time model).

For predicting/projecting on a raster, use inla.mesh.project. You can project result$summary.linear.predictor, result$summary.fitted.values, or result$summary.random, depending on your code and what you want to get.

If you want samples instead of summaries, use inla.posterior.sample, and project the correct part (depends on your model).

Space-time models are complicated, and working examples are very long. See the spde tutorial http://www.r-inla.org/examples/tutorials/spde-tutorial

Upvotes: 2

Related Questions