| mastClimate {mastif} | R Documentation |
Covariates for mast data
Description
Annotates treeData for mastif to include covariates.
Usage
mastClimate( file, plots, years, months = 1:12, FUN = 'mean',
vname = '', normYr = c( 1990:2020 ), lastYear = 2021 )
Arguments
file |
|
plots |
|
years |
|
months |
|
FUN |
|
vname |
name to use for a variable in the model that comes from |
normYr |
years for climate norm for calculating anomalies. |
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
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 )
inputs$yearEffect <- list(groups ='species', p = 3) # AR(3) model, species are lag groups
output <- mastif(inputs = inputs, formulaFec, formulaRep, ng = 1000, burnin = 400)