David,

Thanks, that was helpful. The variable (layer) name was not set, and even
when it was set, it was lost again 'interpolate'. I fixed this in raster
version 1.9-52 (now on CRAN). Such that you can do:

layerNames(zinc) <- 'zinc'
mc <- interpolate(zinc, mg1,xyOnly=F)

Robert

On Fri, Dec 2, 2011 at 2:55 AM, David Stephens (Cefas) <
David.Stephens@cefas.co.uk> wrote:

> Robert,****
>
> ** **
>
> Here is a reproducible example. If we pretend that copper concentration is
> linearly dependant on zinc. Is it possible to make it use the values of the
> zinc raster as the trend variable?****
>
> ** **
>
> library(raster)****
>
> library(gstat)****
>
> ** **
>
> r <- raster(system.file("external/test.grd", package="raster"))****
>
> data(meuse)****
>
> mg <- gstat(id = "zinc", formula = zinc~1, locations = ~x+y, data=meuse,
> nmax=7, set=list(idp = .5))****
>
> zinc <- interpolate(r, mg)****
>
> zinc <- mask(z, r)****
>
> ** **
>
> coordinates(meuse) <- ~x+y****
>
> projection(meuse) <- projection(zinc)****
>
> ** **
>
> var_model <- vgm(psill=72,model='Gau',range=72,nugget=0)****
>
> ** **
>
> mg1 <- gstat(id = "copper", formula = copper~zinc, data=meuse,
> model=var_model)****
>
> c <- interpolate(zinc, mg1,xyOnly=F)****
>
> ** **
>
> Cheers, David.****
>
> ** **
>
> ** **
>
> > packageVersion('gstat')****
>
> [1] ‘1.0.9’****
>
> > packageVersion('raster')****
>
> [1] ‘1.9.33’****
>
> > R.Version()$v****
>
> [1] "R version 2.13.2 (2011-09-30)"****
>
> ** **
>
> ** **
>
> *From:* Robert J. Hijmans [mailto:r.hijmans@gmail.com]
> *Sent:* 01 December 2011 17:28
> *To:* David Stephens (Cefas)
> *Cc:* r-sig-geo@r-project.org
> *Subject:* Re: [R-sig-Geo] KED predictions using raster package****
>
> ** **
>
> David, ****
>
> Can you provide a reproducible example, perhaps based on the below (from
> ?interpolate), but then mimicking what you are doing?****
>
> Robert****
>
> ** **
>
> library(gstat)****
>
> library(raster)****
>
> r <- raster(system.file("external/test.grd", package="raster"))****
>
> data(meuse)****
>
> mg <- gstat(id = "zinc", formula = zinc~1, locations = ~x+y, data=meuse,
> nmax=7, set=list(idp = .5))****
>
> z <- interpolate(r, mg)****
>
> z <- mask(z, r)****
>
> ** **
>
> On Thu, Dec 1, 2011 at 4:51 AM, David Stephens (Cefas) <David.Stephens@cefas.co.uk> wrote:****
>
> Hi,
>
> Im trying to apply a gstat model that incorporates an external drift
> variable to a raster, using the interpolate function of the raster
> package. I seem to be having trouble making it use the values of the
> raster layer as the covariate specified in the gstat formula. Any help
> greatly appreciated.
>
>
>
> David Stephens.
>
>
>
> > z <- raster('C:/geodata/astrium_bathy/6Sec/mosaic_crop_CH_UTM30.img')
>
> > z
>
> class       : RasterLayer
>
> dimensions  : 2759, 5918, 16327762  (nrow, ncol, ncell)
>
> resolution  : 100, 100  (x, y)
>
> extent      : 266620.4, 858420.4, 5440120, 5716020  (xmin, xmax, ymin,
> ymax)
>
> coord. ref. : +proj=utm +zone=30 +ellps=WGS84 +datum=WGS84 +units=m
> +no_defs +towgs84=0,0,0
>
> values      : C:\geodata\astrium_bathy\6Sec\mosaic_crop_CH_UTM30.img
>
> min value   : -113.719
>
> max value   : 7.293
>
>
>
> > projection(z) <- projection(psa.utm30)
>
> > CH.V1.M <- gstat(NULL,id=
> "CH.V1",formula=V1~z,locations=psa.utm30,model=CH.V1.vgm$var_model,nmax=
> 100)
>
> > CH.V1.int <- interpolate(z,CH.V1.M,xyOnly=F,na.rm=T,overwrite=T)
>
> Error in model.frame.default(terms.f, newdata, na.action = na.action) :
>
>  object is not a matrix
>
> In addition: Warning message:
>
> 'newdata' had 2497396 rows but variable(s) found have 1 rows
>
>
> This email and any attachments are intended for the name...{{dropped:13}}
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo****
>
> ** **
>
>
>
>
> This email and any attachments are intended for the named recipient only.
> Its unauthorised use, distribution, disclosure, storage or copying is not
> permitted. If you have received it in error, please destroy all copies and
> notify the sender. In messages of a non-business nature, the views and
> opinions expressed are the author's own and do not necessarily reflect
> those of Cefas. Communications on Cefas’ computer systems may be monitored
> and/or recorded to secure the effective operation of the system and for
> other lawful purposes.
>
>
>

	[[alternative HTML version deleted]]

