Problem in regression kriggin
On 01/09/2013 07:26 PM, halim10-fes wrote:
Dear Ashton, Andy and the group, Thank you very much for your suggestions. Yes, specifying ?data=data? is throwing the error and prk.rich<-krige(Richness~Elev, data, newdata=grd, model=fit.sph1) is not giving that. But regarding your second suggestion to have elevation covariate at all location on the prediction grid or DEM, I am lost again. Please help me out. The issue is as follows: Since I have no DEM at this moment, I have interpolated (ordinary krigging) the elevation of the whole study area based on 125 plots: g.sph <- gstat(gelev, id="Elev", model=fit.sph)
what is gelev?
p.sph <- predict(g.sph, model=fit.sph, newdata=grd) a<-(p.sph["Elev.pred"]) library(raster) raster(a)
this seems useless to me.
s <- as(a, 'SpatialGridDataFrame')
this too.
str(s) Formal class 'SpatialGridDataFrame' [package "sp"] with 4 slots ..@ data :'data.frame': 20212 obs. of 1 variable: .. ..$ Elev.pred: num [1:20212] 70.3 70.2 70.2 70.2 70.2 ... ..@ grid :Formal class 'GridTopology' [package "sp"] with 3 slots .. .. ..@ cellcentre.offset: Named num [1:2] 341960 2667253 .. .. .. ..- attr(*, "names")= chr [1:2] "x" "y" .. .. ..@ cellsize : Named num [1:2] 10 10 .. .. .. ..- attr(*, "names")= chr [1:2] "x" "y" .. .. ..@ cells.dim : Named int [1:2] 124 163 .. .. .. ..- attr(*, "names")= chr [1:2] "x" "y" ..@ bbox : num [1:2, 1:2] 341955 2667248 343195 2668878 .. ..- attr(*, "dimnames")=List of 2 .. .. ..$ : chr [1:2] "x" "y" .. .. ..$ : chr [1:2] "min" "max" ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots .. .. ..@ projargs: chr NA And then I tried regression krigging as follows: prk.rich<-krige(Richness~Elev, data, newdata=s, model=fit.sph1)
data has an Elev attribute, but s has an Elev.pred attribute. Mabye it helps if you first do a s$Elev = s$Elev.pred and then prk.rich<-krige(Richness~Elev, data, newdata=s, model=fit.sph1) There is much unclear, and none of this is reproducible for us. Doing regression kriging with interpolated variables sounds a bit like a Baron M?nchhausen strategy, pulling yourself up by your own hair.
But it gave me following error: Error in gstat.formula.predict(d$formula, newdata, na.action = na.action, : NROW(locs) != NROW(X): this should not occur In addition: Warning messages: 1: 'newdata' had 20212 rows but variable(s) found have 125 rows 2: 'newdata' had 20212 rows but variable(s) found have 125 rows I have gone through http://spatial-analyst.net/wiki/index.php? title=Regression-kriging_guide and other possible different guidelines but could not come to any conclusion. Any help is appreciated. Best regards, --------------- Md. Abdul Halim Assistant Professor Department of Forestry and Environmental Science Shahjalal University of Science and Technology,Sylhet-3114, Bangladesh. Cell: +8801714078386. alt. e-mail: xou03 at yahoo.com
Edzer Pebesma Institute for Geoinformatics (ifgi), University of M?nster Weseler Stra?e 253, 48151 M?nster, Germany. Phone: +49 251 8333081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de http://www.52north.org/geostatistics e.pebesma at wwu.de