Giter Site home page Giter Site logo

gesaroemer / rcompadre Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jonesor/rcompadre

0.0 0.0 0.0 2.72 MB

R tools for obtaining and manupulating data from the COMPADRE and COMADRE Plant and Animal Matrix Databases

Home Page: https://jonesor.github.io/Rcompadre/

License: GNU General Public License v2.0

R 100.00%

rcompadre's Introduction

Rcompadre

Build Status AppVeyor Build Status Coverage status

An R package to work with the COM(P)ADRE Plant and Animal Matrix Population Databases. Note this package is at an early stage of development, and may contain bugs.

Installation

Install from GitHub with:

# install package 'remotes' if necessary
# will already be installed if 'devtools' is installed
install.packages("remotes") 

# argument 'build_opts = NULL' only needed if you want to build vignettes
remotes::install_github("jonesor/Rcompadre", build_opts = NULL)

Usage

library(Rcompadre)

Fetching a database

Fetch the most recent database version from compadre-db.org with

compadre <- cdb_fetch("compadre") # or use 'comadre' for the animal database

or load from a local .RData file with

compadre <- cdb_fetch("path/to/file/COMPADRE_v.4.0.1.RData")

If you prefer using load() to load your local copy of a legacy database, use as_cdb() to convert it to the 'CompadreDB' class

load("COMPADRE_v.4.0.1.RData") # loads object 'compadre'
compadre <- as_cdb(compadre)

Subsetting

For the most part CompadreDB objects work like a data frame. They can be subset using [ or subset()

# subset to the first 10 rows
compadre[1:10,]

# subset to the species 'Echinacea angustifolia'
subset(compadre, SpeciesAccepted == "Echinacea angustifolia")

Example analysis: calculating population growth rates

First we'll use the function cdb_flag to add columns to the database flagging potential issues with the projection matrices, such as missing values, or matrices that don't meet assumptions like ergodicity, irreducibility, or primitivity.

compadre_flags <- cdb_flag(compadre)

We'll only be able to calculate population growth rates from matrices that don't contain missing values, and we only want to use matrices that meet the assumption of ergodicity, so we'll subset the database accordingly.

compadre_sub <- subset(compadre_flags,
                       check_NA_A == FALSE & check_ergodic == TRUE)

Finally, we'll use the lambda function from the library popbio to calculate the population growth rate for every matrix in compadre_sub.

library(popbio)
compadre_sub$lambda <- sapply(matA(compadre_sub), lambda)

In the code above, the accessor function matA() is used to extract a list of projection matrices (the full matrix, "matA") from every row of compadre_sub. There are also accessor functions for the matrix subcomponents (matU(), matF(), matC()), and for many other parts of the database too.

Previous releases

Specific earlier releases of this package can be installed using the appropriate @ tag.

To install version 0.1.0, our (thus far) only release:

devtools::install_github("jonesor/[email protected]")

Contributions

All contributions are welcome. Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

rcompadre's People

Contributors

patrickbarks avatar jonesor avatar levisc8 avatar iainmstott avatar tdjames1 avatar bartholdja avatar wpetry avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.