fitscales: Fit regression models through spatial scales

View source: R/fitscales.R

fitscalesR Documentation

Fit regression models through spatial scales

Description

This function is an alternative to multifit with the advantage of not being restricted to one response variable per time. The function manage the aplication of regression models (model) with different formulas (formula) using both landscape metrics (lsm) and biological variables (bio) in interchangeable roles as predictor and response variables. The function will return a tibble with response and predictor pair applyed to n scales (layer) in many levels, class and id as returned in the lsm object calculated with calc_lsm().

Usage

fitscales(lsm=NULL,bio=NULL,model=NULL, formula="responses ~ predictors",
 responses=NULL, model.arg=NULL, quiet=FALSE)

Arguments

lsm

an output of the calc_lsm or extract_metrics functions. Default is NULL

bio

a table with other information to be used in the models. See the 'euglossini' data, accessible through typing euglossini in the console, for more details. Default is NULL.

model

an valid model name function, as lm or glm, to be called and calcula the model objects. Default is NULL

formula

any valid formula to be used in the models. Default is "responses ~ predictors" which returns pairwise combinations of predictors as lsm metrics and bio vars as responses. Users can take advantage of the wildcards "responses" and "predictors". See details for more information.

responses

a vector specifying which responses variables must be considered while building models. If null, all response variables are returned. Default is null.

model.arg

a vector or a list with any other arguments required for the models functins. It's often used to inform the family of regression, e.g. c(family="poisson") or list(family="poisson", "model" = FALSE, ...)

quiet

a logical to inform whether or not return low concerning warnings. Critical warnings are always returned.

Details

This functions was designed to work with any model package and object supported by the broom framework, which is used to manage the output. Therefore, users must be sure to load the model's package before to run the analysis, as well as that the formula is suitable for the dataset, and that the broom family (broom, broommixed, and broomExtra) can handle the model output.

Fomula wildcards: To make the process more smooth, we implemented two wildcards: "responses" and "predictors". By combining these wildcards users might have some facilities as: "responses ~ predictors" : will return all pairwise combinations of the lsm metrics as predictors and 'bio table' as responses for a given model and formula; "predictors": by using predictors as the seccond term of the function, e.g. "A ~ predictors", users will have models for each predictor over the response variable "A". "responses": using responses as the first term of the function (e.g "responses ~ a+b") will return models for all numeric responses variables in the "bio table". Users can have models for specific sets of response variables by specifying the parameter response of the function, which will not requires variables to be numeric.

The output tibble will present several columns but a single line for each calculated model. For each single model, the output will always have the following columns: response: the response variable used to that model calculation predictor: same as response, but for predictors variable used layer: the scale for which the model was calculated class: same as layer when the metrics considering classes id: same as layer and classes when both are required by the metric calculation data: the data passed to the model calculation models: the model object itselves. tidy: the summary of the model estimation glance: the adjusment estimatiors for each model, as AIC, BIC, r_squared... augment: the model residuals and other information for each record on data

For other information about tidy, glance and augment, users may look at the broom package family.

Author(s)

Wilson Frantine-Silva

See Also

modelplot(), calc_lsm(), extract_metrics(), multifit()

Examples

## Not run: 
ls  <- decouple(r,p,b=c(1000,2000,3000))
lsm <- calc_lsm(ls, c("pland","shdi"))
bio <- euglossini ##see documentantion for details
models <- fitscales(lsm, bio, "glm", "responses ~ predictors",
responses=c("Abundance", "Richness"), model.arg=c(family="gaussian"), quiet=F)
head(models)

## Other usages:
mods.all.pairs            <- fitscales(lsm,bio,"lm","responses ~ predictors")
mods.some.resp.all.pred   <- fitscales(lsm,bio,"lm","responses ~ predictors",
 responses = c("Abundance","Richness"))
mods.all.resp.one.pred    <- fitscales(lsm,bio,"lm","responses ~ shdi+pland_3")
mods.one.resp.all.pred    <- fitscales(lsm,bio,"lm","Abundance ~ predictors")
mods.one.formule.for.all  <- fitscales(lsm,bio,"lm","Abundance ~ shdi+pland_3")
mods.resp.operations      <- fitscales(lsm,bio,"lm","log(Abundance)+Richness ~ shdi+pland_3")


## End(Not run)

wilsonfrantine/landscapeDecoupler documentation built on Oct. 31, 2024, 3:45 a.m.