Skip to content

Using the ENFA from adehabitatHS in R with sp classes

6 messages · Mathieu Basille, AGG18 at pitt.edu, alannie

#
Hi folks!

I have been having significant difficulty using the sp classes to perform
the ENFA in R. 
The objective of this posting is to inquire about how to "prepare data for
the ENFA," which in previous versions of the software package adehabitat was
carried out via 'data2enfa' and the 'dudi.pca' functions.

I have been using the code:

#Add table of coordinate locations
#Convert to class sp
#Import .asc variable maps into R.
colname = basename("bio1.asc"), proj4string = CRS(as.character(NA)))
colname = basename("bio2.asc"), proj4string = CRS(as.character(NA)))

#etc

#Combine data maps
After the last bit, I cannot go forward. 

I need to somehow combine the 'join' data which contains variable maps with
the 'locs' data which has species location data so that I can get the
principle component analysis from function dudi.pca. 

In the documentation for package adehabitatHS it says:

## We prepare the data for the ENFA
tab <- slot(map, "data")
pr <- slot(count.points(locs, map), "data")[,1]

and then goes on to do the PCA and ENFA

I have already tried working through the example 'lynxjura' multiple times
and have no greater understanding of what comprises the data (noted as
"data" in the example) or how to utilize the slot function in my own data
set. 

I would like assistance to put my data in the format for the PCA and the
ENFA. 

Thanks in advance for all assistance. 

Alannie






--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Using-the-ENFA-from-adehabitatHS-in-R-with-sp-classes-tp7584418.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
#
Dear Alannie,

Obviously all these "data"s are confusing :)
The 'enfa' example uses a dataset call 'lynxjura' (not 'data'), which is a 
list with several elements. One of these elements is the maps, with the 
name 'map' (singular!). This is what you want to achieve. This is simply a 
SpatialPixelsDataFrame, but as far as I can tell, a SpatialGridDataFrame 
will do too (if you want to know more about the differences between these 
two, check the sp vignette).

So, following your example, just replace "map" by "join", and it should 
work. The 'slot(map, "data")' line extracts the data frame storing the data 
of the map, since the dudi.pca and enfa functions do not directly need the 
spatial attributes.

Hope this helps,
Mathieu.


Le 08/14/2013 02:23 PM, alannie a ?crit :

  
    
#
Dear Mathieu,

Thank you for the assistance.

Upon executing the situation where I take the material of 'join' to
replace 'map' I receive an error:
bio6 at data, bio7 at data)
Error in slot(join, "data") :
  no slot of name "data" for this object of class "data.frame"

the description of what is compiled in the maps contain in 'join' are:
bio1.asc bio2.asc bio3.asc bio4.asc bio5.asc bio6.asc bio7.asc
1       NA       NA       NA       NA       NA       NA       NA
2       NA       NA       NA       NA       NA       NA       NA
3       NA       NA       NA       NA       NA       NA       NA
4       NA       NA       NA       NA       NA       NA       NA
5       NA       NA       NA       NA       NA       NA       NA
6       NA       NA       NA       NA       NA       NA       NA
[1] "data.frame"


Do I need to create a slot or name an element 'data?'

Please advise further.

Cheers,
Alannie
#
Sorry I didn't spot that one before... Please try:

join<- cbind(bio1, bio2, bio3, bio4, bio5, bio6, bio7)

and check the class and data:

summary(join)

You want this to be of class SpatialGridDataFrame (or 
SpatialPixelsDataFrame), so you want to keep the spatial attributes 
together with the data that comes with it.

Also note that, given a Spatial*DataFrame, 'xx at data' is equivalent to 
'slot(xx, "data")'.

Hope this helps,
Mathieu.


Le 08/14/2013 03:37 PM, AGG18 at pitt.edu a ?crit :

  
    
#
Dear Mathieu,

The join/cbind/@data is wonderful!

However, if I try to join the location data as a data.frame or sp class it
does not work.

What would be the solution to this portion of the equation?

In other words, how to I add locations to the formula?


Thank you a million * ? !


Alannie




--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Using-the-ENFA-from-adehabitatHS-in-R-with-sp-classes-tp7584418p7584422.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
#
Not sure where your problem is. If you have the SpatialPixelsDataFrame and 
the SpatialPoints, did you try to go on like in the example?

tab <- slot(map, "data")
pr <- slot(count.points(locs, map), "data")[,1]
pc <- dudi.pca(tab, scannf = FALSE)
(enfa1 <- enfa(pc, pr, scannf = FALSE, nf = 3))

etc., etc.

Mathieu.


Le 08/14/2013 04:46 PM, alannie a ?crit :