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

## 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
)
#> 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     xmidS     xmidA       scalS
#>          <num>  <num>       <num>       <num>     <num>     <num>       <num>
#>   1: 0.1013699     NA   0.3808219   0.7808219 0.3731891 0.7588353 0.024809594
#>   2: 0.1013699     NA   0.3643836   0.7095890 0.3502720 0.7143040 0.045162901
#>   3: 0.1013699     NA   0.3643836   0.7095890 0.3449777 0.7123648 0.034784190
#>   4: 0.1013699     NA   0.3643836   0.7095890 0.3469861 0.7098906 0.038502148
#>   5: 0.1013699     NA   0.3643836   0.7095890 0.3502720 0.7143040 0.045162901
#>  ---                                                                         
#> 801: 0.6136986      1   0.4000000   0.7123288 0.3904855 0.7400015 0.009961817
#> 802: 0.6136986      1   0.3808219   0.7123288 0.3823665 0.7475907 0.009082290
#> 803: 0.6136986      1   0.3808219   0.7808219 0.3787929 0.7611913 0.025539421
#> 804: 0.6136986      1   0.4000000   0.7123288 0.3904855 0.7400015 0.009961817
#> 805: 0.6136986      1   0.3808219   0.7808219 0.3859633 0.7492422 0.012924676
#>           scalA
#>           <num>
#>   1: 0.03984095
#>   2: 0.03120381
#>   3: 0.03371281
#>   4: 0.01970562
#>   5: 0.03120381
#>  ---           
#> 801: 0.03408254
#> 802: 0.03335559
#> 803: 0.03799136
#> 804: 0.03408254
#> 805: 0.03646754

# Fit double logistic curve to NDVI time series for the observed days
model_ndvi(ndvi, observed = TRUE)
#> 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     xmidS     xmidA       scalS
#>          <num>  <num>       <num>       <num>     <num>     <num>       <num>
#>   1: 0.1013699     NA   0.3808219   0.7808219 0.3731891 0.7588353 0.024809594
#>   2: 0.1013699     NA   0.3643836   0.7095890 0.3502720 0.7143040 0.045162901
#>   3: 0.1013699     NA   0.3643836   0.7095890 0.3449777 0.7123648 0.034784190
#>   4: 0.1013699     NA   0.3643836   0.7095890 0.3469861 0.7098906 0.038502148
#>   5: 0.1013699     NA   0.3643836   0.7095890 0.3502720 0.7143040 0.045162901
#>  ---                                                                         
#> 801: 0.6136986      1   0.4000000   0.7123288 0.3904855 0.7400015 0.009961817
#> 802: 0.6136986      1   0.3808219   0.7123288 0.3823665 0.7475907 0.009082290
#> 803: 0.6136986      1   0.3808219   0.7808219 0.3787929 0.7611913 0.025539421
#> 804: 0.6136986      1   0.4000000   0.7123288 0.3904855 0.7400015 0.009961817
#> 805: 0.6136986      1   0.3808219   0.7808219 0.3859633 0.7492422 0.012924676
#>           scalA       fitted
#>           <num>        <num>
#>   1: 0.03984095 1.738081e-05
#>   2: 0.03120381 4.024955e-03
#>   3: 0.03371281 9.079418e-04
#>   4: 0.01970562 1.693462e-03
#>   5: 0.03120381 4.024955e-03
#>  ---                        
#> 801: 0.03408254 9.760091e-01
#> 802: 0.03335559 9.822608e-01
#> 803: 0.03799136 9.797107e-01
#> 804: 0.03408254 9.760091e-01
#> 805: 0.03646754 9.762660e-01