Reputation: 1
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.
Upvotes: 0
Views: 558
Reputation: 47146
Instead of 'predict' you could use the raster function "interpolate" (it has an example for thin plate splines)
Upvotes: 1