0

I have a question about Raster.Predict in R. Is it possible to use a spline model to generate a new raster using raster predict?

I have a set of data for which I would like to fit a spline model, fitting temperature to depth, then apply that spline model to a depth raster to generate a temperature raster. A minimum working example is below. The issue is that the returned raster, r2.spl, is identical to the input raster.

I'm guessing the spline model is not supported by raster predict, or am I missing something else?

#MWE for Raster Predict using smoothing spline
#Make data
x<- c( -1.5,-3.0,-4.5,-6.0,-7.5,-9.0,-10.5,-12.0,-13.5,-20.0)
y<- c(19.3,19.3,19.2,19.3,19.1,17.7,10.6,9.9,9.2,7.4)

# fit spline model
spl.xy<- smooth.spline(x,y , df=10)
plot(x,y)
lines(predict(spl.xy), col="red")

#generate raster
r1<- raster(nrow=10, ncol=10)
names(r1)<-c('x')
r1
spl.xy

# Assign random cell values
values(r1) <- runif(ncell(r1))*-20
plot(r1)

#predict new raster using Raster Predict
r2.spl<-predict(r1, spl.xy, progress="text")
plot(r2.spl)
r2.spl

Thanks in advance for any assistance.

Trevor
  • 1

1 Answers1

1

Instead of 'predict' you could use the raster function "interpolate" (it has an example for thin plate splines)

Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63
  • Thanks Robert, I had looked at the interpolate function but it looks to me like interpolate works to predict a spatial model to a raster layer. The model I would like to use to predict the raster is non-spatial. I'm currently working on extracting the values from the first raster, predicting new z values using spline predict, then generating a new raster based on the predicted z. Learning more about rasters in R at any rate! – Trevor Mar 18 '14 at 18:18
  • In that case it is probably overlay or calc that you can use. – Robert Hijmans Apr 23 '15 at 03:32