How can I use Adehabitat to obtain an .asc object with the predicted values of a niche model?

View: New views
2 Messages — Rating Filter:   Alert me  

How can I use Adehabitat to obtain an .asc object with the predicted values of a niche model?

by Núria Roura :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear all,

I'm using the package adehabitat in R to import several .asc files(=matrix), and also create a kasc object (=dataframe) with all of them.
 
The main idea is to use this kasc object to map the predicted values ofclimate-matching model for an overall area. However, I don't know how toproceed: Do I have to project the model (already stored in R) onto the kascobject directly, or convert the kasc object to a data frame where each rowrefers to a pixel?
 
 
On the other hand, I would also like to know how to obtain the XYcoordinates for each row of the kasc object.
 
Thank you very much. Cheers,
 
Núria Roura
 

_______________________________________________
AniMov mailing list
AniMov@...
http://www.faunalia.com/cgi-bin/mailman/listinfo/animov

Re: How can I use Adehabitat to obtain an .asc object with the predicted values of a niche model?

by Clément Calenge :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear Nuria,

Sorry for this late reply, I was very busy last week.

> The main idea is to use this kasc object to map the predicted values
> ofclimate-matching model for an overall area. However, I don't know
> how toproceed: Do I have to project the model (already stored in R)
> onto the kascobject directly, or convert the kasc object to a data
> frame where each rowrefers to a pixel?

The simplest way is to use the functions kasc2df and df2kasc. For
example, using the dataset puechabon:

## load the data:
data(puechabon)

## converts the kasc to data frame
li <- kasc2df(puechabon$kasc)
uu <- li$tab

## I simulate here a virtual response to build a model mod.
## You do not have to do this as you already have a model
resp <- sample(c(0,1), nrow(li$tab), replace=TRUE, prob=c(0.7, 0.1))
uu$resp <- resp
mod <- glm(resp~Elevation+Aspect+Slope+Herbaceous, family=binomial, data=uu)


## -------> OK, now, you have a model mod, and the data frame in ii$tab
pr <- predict(mod, newdata=li$tab)

## then, convert again to kasc. Note that kasc is a class of
## object designed to store several variables. So
## duplicate your variables (i.e. a data frame with the same column two
times)
res <- df2kasc(data.frame(res1 = pr, res2 = pr), li$index, puechabon$kasc)

## and finally get your map:
final <- getkasc(res,1)

final is the map containing the predictions of the model.

> On the other hand, I would also like to know how to obtain the
> XYcoordinates for each row of the kasc object.

The best way is probably to use the functions of the package "sp":

library(sp)
oo <- kasc2spixdf(puechabon$kasc)
coordinates(oo)

Hope this helps,


Clem.

--
Clément CALENGE
LBBE - UMR CNRS 5558 - Université Claude Bernard Lyon 1 - FRANCE
tel. (+33) 04.72.43.27.57
fax. (+33) 04.72.43.13.88


_______________________________________________
AniMov mailing list
AniMov@...
http://www.faunalia.com/cgi-bin/mailman/listinfo/animov