Last data update: 2014.03.03

R: estimate.shiftvec
estimate.shiftvecR Documentation

estimate.shiftvec

Description

Given two data frames, one containing isotopic measurements from some predator species, and another containing isotopic measurements from a collection of prey species, return num.samples samples of discrimination factors from predators to prey.

Usage

estimate.shiftvec(predator, prey, num.samples=1000, num.preysamples=1,
  pred.distinput=FALSE, prey.distinput=TRUE)

Arguments

predator

A data frame containing the isotopic measurements (presented as raw data or mean/standard deviation) from a predator species.

prey

A data frame containing the isotopic measurements (presented as raw data or mean/standard deviation) from a prey species.

num.samples

The number of samples of discrimination factors to produce.

num.preysamples

The number of samples to draw from each prey source when performing the estimation process.

pred.distinput

TRUE if the predator measurements are in mean/standard deviation form (see build.isotopeframe).

prey.distinput

TRUE if the prey measurements are in mean/standard deviation form (see build.isotopeframe).

Value

A matrix with num.samples rows, each of which contains one estimate discrimination factor.

Author(s)

Robert Robere

See Also

build.isotopeframe

Examples

## normally input is read from a file via build.isotopeframe, but here
## we generate the input by hand
## we have three prey species: birds, mice, and bugs
## one predator species: cats
## we are measuring two isotopic values for each: %%C and %%N
## assume that all measurements are normally distributed
bird.samples <- as.data.frame(mvrnorm(n=25, mu=c(2, 2),
  Sigma=diag(c(1, 1), nrow=2)))
mice.samples <- as.data.frame(mvrnorm(n=25, mu=c(4, 4),
  Sigma=diag(c(1, 1), nrow=2)))
bugs.samples <- as.data.frame(mvrnorm(n=25, mu=c(2, 6),
  Sigma=diag(c(1, 1), nrow=2)))

## note that prey are collected into a single data frame, 
## as are the predators
## if number of samples differs from species to species,
## the data frame should be padded
## with NAs appropriately (this is done automatically when
## reading in from CSV)
pred.frame <- data.frame(cats=mvrnorm(n=20, mu=c(6, 6),
  Sigma=diag(c(1/2, 1/2), nrow=2)))
prey.frame = data.frame(bird=bird.samples, mice=mice.samples,
  bugs=bugs.samples)

## now estimate discrimination factors
## in applications, usually the prey measurements are given by mean/sd
## of corresponding gaussian, so we notify the function that we are
## actually providing samples in this example
estimate.shiftvec(pred.frame, prey.frame, num.samples=10,
  prey.distinput=FALSE) 

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(EDFIR)
Loading required package: lpSolve
Loading required package: geometry
Loading required package: magic
Loading required package: abind
Loading required package: vertexenum
Loading required package: MASS
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/EDFIR/estimate.shiftvec.Rd_%03d_medium.png", width=480, height=480)
> ### Name: estimate.shiftvec
> ### Title: estimate.shiftvec
> ### Aliases: estimate.shiftvec
> 
> ### ** Examples
> 
> ## normally input is read from a file via build.isotopeframe, but here
> ## we generate the input by hand
> ## we have three prey species: birds, mice, and bugs
> ## one predator species: cats
> ## we are measuring two isotopic values for each: %%C and %%N
> ## assume that all measurements are normally distributed
> bird.samples <- as.data.frame(mvrnorm(n=25, mu=c(2, 2),
+   Sigma=diag(c(1, 1), nrow=2)))
> mice.samples <- as.data.frame(mvrnorm(n=25, mu=c(4, 4),
+   Sigma=diag(c(1, 1), nrow=2)))
> bugs.samples <- as.data.frame(mvrnorm(n=25, mu=c(2, 6),
+   Sigma=diag(c(1, 1), nrow=2)))
> 
> ## note that prey are collected into a single data frame, 
> ## as are the predators
> ## if number of samples differs from species to species,
> ## the data frame should be padded
> ## with NAs appropriately (this is done automatically when
> ## reading in from CSV)
> pred.frame <- data.frame(cats=mvrnorm(n=20, mu=c(6, 6),
+   Sigma=diag(c(1/2, 1/2), nrow=2)))
> prey.frame = data.frame(bird=bird.samples, mice=mice.samples,
+   bugs=bugs.samples)
> 
> ## now estimate discrimination factors
> ## in applications, usually the prey measurements are given by mean/sd
> ## of corresponding gaussian, so we notify the function that we are
> ## actually providing samples in this example
> estimate.shiftvec(pred.frame, prey.frame, num.samples=10,
+   prey.distinput=FALSE) 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>