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

# Guess starting parameters
model_start(ndvi)
#>      id   NDVI SummaryQA DayOfYear   yr filtered    winter rolled       top
#>   1:  0 0.0791         2        61 2016       NA 0.3076500     NA 0.8735000
#>   2:  1 0.0526         2        61 2016       NA 0.3163400     NA 0.8632175
#>   3:  2 0.0707         2        61 2016       NA 0.2649875     NA 0.8707500
#>   4:  3 0.0456         2        61 2016       NA 0.2301750     NA 0.8635525
#>   5:  5 0.0526         2        61 2016       NA 0.3163400     NA 0.8632175
#>  ---                                                                       
#> 801:  1 0.8755         1       225 2015   0.8755 0.3163400 0.8671 0.8632175
#> 802:  2 0.8740         1       225 2015   0.8740 0.2649875 0.8732 0.8707500
#> 803:  3 0.8643         1       225 2015   0.8643 0.2301750 0.8643 0.8635525
#> 804:  5 0.8755         1       225 2015   0.8755 0.3163400 0.8671 0.8632175
#> 805:  6 0.8729         1       225 2015   0.8729 0.3149325 0.8688 0.8632000
#>              t scaled xmidS_start xmidA_start
#>   1: 0.1643836     NA   0.3452055   0.7095890
#>   2: 0.1643836     NA   0.3452055   0.7095890
#>   3: 0.1643836     NA   0.3452055   0.7095890
#>   4: 0.1643836     NA   0.3452055   0.7095890
#>   5: 0.1643836     NA   0.3452055   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
#>     1:  0 2016 0.3373884 0.7165697 0.02264830 0.03686743 0.000000000
#>     2:  0 2016 0.3373884 0.7165697 0.02264830 0.03686743 0.002739726
#>     3:  0 2016 0.3373884 0.7165697 0.02264830 0.03686743 0.005479452
#>     4:  0 2016 0.3373884 0.7165697 0.02264830 0.03686743 0.008219178
#>     5:  0 2016 0.3373884 0.7165697 0.02264830 0.03686743 0.010958904
#>    ---                                                              
#> 12806:  5 2019 0.3929376 0.7228242 0.01317131 0.04943371 0.989041096
#> 12807:  5 2019 0.3929376 0.7228242 0.01317131 0.04943371 0.991780822
#> 12808:  5 2019 0.3929376 0.7228242 0.01317131 0.04943371 0.994520548
#> 12809:  5 2019 0.3929376 0.7228242 0.01317131 0.04943371 0.997260274
#> 12810:  5 2019 0.3929376 0.7228242 0.01317131 0.04943371 1.000000000
#>              fitted          irg
#>     1: 3.355173e-07 1.356661e-06
#>     2: 3.788475e-07 1.531112e-06
#>     3: 4.277638e-07 1.727997e-06
#>     4: 4.829857e-07 1.950198e-06
#>     5: 5.453252e-07 2.200972e-06
#>    ---                          
#> 12806: 4.562408e-03 5.007750e-20
#> 12807: 4.317491e-03 3.342750e-20
#> 12808: 4.085667e-03 1.990435e-20
#> 12809: 3.866242e-03 8.920830e-21
#> 12810: 3.658559e-03 0.000000e+00