Description Usage Arguments Details Value Author(s) See Also Examples
Takes the oputput of prepareLaggedData
to fit the following model with Random Forest:
p_{t} = p_{t1} +...+ p_{tn} + d_{t} + d_{t1} +...+ d_{tn} + r
where:
d is a driver (several drivers can be added).
t is the time of any given value of the response p.
t1 is the lag number 1 (in time units).
p_{t1} +...+ p_{tn} represents the endogenous component of ecological memory.
d_{t1} +...+ d_{tn} represents the exogenous component of ecological memory.
d_{t} represents the concurrent effect of the driver over the response.
r represents a column of random values, used to test the significance of the variable importance scores returned by Random Forest.
1 2 3 4 5 6 7 8 9 10 11 12  computeMemory(
lagged.data = NULL,
drivers = NULL,
response = "Response",
add.random = TRUE,
random.mode = "autocorrelated",
repetitions = 10,
subset.response = "none",
min.node.size = 5,
num.trees = 2000,
mtry = 2
)

lagged.data 
a lagged dataset resulting from 
drivers 
a character string or vector of character strings with variables to be used as predictors in the model (i.e. c("Suitability", "Driver.A")). Important: 
response 
character string, name of the response variable (typically, "Response_0"). 
add.random 
if TRUE, adds a random term to the model, useful to assess the significance of the variable importance scores. 
random.mode 
either "white.noise" or "autocorrelated". See details. 
repetitions 
integer, number of random forest models to fit. 
subset.response 
character string with values "up", "down" or "none", triggers the subsetting of the input dataset. "up" only models memory on cases where the response's trend is positive, "down" selectes cases with negative trends, and "none" selects all cases. 
min.node.size 
integer, argument of the ranger function. Minimal number of samples to be allocated in a terminal node. Default is 5. 
num.trees 
integer, argument of the ranger function. Number of regression trees to be fitted (size of the forest). Default is 2000. 
mtry 
integer, argument of the ranger function. Number of variables to possibly split at in each node. Default is 2. 
This function uses the ranger package to fit Random Forest models. Please, check the help of the ranger function to better understand how Random Forest is parameterized in this library. This function fits the model explained above as many times as defined in the argument repetitions
. To test the statistical significance of the variable importance scores returned by random forest, on each repetition the model is fitted with a different r
(random) term. If random.mode
equals "autocorrelated", the random term will have a temporal autocorrelation, and if it equals "white.noise", it will be a pseudorandom sequence of numbers generated with rnorm
, with no temporal autocorrelation. The importance of the random sequence (as computed by random forest) is stored for each model run, and used as a benchmark to assess the importance of the other predictors used in the models. Importance values of other predictors that are above the median of the importance of the random term should be interpreted as nonrandom, and therefore, significant.
A list with 4 slots:
memory
dataframe with five columns:
Variable
character, names and lags of the different variables used to model ecological memory.
median
numeric, median importance across repetitions
of the given Variable
according to Random Forest.
sd
numeric, standard deviation of the importance values of the given Variable
across repetitions
.
min
and max
numeric, percentiles 0.05 and 0.95 of importance values of the given Variable
across repetitions
.
R2
vector, values of pseudo Rsquared value obtained for the Random Forest model fitted on each repetition. Pseudo Rsquared is the Pearson correlation beteween the observed and predicted data.
prediction
dataframe, with the same columns as the dataframe in the slot memory
, with the median and confidence intervals of the predictions of all random forest models fitted.
multicollinearity
multicollinearity analysis on the input data performed with vif. A vif value higher than 5 indicates that the given variable is highly correlated with other variables.
Blas M. Benito <blasbenito@gmail.com>
plotMemory
, extractMemoryFeatures
##'
Wright, M. N. & Ziegler, A. (2017). ranger: A fast implementation of random forests for high dimensional data in C++ and R. J Stat Softw 77:117. https://doi.org/10.18637/jss.v077.i01.
Breiman, L. (2001). Random forests. Mach Learn, 45:532. https://doi.org/10.1023/A:1010933404324.
Hastie, T., Tibshirani, R., Friedman, J. (2009). The Elements of Statistical Learning. Springer, New York. 2nd edition.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18  #loading data
data(palaeodataLagged)
memory.output < computeMemory(
lagged.data = palaeodataLagged,
drivers = c("climate.temperatureAverage", "climate.rainfallAverage"),
response = "Response",
add.random = TRUE,
random.mode = "autocorrelated",
repetitions = 10,
subset.response = "none"
)
str(memory.output)
str(memory.output$memory)
#plotting output
plotMemory(memory.output = memory.output)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.