I want to perform IDW interpolation using R, and more specifically, using the "idw"idw
command from the gstatgstat
package. Also, I want to use the optimal number of neighbors (point locations) and distance power, which will be determined by what combination of idp"idp" and nmax"nmax" produces the lowest RMSE in leave-one-out-cross validation. For this reason, after each run of IDW with different "nmax" and "idp" parameters, I perform the leave-one-out cross validation. In order to do this, I have written a double for loop in R that tests each idp"idp" parameter for each number of nmax"nmax" neighbors, but my script can't produce the result I want.
`power = seq(from = 1, to = 1.6, by = 0.1) neigh = seq(from = 4, to = 5, by = 1)
January
for(i in power) { for(j in 1:length(neigh) jan_idw = idw(Jan ~ 1, st, grd, nmax = power, idp = neigh) list_jan_idw = c(list_jan_idw,jan_idw ) krige.cv(Jan ~ 1, st, nfold = 52) } }`
power = seq(from = 1, to = 1.6, by = 0.1)
neigh = seq(from = 4, to = 5, by = 1)
# January
for(i in power) {
for(j in 1:length(neigh)
jan_idw = idw(Jan ~ 1, st, grd, nmax = power, idp = neigh)
list_jan_idw = c(list_jan_idw,jan_idw )
krige.cv(Jan ~ 1, st, nfold = 52)
}
}
For each run, I want the results to be stored in a data frame or matrix.