[R] Conditioned Latin Hypercube Sampling within determined distance

SergioHGS shenrike at hotmail.com
Mon Jun 25 20:05:44 CEST 2012


Hi,

I'm sorry for not explaining well. I'm trying to do my best, but it's
alittle complicated for me. I will send what I've tried but I think I should
also provide some files to make possible for you to run the codes I'm
running, but i couldn't find a way to do it.
I have 2 rasters to represent environmental characteristics of my area
(slasc.asc and weasc.asc). I also have a raster containing the cost of
reaching every place in the area (euc_.asc). The function "clhs" allows to
sample in places according to lowest-reaching costs, it means the clhs will
choose points where is easier to go. To make this, I should use the code 

res <- clhs(s, size = 30, iter = 2000, progress = FALSE, simple = FALSE,
cost = "cost").

Then the R returns the error:

Error in .local(x, ...) : Could not find the cost attribute

I don't know what i'm doing wrong. I was wondering if somebody knows what I
should try.  The R-help says the cost is a character giving the name or an
integer giving the index of the attribute in x that gives a cost that can be
use to constrain the cLHS sampling. If NULL (default), the cost-constrained
implementation is not used. 
Below it's the codes I'm using:

require(raster)
require(clhs)
require(proj4)
require(rgdal)
# 1 - load the data 
r1<-raster("D:/Sg/Lavr/R/slasc.asc")
r2<-raster("D:/Sg/Lavr/R/weasc.asc")
#2 - load cost raster # I'M NOT SURE IF THIS STEP IS CORRECT
rcost<-raster("D:/Sg/Lavr/R/euc_.asc")
#3 - set spatial references
projection(r1) <- "+proj=utm +zone=23 +south +ellps=WGS84 +datum=WGS84
+units=m +no_defs"
projection(r2) <- "+proj=utm +zone=23 +south +ellps=WGS84 +datum=WGS84
+units=m +no_defs"
projection(rcost) <- "+proj=utm +zone=23 +south +ellps=WGS84 +datum=WGS84
+units=m +no_defs"
#4 - creates a multiple raster*object
s = stack(r1, r2, rcost)
#5 - Conditional latin hypercube sampling
res <- clhs(s, size = 30, iter = 2000, progress = FALSE, simple = FALSE,
cost = "rcost")

Error in .local(x, ...) : Could not find the cost attribute.

Thank you!

Sergio




--
View this message in context: http://r.789695.n4.nabble.com/Conditioned-Latin-Hypercube-Sampling-within-determined-distance-tp4633974p4634457.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list