Calculate the instantaneous rate of green-up.

calc_irg(DT, id = "id", year = "yr", scaled = TRUE)

Arguments

DT

data.table of model parameters (output from model_params).

id

id column. default is 'id'. See details.

year

year column name. default is 'yr'.

scaled

boolean indicating if irg should be rescaled between 0-1 within id and year. If TRUE, provide id and year. Default is TRUE.

Value

Extended data.table 'irg' column of instantaneous rate of green-up calculated for each day of the year, for each individual and year.

Details

The DT argument expects a data.table of model estimated parameters for double logistic function of NDVI for each year and individual. Since it is the rate of green-up, model parameters required are only xmidS and scalS.

The scaled argument is used to optionally rescale the IRG result to 0-1, for each year and individual.

The id argument is used to split between sampling units. This may be a point id, polygon id, pixel id, etc. depending on your analysis. This should match the id provided to filtering functions. The formula used is described in Bischoff et al. (2012):

$$IRG = (exp((t + xmidS) / scalS)) / (2 * scalS * (exp(1) ^ ((t + xmidS) / scalS)) + (scalS * (exp(1) ^ ((2 * t) / scalS))) + (scalS * exp(1) ^ ((2 * xmidS) / scalS)))$$

(See the "Getting started with irg vignette" for a better formatted formula.)

See also

Other irg: irg()

Examples

# Load data.table
library(data.table)

# Read in example data
ndvi <- fread(system.file("extdata", "sampled-ndvi-MODIS-MOD13Q1.csv", package = "irg"))

# Filter and scale NDVI time series
filter_ndvi(ndvi)
#>         id   NDVI SummaryQA DayOfYear    yr  filtered    winter    rolled
#>      <int>  <num>     <num>     <int> <num>     <num>     <num>     <num>
#>   1:     0 0.1864         3        11  2015 0.3076500 0.3076500 0.3076500
#>   2:     1 0.0541         2         3  2015 0.3163400 0.3163400 0.3163400
#>   3:     2 0.1781         3        11  2015 0.2649875 0.2649875 0.2649875
#>   4:     3 0.1024         2         5  2015 0.2301750 0.2301750 0.2301750
#>   5:     4 0.0898         2         3  2015 0.2177150 0.2177150 0.2177150
#>  ---                                                                     
#> 801:     2 0.1179         2       364  2019 0.2649875 0.2649875 0.2649875
#> 802:     3 0.0789         2       364  2019 0.2301750 0.2301750 0.2301750
#> 803:     4 0.1572         2       364  2019 0.2177150 0.2177150 0.2177150
#> 804:     5 0.0763         2       364  2019 0.3163400 0.3163400 0.3163400
#> 805:     6 0.1197         2       362  2019 0.3149325 0.3149325 0.3149325
#>            top
#>          <num>
#>   1: 0.8735000
#>   2: 0.8632175
#>   3: 0.8707500
#>   4: 0.8635525
#>   5: 0.8476000
#>  ---          
#> 801: 0.8707500
#> 802: 0.8635525
#> 803: 0.8476000
#> 804: 0.8632175
#> 805: 0.8632000
scale_doy(ndvi)
#>         id   NDVI SummaryQA DayOfYear    yr  filtered    winter    rolled
#>      <int>  <num>     <num>     <int> <num>     <num>     <num>     <num>
#>   1:     0 0.1864         3        11  2015 0.3076500 0.3076500 0.3076500
#>   2:     1 0.0541         2         3  2015 0.3163400 0.3163400 0.3163400
#>   3:     2 0.1781         3        11  2015 0.2649875 0.2649875 0.2649875
#>   4:     3 0.1024         2         5  2015 0.2301750 0.2301750 0.2301750
#>   5:     4 0.0898         2         3  2015 0.2177150 0.2177150 0.2177150
#>  ---                                                                     
#> 801:     2 0.1179         2       364  2019 0.2649875 0.2649875 0.2649875
#> 802:     3 0.0789         2       364  2019 0.2301750 0.2301750 0.2301750
#> 803:     4 0.1572         2       364  2019 0.2177150 0.2177150 0.2177150
#> 804:     5 0.0763         2       364  2019 0.3163400 0.3163400 0.3163400
#> 805:     6 0.1197         2       362  2019 0.3149325 0.3149325 0.3149325
#>            top           t
#>          <num>       <num>
#>   1: 0.8735000 0.027397260
#>   2: 0.8632175 0.005479452
#>   3: 0.8707500 0.027397260
#>   4: 0.8635525 0.010958904
#>   5: 0.8476000 0.005479452
#>  ---                      
#> 801: 0.8707500 0.994520548
#> 802: 0.8635525 0.994520548
#> 803: 0.8476000 0.994520548
#> 804: 0.8632175 0.994520548
#> 805: 0.8632000 0.989041096
scale_ndvi(ndvi)
#>         id   NDVI SummaryQA DayOfYear    yr  filtered    winter    rolled
#>      <int>  <num>     <num>     <int> <num>     <num>     <num>     <num>
#>   1:     0 0.1864         3        11  2015 0.3076500 0.3076500 0.3076500
#>   2:     1 0.0541         2         3  2015 0.3163400 0.3163400 0.3163400
#>   3:     2 0.1781         3        11  2015 0.2649875 0.2649875 0.2649875
#>   4:     3 0.1024         2         5  2015 0.2301750 0.2301750 0.2301750
#>   5:     4 0.0898         2         3  2015 0.2177150 0.2177150 0.2177150
#>  ---                                                                     
#> 801:     2 0.1179         2       364  2019 0.2649875 0.2649875 0.2649875
#> 802:     3 0.0789         2       364  2019 0.2301750 0.2301750 0.2301750
#> 803:     4 0.1572         2       364  2019 0.2177150 0.2177150 0.2177150
#> 804:     5 0.0763         2       364  2019 0.3163400 0.3163400 0.3163400
#> 805:     6 0.1197         2       362  2019 0.3149325 0.3149325 0.3149325
#>            top           t scaled
#>          <num>       <num>  <num>
#>   1: 0.8735000 0.027397260      0
#>   2: 0.8632175 0.005479452      0
#>   3: 0.8707500 0.027397260      0
#>   4: 0.8635525 0.010958904      0
#>   5: 0.8476000 0.005479452      0
#>  ---                             
#> 801: 0.8707500 0.994520548      0
#> 802: 0.8635525 0.994520548      0
#> 803: 0.8476000 0.994520548      0
#> 804: 0.8632175 0.994520548      0
#> 805: 0.8632000 0.989041096      0

