1

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.

zx8754
  • 52,746
  • 12
  • 114
  • 209
user2221184
  • 133
  • 1
  • 8
  • What is it you want to do? And please show us example code that works. `a = c(8 random values)` is not proper `R` code – Robert Hijmans May 16 '15 at 01:48
  • I've improved my example. I am trying to do a space-time model that will try and model future event using INLA. Without using raster data, I would simply make a SpatialPolygonsDataFrame, then with that use poly2nb and construct a space-time table before doing my formula specs and running the INLA model. Any help on how to do this using raster data would be greatly appreciated. – user2221184 May 17 '15 at 17:44

1 Answers1

2

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