Skip to content

Presence-absence to Occurrence Dataset?

4 messages · Coffey, Elyse D. (UMSL-Student), David Valentim Dias, Tom_Philippi at nps.gov +1 more

#
Elyse--

For the first step of converting your community matrix to triplets of
{site, species, presence}, you can use melt() from the flexible & powerful
reshape package as David suggested, or dematrify() from Dave Roberts'
labdsv package, which was built specifically for this task and has simpler
syntax than melt.  The second step is to then merge your location dataframe
with the long-format occurrence data by sitenames.

Do you need coordinates for only presences, or for presences and absences?
If you need only presences, dematrify() with thresh=0.5 would automatically
drop absences, while melt() would require a second step LongOccurrences <-
LongOccurrences[Freq>0,]

So, (untested code) for dataframes named CommMatrix and SiteCoords and
sitenames as Site:
LongOccurrences <- dematrify(CommMatrix,thresh=0.5)
Presences <- merge(LongOccurrences,SiteCoords,by="Site",all.x=TRUE)

If you have more complex needs for handling community and environmental
data, you might consider the mefa package.

Tom
-------------------------------------------
Tom Philippi
Quantitative Ecologist
Inventory and Monitoring Program
National Park Service
c/o Cabrillo National Monument
1800 Cabrillo Memorial Dr
San Diego, CA 92106
(619) 523-4576
Tom_philippi at NPS.gov
http://science.nature.nps.gov/im/monitor
-------------------------------------------



                                                                           
             David Valentim                                                
             Dias                                                          
             <dvdscripter at gmai                                          To 
             l.com>                    "r-sig-ecology at r-project.org"       
             Sent by:                  <r-sig-ecology at r-project.org>       
             r-sig-ecology-bou                                          cc 
             nces at r-project.or                                             
             g                                                     Subject 
                                       Re: [R-sig-eco] Presence-absence to 
                                       Occurrence Dataset?                 
             04/20/2012 01:32                                              
             PM AST                                                        
                                                                           
                                                                           
                                                                           
                                                                           




You can check melt() (from reshape2) and reshape() functions.


2012/4/20 Coffey, Elyse D. (UMSL-Student) <edc6cb at mail.umsl.edu>
species
species)
coordinates
manipulate
--
Curr?culo: http://lattes.cnpq.br/7541377569511492


_______________________________________________
R-sig-ecology mailing list
R-sig-ecology at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
#
Hi Elyse,

Tom referred to the mefa package, I'd like to draw the attention to
the mefa4 package which is more efficient and can handle large data
since it uses sparse matrices through the Matrix package. The Melt()
function is the inverse operation to xtabs() or its modified version
Xtabs() in mefa4. It can take a matrix, sparse matrix, S3 mefa or S4
Mefa object as its argument:

library(mefa4)

y <- matrix(sample(0:4, 12, replace=TRUE, prob=c(0.5, rep(0.5/4, 4))), 4, 3)
x <- data.frame(x=runif(4), y=runif(4))
colnames(y) <- LETTERS[1:3]
rownames(y) <- rownames(x) <- paste("row", 1:4, sep="_")

z <- Melt(y)
data.frame(z, x[z$rows,])

There is also the (relatively) new multitable package by Steve Walker
with similar functionality. Lots of ways to do it -- the problem must
bother many of us :)

Cheers,

Peter

P?ter S?lymos
Alberta Biodiversity Monitoring Institute
and Boreal Avian Modelling project
Department of Biological Sciences
CW 405, Biological Sciences Bldg
University of Alberta
Edmonton, Alberta, T6G 2E9, Canada
Phone: 780.492.8534
Fax: 780.492.7635
email <- paste("solymos", "ualberta.ca", sep = "@")
http://www.abmi.ca
http://www.borealbirds.ca
http://sites.google.com/site/psolymos
On Fri, Apr 20, 2012 at 1:06 PM, <Tom_Philippi at nps.gov> wrote: