La continuité du service gitlab.irstea.fr sera assurée en 2020. Nous envisageons ensuite une évolution vers une forge nationale INRAE encore à construire. Nous vous tiendrons au courant des évolutions futures.

Commit bf8dcb6e authored by Monnet Jean-Matthieu's avatar Monnet Jean-Matthieu

Corrected bug in ABApredict in the case of log transform. Modified extraction of variable names

parent 2ae38ca6
......@@ -396,18 +396,26 @@ ABApredict <- function(modell, map.metrics, strata=NULL)
if (modell$stats[stratum,"transform"] == "boxcox") # case of Box-Cox transform
{
# apply linear model
dummy[[stratum]] <- raster::predict(map.metrics[[names(modell$model[[stratum]]$coefficients)[-1]]], modell$model[[stratum]])
variables <- names(modell$model[[stratum]]$coefficients)
variables <- variables[variables !="(Intercept)"]
dummy[[stratum]] <- raster::predict(map.metrics[[variables]], modell$model[[stratum]])
# back-transform
dummy[[stratum]] <- lidaRtRee::iBoxcoxTrBiasCor(dummy[[stratum]], modell$stats[stratum,"lambda"], modell$stats[stratum,"var.res"])
}
if (modell$stats[stratum,"transform"] == "log") # case of case of log-log transform
{
dummy[[stratum]] <- raster::predict(log(map.metrics[[names(modell$model[[stratum]]$coefficients)[-1]]]), modell$model[[stratum]])
variables <- names(modell$model[[stratum]]$coefficients)
variables <- variables[variables !="(Intercept)"]
newdata <- log(map.metrics[[variables]])
names(newdata) <- variables
dummy[[stratum]] <- raster::predict(newdata, modell$model[[stratum]])
dummy[[stratum]]<- exp(dummy[[stratum]]) * exp(modell$stats[stratum,"var.res"]/2)
}
if (modell$stats[stratum,"transform"] == "none") # case of case of no transform
{
dummy[[stratum]] <- raster::predict(map.metrics[[names(modell$model[[stratum]]$coefficients)[-1]]], modell$model[[stratum]])
variables <- names(modell$model[[stratum]]$coefficients)
variables <- variables[variables !="(Intercept)"]
dummy[[stratum]] <- raster::predict(map.metrics[[variables]], modell$model[[stratum]])
}
# set prediction outside of strata to NA
dummy[[stratum]][map.metrics$strata != stratum.ID] <- NA
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment