Apply stored z-standardization to environmental predictors
Source:R/Processes_utils.R
apply_env_scaling.RdRe-applies the constants learned by compute_env_scaling() to env.
The transformation uses the stored mean/sd only and never recomputes them
from env, so calibration and prediction use an identical transformation
(the usual pitfall of scale() inside a model formula is avoided).
Arguments
- env
A
data.frame/data.tableof raw environmental data.- scaling
The
data.framereturned bycompute_env_scaling(), orNULL(in which caseenvis returned unchanged). For a model fit withenv_autoscale = TRUEthis ismodel$env_scaling.
Examples
# reproduce the standardization a model fit with env_autoscale = TRUE used:
env <- data.frame(siteID = 1:3, year = 1L, temp = c(4, 6, 8), prec = c(700, 850, 1000))
scaling <- compute_env_scaling(env)
apply_env_scaling(env, scaling)
#> siteID year temp prec
#> <int> <int> <num> <num>
#> 1: 1 1 -1 -1
#> 2: 2 1 0 0
#> 3: 3 1 1 1