spatial.uncertainty: Spatial uncertainty

View source: R/spatial.uncertainty.R

spatial.uncertaintyR Documentation

Spatial uncertainty

Description

Calculates the standard errors and +/- 95

Usage

spatial.uncertainty(x, y, vars, b = 99, seed = NULL, out.raster = NULL, ...)

Arguments

x

randomForest or ranger model object

y

raster object representing prediction

vars

raster stack/brick used to predict y

b

number of jackknife replicates

seed

Optional seed

out.raster

Optional raster to disk

...

Additional arguments passed to writeRaster

Details

Uses an Infinitesimal Jackknife to calculate standard errors, lower and upper 95 prediction and vars are a raster stack/brick object used for the spatial estimates. The names of the parameters used in the model must match vars and the extent of y and vars must be the same. The spatial prediction should represent a continuous process or probability and not a nominal prediction.

Value

raster stack object with standard errors, lower and upper CI's.

Author(s)

Jeffrey S. Evans <jeffrey_evans@tnc.org>

References

Wager, S., T. Hastie, & B. Efron (2014) Confidence Intervals for Random Forests: The Jackknife and the Infinitesimal Jackknife. J Mach Learn Res 15:1625-1651.

Examples

## Not run: 
library(randomForest)
library(raster)
library(ranger)

r <- brick(system.file("external/rlogo.grd", package="raster"))

# known presence and absence points
p <- matrix(c(48, 48, 48, 53, 50, 46, 54, 70, 84, 85, 74, 84, 95, 85, 
   66, 42, 26, 4, 19, 17, 7, 14, 26, 29, 39, 45, 51, 56, 46, 38, 31, 
   22, 34, 60, 70, 73, 63, 46, 43, 28), ncol=2)
a <- matrix(c(22, 33, 64, 85, 92, 94, 59, 27, 30, 64, 60, 33, 31, 9,
   99, 67, 15, 5, 4, 30, 8, 37, 42, 27, 19, 69, 60, 73, 3, 5, 21,
   37, 52, 70, 74, 9, 13, 4, 17, 47), ncol=2)

# extract values for points
xy <- rbind(cbind(1, p), cbind(0, a))
dat <- data.frame(cbind(pa=xy[,1], extract(r, xy[,2:3])))

# randomForest example
( rfm <- randomForest(x=dat[,2:ncol(dat)], y=as.factor(dat$pa)) )
  e <- predict(r, rfm, type="prob", index=2)

( ci <- spatial.uncertainty(rfm, e, r) )

# Ranger example
( rfm <- ranger(x=dat[,2:ncol(dat)], y=as.factor(dat$pa), 
                probability = TRUE, num.trees = 501, 
				importance="permutation", write.forest = TRUE,  
				keep.inbag = TRUE) )
  rf.predict <- function(model, data) {
    as.numeric(ranger:::predict.ranger(model, data = data,
      type = "response")$predictions[,2])
  }				
  e <- predict(vars, rfm, fun=rf.predict, progress="window")

( ci <- spatial.uncertainty(rfm, e, r) )

## End(Not run) 


jeffreyevans/rfUtilities documentation built on Nov. 12, 2023, 6:52 p.m.