

Dear All.
I am very new in programing. I try to perform a cokriging in gstat.
I have four variable and coordinates of each variables are differ(non-Collocated model).
Each variable and its coordinates are saved in d1-d4 text file.
My program for fitting cross-variogram is:

m<-vgm(1954,"Gau",80017,225)
g <- gstat(NULL, id = "k", form =k ~ 1,data=d1)
g <- gstat(g, id = "hgrad", form =hgrad~ 1,data=d2)
g <- gstat(g, id = "res", form =res~ 1,data=d3)
g <- gstat(g, id = "wtab", form =wtab~ 1,data=d4)
vm <- variogram(g)
vm.fit <- fit.lmc(vm, g, model=m,fit.ranges =F, fit.lmc =F)
plot(vm, vm.fit,main="Empirical and Fitted Cross-Variogram ",col="black",pch=20)

I have two problem:

1- How can I make a grid with shapefile(like meuse.grid). I want my results plot in my map.
My program for create a grid is:
gg<-spsample(shapefile,n=1000,type="nonaligned",cellsize=200)
plot(gg)
coordinates(gg)<-~x+y
gridded(gg) <- TRUE 
grd = as(gg, "SpatialPixels") 
image(grd) 

2-How can I perform cokriging
When I crate a grid with below program:
x.range <- as.integer(range(d1@coords[,1]))
y.range <- as.integer(range(d1@coords[,2]))
plot(x.range,y.range)
grd <- expand.grid(x=seq(from=x.range[1], to=x.range[2], 
by=500), y=seq(from=y.range[1], to=y.range[2], by=500) )
coordinates(grd) <- ~ x+y
gridded(grd) <- TRUE
The cokriging run by Inverse distance but I try to perform ordinary cokriging.


3-When I use below program for ceate grid and perform predict
 
gg<-spsample(shapefile,n=1000,type="nonaligned",cellsize=200)
plot(gg)
coordinates(gg)<-~x+y
gridded(gg) <- TRUE 
grd = as(gg, "SpatialPixels") 
image(grd) 
cok.maps <- predict(vm.fit, meuse.grid)
The Erorr is:
Error in predict.gstat(vm.fit, grd) : 
  gstat: value not allowed for: variograms do not satisfy a legal model

What do I do?

	[[alternative HTML version deleted]]