# Guess starting parameters
model_start(ndvi)
#> Key: <scaled>
#>         id   NDVI SummaryQA DayOfYear    yr filtered    winter rolled       top
#>      <int>  <num>     <num>     <int> <num>    <num>     <num>  <num>     <num>
#>   1:     4 0.1262         3        38  2015 0.217715 0.2177150     NA 0.8476000
#>   2:     1 0.0599         2        38  2016 0.316340 0.3163400     NA 0.8632175
#>   3:     3 0.0714         2        38  2016 0.230175 0.2301750     NA 0.8635525
#>   4:     4 0.0433         2        38  2016 0.217715 0.2177150     NA 0.8476000
#>   5:     5 0.0599         2        38  2016 0.316340 0.3163400     NA 0.8632175
#>  ---                                                                           
#> 801:     1 0.8755         1       225  2015 0.875500 0.3163400 0.8671 0.8632175
#> 802:     2 0.8740         1       225  2015 0.874000 0.2649875 0.8732 0.8707500
#> 803:     3 0.8643         1       225  2015 0.864300 0.2301750 0.8643 0.8635525
#> 804:     5 0.8755         1       225  2015 0.875500 0.3163400 0.8671 0.8632175
#> 805:     6 0.8729         1       225  2015 0.872900 0.3149325 0.8688 0.8632000
#>              t scaled xmidS_start xmidA_start
#>          <num>  <num>       <num>       <num>
#>   1: 0.1013699     NA   0.3808219   0.7808219
#>   2: 0.1013699     NA   0.3643836   0.7095890
#>   3: 0.1013699     NA   0.3643836   0.7095890
#>   4: 0.1013699     NA   0.3643836   0.7095890
#>   5: 0.1013699     NA   0.3643836   0.7095890
#>  ---                                         
#> 801: 0.6136986      1   0.4000000   0.7123288
#> 802: 0.6136986      1   0.3808219   0.7123288
#> 803: 0.6136986      1   0.3808219   0.7808219
#> 804: 0.6136986      1   0.4000000   0.7123288
#> 805: 0.6136986      1   0.3808219   0.7808219

# Double logistic model parameters given starting parameters for nls
mods <- model_params(
  ndvi,
  return = 'models',
  xmidS = 'xmidS_start',
  xmidA = 'xmidA_start',
  scalS = 0.05,
  scalA = 0.01
)

# Fit double logistic curve to NDVI time series
fit <- model_ndvi(mods, observed = FALSE)

# Calculate IRG for each day of the year
calc_irg(fit)
#>           id    yr     xmidS     xmidA      scalS      scalA           t
#>        <int> <num>     <num>     <num>      <num>      <num>       <num>
#>     1:     4  2015 0.3731891 0.7588353 0.02480959 0.03984095 0.000000000
#>     2:     4  2015 0.3731891 0.7588353 0.02480959 0.03984095 0.002739726
#>     3:     4  2015 0.3731891 0.7588353 0.02480959 0.03984095 0.005479452
#>     4:     4  2015 0.3731891 0.7588353 0.02480959 0.03984095 0.008219178
#>     5:     4  2015 0.3731891 0.7588353 0.02480959 0.03984095 0.010958904
#>    ---                                                                  
#> 12806:     4  2019 0.3820566 0.7359233 0.02430961 0.05110263 0.989041096
#> 12807:     4  2019 0.3820566 0.7359233 0.02430961 0.05110263 0.991780822
#> 12808:     4  2019 0.3820566 0.7359233 0.02430961 0.05110263 0.994520548
#> 12809:     4  2019 0.3820566 0.7359233 0.02430961 0.05110263 0.997260274
#> 12810:     4  2019 0.3820566 0.7359233 0.02430961 0.05110263 1.000000000
#>              fitted          irg
#>               <num>        <num>
#>     1: 2.879348e-07 1.173251e-06
#>     2: 3.217973e-07 1.310242e-06
#>     3: 3.596309e-07 1.463229e-06
#>     4: 4.019004e-07 1.634078e-06
#>     5: 4.491251e-07 1.824875e-06
#>    ---                          
#> 12806: 7.011788e-03 2.080883e-11
#> 12807: 6.648203e-03 1.469710e-11
#> 12808: 6.303351e-03 9.236763e-12
#> 12809: 5.976280e-03 4.358408e-12
#> 12810: 5.666083e-03 0.000000e+00