mastClimate: Covariates for mast data

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/mastifFunctions.R

Description

Annotates treeData for mastif to include covariates.

Usage

1
2
  mastClimate(file, plots, years, months, FUN = 'mean', 
              vname = '', lastYear = 2021)

Arguments

file

character giving the path and file name where covariate is stored in mastif covariate format (see Details).

plots

character vector from treeData$plot.

years

numeric vector from treeData$year.

months

numeric vector of months to include in annual values.

FUN

character specifies how monthly covariate values are combined into annual values.

vname

name to use for a variable in the model that comes from file.

lastYear

last data year to include.

Details

The version of treeData used in mastif can have additional tree years included when there are seed trap years that were not censused or when AR(p) effects extend observations to impute the p years before and after a tree was observed. The function mastFillCensus makes this version of treeData available to the user. The function mastClimate provides a quick way to add plot-year covariates to treeData.

A covariate like minimum monthly temperature is stored in a plot by year_month format, where rownames of file are plot names matching treeData$plot, and colnames of file could be 2012_1, 2012_2, ... for the 12 months in the year. The numeric vector months holds the months to be included in the annual values, e.g., c(3, 4) for minimum winter temperatures during the period from March through April. To find the minimum for this period, set FUN to 'min'.

More detailed vignettes can be obtained with: browseVignettes('mastif')

Value

A numeric vector equal in length to the number of rows in treeData that can be added as a column and included in formulaFec.

Author(s)

James S Clark, jimclark@duke.edu

References

Clark, J.S., C. Nunes, and B. Tomasek. 2019. Foodwebs based on unreliable foundations: spatio-temporal masting merged with consumer movement, storage, and diet. Ecological Monographs, e01381.

See Also

mastFillCensus to fill tree census

mastif for analysis

A more detailed vignette is can be obtained with:

browseVignettes('mastif')

website 'http://sites.nicholas.duke.edu/clarklab/code/'.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
d <- "https://github.com/jimclarkatduke/mast/blob/master/liriodendronExample.rData?raw=True"
repmis::source_data(d)

inputs   <- list( specNames = specNames, seedNames = seedNames, 
                  treeData = treeData, seedData = seedData, 
                  xytree = xytree, xytrap = xytrap)
                  
# interpolate census, add years for AR(p) model
inputs   <- mastFillCensus(inputs, p = 3)
treeData <- inputs$treeData               #now includes additional years

# include minimum spring temperature of previous year
cfile <- tempfile(fileext = '.csv')
d <- "https://github.com/jimclarkatduke/mast/blob/master/tmin.csv?raw=True"
download.file(d, destfile=cfile)

tyears <- treeData$year - 1
tplots <- treeData$plot
  
tmp <- mastClimate( file = cfile, plots = tplots, 
                    years = tyears, months = 1:4, FUN = 'min')
treeData$tminSprAnomaly <- tmp$x[,3]                             
inputs$treeData <- treeData
  
formulaRep <- as.formula( ~ diam )
formulaFec <- as.formula( ~ diam + tminSprAnomaly )        
  
yearEffect <- list(groups ='species', p = 3)  # AR(3) model, species are lag groups
  
output <- mastif(inputs = inputs, formulaFec, formulaRep, 
                 yearEffect = yearEffect, ng = 2000, burnin = 1000)

mastif documentation built on Oct. 25, 2020, 5:07 p.m.