I would like to study the association between categorical rasterised environmental variables in R. Is there any way to do it in R?

  • $\begingroup$ This question is pretty broad -- can you expand on your question and provide any more specifics on what you're trying to accomplish? What steps have you taken thus far to identify resources in R to do what you're trying to do? What are the major gaps in the search for resources you've undertaken so far? $\endgroup$
    – dlid
    Oct 12 '20 at 20:34
  • $\begingroup$ I have a set of environmental variables in raster format where I want to study the dependencies between them. To do so I was thinking of using association tests such as chi-squared test. I want to know if there are any libraries in R dedicated to that. $\endgroup$
    – user1988
    Oct 12 '20 at 21:45

The raster package in R is devoted to handle with raster data: https://cran.r-project.org/web/packages/raster/raster.pdf

I'm not quite sure about what do you want to do with your data. Since I assume your rasters contain quantitative data, you can use the function 'layerStats' to get the correlation between two rasters. However, to use it, you must join the raster in a multiband raster using 'stack'. Here is an example written by me:


#load the rasters
provision <- raster('prov_mask.tif')
cultural <- raster('cult_mask.tif')
regulating <- raster('regul_mask.tif')

#standardize the rasters with same extent and crs
cultural <- raster(vals=values(cultural),ext=extent(provision),
regulating <- raster(vals=values(regulating),ext=extent(provision),

#do the correlation matrix among the three rasters
SE <- stack(provision, regulating, cultural)
cor.SE <- layerStats(SE, 'pearson', na.rm = TRUE)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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