Fit double logistic model to NDVI time series given parameters estimated with model_params.

model_ndvi(DT, observed = TRUE)

Arguments

DT

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

observed

boolean indicating if a full year of fitted values should be returned (observed = FALSE) or if only observed values will be fit (observed = TRUE)

Value

Model parameter data.table appended with 'fitted' column of double logistic model of NDVI for a full year. Calculated at the daily scale with the following formula from Bischoff et al. (2012). $$fitted = \frac{1}{1 + \exp{\frac{xmidS - t}{scalS}}} - \frac{1}{1 + \exp{\frac{xmidA - t}{scalA}}}$$(See the "Getting started with irg vignette" for a better formatted formula.)

See also

Other model: model_params(), model_start()

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 for xmidS and xmidA
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

## Two options: fit to full year or observed data
# Option 1 - returns = 'models'

# Double logistic model parameters
#   given global starting parameters for scalS, scalA
#   and output of model_start for xmidS, xmidA
mods <- model_params(
  ndvi,
  returns = 'models',
  xmidS = 'xmidS_start',
  xmidA = 'xmidA_start',
  scalS = 0.05,
  scalA = 0.01
)

# Fit to the whole year (requires assignment)
fit <- model_ndvi(mods, observed = FALSE)

# Option 2 - returns = 'columns'
model_params(
  ndvi,
  returns = 'columns',
  xmidS = 'xmidS_start',
  xmidA = 'xmidA_start',
  scalS = 0.05,
  scalA = 0.01
)
#>      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     xmidS     xmidA       scalS
#>   1: 0.1643836     NA   0.3452055   0.7095890 0.3373884 0.7165697 0.022648297
#>   2: 0.1643836     NA   0.3452055   0.7095890 0.3561967 0.7285859 0.031276884
#>   3: 0.1643836     NA   0.3452055   0.7095890 0.3411214 0.7208200 0.034678822
#>   4: 0.1643836     NA   0.3452055   0.7095890 0.3456795 0.7250997 0.033220445
#>   5: 0.1643836     NA   0.3452055   0.7095890 0.3561967 0.7285859 0.031276884
#>  ---                                                                         
#> 801: 0.6136986      1   0.4000000   0.7123288 0.3904855 0.7400015 0.009961818
#> 802: 0.6136986      1   0.3808219   0.7123288 0.3823661 0.7475907 0.009083805
#> 803: 0.6136986      1   0.3808219   0.7808219 0.3787929 0.7611913 0.025539395
#> 804: 0.6136986      1   0.4000000   0.7123288 0.3904855 0.7400015 0.009961818
#> 805: 0.6136986      1   0.3808219   0.7808219 0.3859433 0.7492424 0.013003034
#>           scalA
#>   1: 0.03686743
#>   2: 0.04512882
#>   3: 0.03669032
#>   4: 0.04583330
#>   5: 0.04512882
#>  ---           
#> 801: 0.03408254
#> 802: 0.03335550
#> 803: 0.03799136
#> 804: 0.03408254
#> 805: 0.03646694

# Fit double logistic curve to NDVI time series for the observed days
model_ndvi(ndvi, observed = TRUE)
#>      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     xmidS     xmidA       scalS
#>   1: 0.1643836     NA   0.3452055   0.7095890 0.3373884 0.7165697 0.022648297
#>   2: 0.1643836     NA   0.3452055   0.7095890 0.3561967 0.7285859 0.031276884
#>   3: 0.1643836     NA   0.3452055   0.7095890 0.3411214 0.7208200 0.034678822
#>   4: 0.1643836     NA   0.3452055   0.7095890 0.3456795 0.7250997 0.033220445
#>   5: 0.1643836     NA   0.3452055   0.7095890 0.3561967 0.7285859 0.031276884
#>  ---                                                                         
#> 801: 0.6136986      1   0.4000000   0.7123288 0.3904855 0.7400015 0.009961818
#> 802: 0.6136986      1   0.3808219   0.7123288 0.3823661 0.7475907 0.009083805
#> 803: 0.6136986      1   0.3808219   0.7808219 0.3787929 0.7611913 0.025539395
#> 804: 0.6136986      1   0.4000000   0.7123288 0.3904855 0.7400015 0.009961818
#> 805: 0.6136986      1   0.3808219   0.7808219 0.3859433 0.7492424 0.013003034
#>           scalA       fitted
#>   1: 0.03686743 0.0004808814
#>   2: 0.04512882 0.0021621933
#>   3: 0.03669032 0.0060811435
#>   4: 0.04583330 0.0042418180
#>   5: 0.04512882 0.0021621933
#>  ---                        
#> 801: 0.03408254 0.9760090507
#> 802: 0.03335550 0.9822610413
#> 803: 0.03799136 0.9797106603
#> 804: 0.03408254 0.9760090507
#> 805: 0.03646694 0.9762675518