Learn R Programming

spatialEco (version 2.0-1)

raster.downscale: Raster Downscale

Description

Downscales a raster to a higher resolution raster using a robust regression

Usage

raster.downscale(
  x,
  y,
  scatter = FALSE,
  full.res = FALSE,
  residuals = FALSE,
  se = FALSE,
  p = 0.95,
  uncertainty = c("none", "prediction", "confidence")
)

Value

A list object containing:

  • downscale downscaled terra SpatRaster object

  • model MASS rlm model object

  • MSE Mean Square Error

  • AIC Akaike information criterion

  • parm.ci Parameter confidence intervals

  • residuals If residuals = TRUE, a SpatRaster of the residual error

  • uncertainty If pred.int = TRUE, SpatRaster's of the lower/upper prediction intervals

  • std.error If se = TRUE, SpatRaster's of the standard error

Arguments

x

A terra SpatRaster object representing independent variable(s)

y

A terra SpatRaster object representing dependent variable

scatter

(FALSE/TRUE) Optional scatter plot

full.res

(FALSE/TRUE) Use full resolution of x (see notes)

residuals

(FALSE/TRUE) Output raster residual error raster, at same resolution as y

se

(FALSE/TRUE) Output standard error raster, using prediction or confidence interval

p

The confidence/prediction interval (default is 95%)

uncertainty

Output uncertainty raster(s) of confidence or prediction interval, at same resolution as y. Options are c("none", "prediction", "confidence")

Author

Jeffrey S. Evans jeffrey_evans@tnc.org

References

Bruce, P., & A. Bruce. (2017). Practical Statistics for Data Scientists. O’Reilly Media.

Examples

Run this code
if (FALSE) {
library(geodata)
library(terra)

# Download example data (requires geodata package)
  elev <- geodata::elevation_30s(country="SWZ",  path=tempdir())
 slp <- terrain(elev, v="slope")
  tmax <- geodata::worldclim_country(country="SWZ", var="tmax", 
                                     path=tempdir())
    tmax <- crop(tmax[[1]], ext(elev))

# Downscale temperature
x=c(elev,slp)
  names(x) <- c("elev","slope")
y=tmax
  names(y) <- c("tmax")

tmax.ds <- raster.downscale(x, y, scatter=TRUE, residuals = TRUE,
                            uncertainty = "prediction", se = TRUE)
	
  # plot prediction and parameters	
  opar <- par(no.readonly=TRUE)
    par(mfrow=c(2,2))
      plot(tmax, main="Temp max")
      plot(x[[1]], main="elevation")
      plot(x[[2]], main="slope")
      plot(tmax.ds$downscale, main="Downscaled Temp max")
  par(opar)

  # Plot residual error and raw prediction +/- intervals
  opar <- par(no.readonly=TRUE)
    par(mfrow=c(2,2))
      plot(tmax.ds$std.error, main="Standard Error")
      plot(tmax.ds$residuals, main="residuals")
      plot(tmax.ds$uncertainty[[1]], 
	       main="lower prediction interval")
      plot(tmax.ds$uncertainty[[2]], 
	       main="upper prediction interval")
  par(opar)
  
  # plot prediction uncertainty
  opar <- par(no.readonly=TRUE)
    par(mfrow=c(2,1))
      plot(tmax.ds$downscale - tmax.ds$uncertainty[[1]], 
	       main="lower prediction interval")
      plot(tmax.ds$downscale - tmax.ds$uncertainty[[2]], 
	       main="upper prediction interval")  
  par(opar)  
 
}

Run the code above in your browser using DataLab