Thanks for the very helpful reply! I will try it right now! I need to
present at a conference in early April and would like to get these
results before that!
Just three quick questions before you go to enjoy the Easter weekend:
- how do I get the values out of 'jj' (## jj contains the values of
elevation inside the home range of the animals) to calculate mean,
variance, etc, across all the points in 'jj'? I assume 'jj' is of class
'kasc'. In my case it might be 'asc' as I will have only a single home
range at the time (one animal).
Just a small correction to my previous e-mail. If you creates jj with:
jj<-lapply(foo, function(x) x*el)
jj is not a map of class "kasc". To convert jj to the class "kasc", copy the
attributes of the map "foo" to jj with getkascattr:
jj<-getkascattr(foo, jj)
image(jj)
And now, jj is map of class "kasc", i.e. a data.frame with each column
corresponding to a map. All the pixels located inside the home ranges
are coded by numeric values in the data frame, and pixels located outside
the home ranges are coded by NA. So you can get the pixels values with
something like:
oo<-lapply(jj, function(x) x[!is.na(x)])
oo is a list with one component per animal. Each component corresponds to a
vector of pixels inside the animals home range. It is quite easy after
that to get
values such as average, mean, median, etc.:
lapply(oo, summary)
lapply(oo, mean)
lapply(oo, sd)
etc.
- can I get the points out of the 'kasc' object in a way that I can
still run spatial statistics on them? I would like to calculate the
nugget and range for the NDVI values within the home range.
I never performed such spatial statistics with home ranges but this
could certainly be done... IMHO, the best way to achieve is also to get
the coordinates of the kept pixels when computing the vector oo:
xyc<-getXYcoords(jj)
## xyc contains the coordinates of the pixels of the maps
## it is a list with two components, the vectors of coordinates
## of the pixels of the maps
## compute the x values
xc <- rep(xyc$x, times=length(xyc$y))
yc <- rep(xyc$y, each=length(xyc$x))
xyc<-data.frame(x=xc,y=yc)
lixyc<-lapply(1:ncol(jj), function(x) xyc[!is.na(jj[,x]),])
## So that each point in oo is associated to its coordinates
## in lixyc
## for example
plot(lixyc[[1]], col=grey(oo[[1]]/300), pch=15, cex=4, asp=1)
plot(lixyc[[2]], col=grey(oo[[2]]/300), pch=15, cex=4, asp=1)
plot(lixyc[[3]], col=grey(oo[[3]]/300), pch=15, cex=4, asp=1)
Then you have to compute a variogram. I never used functions
allowing such analyses, but it seems that the package nlme has a function
Variogram...
- do you know how to convert a polygon shapefile into the same class as
produced by the command kernelUD? Alternatively I could import a raster
version of the polygon shape file, convert it to the correct format, and
repeat the spatial join method you are suggesting for the home ranges!
I'm sorry, I do not have any easy solution to this problem. The function
kernelUD
returns a *raster* map of class "asc", a central class in adehabitat. I
don't know how
to rasterize a shapefile in R (the library shapefiles or Maptools, which
deal with
shapefiles do not allow such operations). Maybe the simpler way would be to
rasterize the shapefile with a GIS...