[R-sig-Geo] Problem in regression kriggin

Zia Uddin Ahmed zua3 at cornell.edu
Wed Jan 9 21:34:34 CET 2013


Your prediction grid must  have elevation data, that you predicted by OK. Newdata  file (prediction grid file) may be looks like this:
x
y
Elev

Data file: x  y Richness  Elev
Zia

Sent from my iPad

On Jan 9, 2013, at 2:33 PM, "halim10-fes" <halim10-fes at sust.edu> 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)
> p.sph <- predict(g.sph, model=fit.sph, newdata=grd)
> a<-(p.sph["Elev.pred"])
> library(raster)
> raster(a)
> s <- as(a, 'SpatialGridDataFrame')
> 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)
> 
> 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
> 
> 
> -- 
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list