I have a follow up question to Statistical analyses for survey against raster?

I have a very similar problem as the initial poster David. I am creating a multivariate model from raster data in order to predict a response variable. In my case I am using soil and climatic data to predict crop yields.

I independently came to a very similar conclusion as the answer posted by Aaron, to use zonal stats, export to R, and create a Random Forest model. However, I am now stuck because I want to create a raster in ArcGIS of my predicted yields based on the input rasters but I can't figure out how to translate the output from R to Arc.

In R I used this code:

fit <- randomForest(Yield ~ .,   data=data)
print(fit) # view results 
importance(fit) # importance of each predictor

The output a plot that reasonably predicts yield.

What I want to do is take the Random Forest model and use rasters of my predictor variables (e.g. slope) from a new location, and predict the yields for the new location. I understand how this works with simple linear regression but I can't wrap my head around how to do this with Random Forests. What equation does RF use to make the prediction plot? How can I get that equation and its coefficients from R to make a new map in Arc?

  • 3
    Why don't you just compute the predictions in R and write them to a raster export file that ArcGIS can read?
    – whuber
    Commented Jul 30, 2013 at 18:14
  • Or even take your entire workflow into R... Commented Jul 30, 2013 at 20:43
  • 2
    I looked into using raster processing in R for a different issue but I am doing it over a large area and R's rasters were too slow or crashed, so I don't think I can take the whole workflow into R. But if you have any suggestions on computing rasters in R I will look into it more. I also don't really understand how to random forests make the predictions so I don't get how to feed it data from new rasters so that I export those predictions to Arc...
    – BenHedges
    Commented Jul 31, 2013 at 19:38

1 Answer 1


The raster package makes R memory safe with large rasters. There is also a very convenient raster prediction function that works with R's generic predict. Because of this you can predict a large variety of models that use the predict wrapper. The primary requirement is that a model is predicted to a stack or brick raster object. To create this type of object your rasters have to align perfectly (i.e., rows, columns, resolution, bounding coordinates and origin coordinates).

I just posted a a tutorial on my Quantitative Ecology website that illustrates a workflow for specifying a spatial Random Forests model in R. I will be refining the content but, for now you will get the idea. I highly recommend that you not use symbolic syntax to specify your model. There are issues with how the Fortran code parses this type of syntax that causes speed and memory issues. Instead use indexing. i.e., mdl <- randomForest(y=dat[,"Yield"], x=[,2:10])

  • Jeffrey's answer looks great, I'll definitely look into using R as he outlined. I wanted to add that I found a cool tool for ArcGIS from Duke that uses Random Forests and other statistical models. It's is a bunch of arcpy scripts that tie to R and are pretty slick. If you are more familiar with Arc than R this might be a good a approach, but you will still need to know the basics of R to get it working. http://mgel.env.duke.edu/mget/
    – BenHedges
    Commented Sep 26, 2013 at 14:13
  • Please keep in mind that RF can be parameter sensitive. Because RF has to fit noise you can get a notably better fit if you apply a model selection procedure. The only thing that the Duke tool allows for is a kitchen sink model. GUI wrappers are nice and convenient but are not a substitute for statistical rigor. Data should be explored and models investigated. A "push button" approach is rarely adequate for deriving a good model. Commented Sep 26, 2013 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.