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

Usage,
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

Examples

# Load data.table
library(data.table)

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

# Filter and scale NDVI time series
filter_ndvi(ndvi)
#>       id   yr DayOfYear  NDVI SummaryQA filtered winter rolled    top
#>    1:  1 2002         3 -1367         3     4099   4099   4099 7443.4
#>    2:  2 2002        14  -304         3     5382   5382   5382 7462.9
#>    3:  3 2002         1   374         2     3702   3702   3702 6709.8
#>    4:  4 2002        15   635         3     5180   5180   5180 7288.1
#>    5:  5 2002         9   685         2     4621   4621   4621 7645.1
#>   ---                                                                
#> 1261:  1 2012       353   151         2     4099   4099   4099 7443.4
#> 1262:  2 2012       356   330         2     5382   5382   5382 7462.9
#> 1263:  3 2012       356   560         2     3702   3702   3702 6709.8
#> 1264:  4 2012       356  1720         2     5180   5180   5180 7288.1
#> 1265:  5 2012       356  2689         2     4621   4621   4621 7645.1
scale_doy(ndvi)
#>       id   yr DayOfYear  NDVI SummaryQA filtered winter rolled    top
#>    1:  1 2002         3 -1367         3     4099   4099   4099 7443.4
#>    2:  2 2002        14  -304         3     5382   5382   5382 7462.9
#>    3:  3 2002         1   374         2     3702   3702   3702 6709.8
#>    4:  4 2002        15   635         3     5180   5180   5180 7288.1
#>    5:  5 2002         9   685         2     4621   4621   4621 7645.1
#>   ---                                                                
#> 1261:  1 2012       353   151         2     4099   4099   4099 7443.4
#> 1262:  2 2012       356   330         2     5382   5382   5382 7462.9
#> 1263:  3 2012       356   560         2     3702   3702   3702 6709.8
#> 1264:  4 2012       356  1720         2     5180   5180   5180 7288.1
#> 1265:  5 2012       356  2689         2     4621   4621   4621 7645.1
#>                 t
#>    1: 0.005479452
#>    2: 0.035616438
#>    3: 0.000000000
#>    4: 0.038356164
#>    5: 0.021917808
#>   ---            
#> 1261: 0.964383562
#> 1262: 0.972602740
#> 1263: 0.972602740
#> 1264: 0.972602740
#> 1265: 0.972602740
scale_ndvi(ndvi)
#>       id   yr DayOfYear  NDVI SummaryQA filtered winter rolled    top
#>    1:  1 2002         3 -1367         3     4099   4099   4099 7443.4
#>    2:  2 2002        14  -304         3     5382   5382   5382 7462.9
#>    3:  3 2002         1   374         2     3702   3702   3702 6709.8
#>    4:  4 2002        15   635         3     5180   5180   5180 7288.1
#>    5:  5 2002         9   685         2     4621   4621   4621 7645.1
#>   ---                                                                
#> 1261:  1 2012       353   151         2     4099   4099   4099 7443.4
#> 1262:  2 2012       356   330         2     5382   5382   5382 7462.9
#> 1263:  3 2012       356   560         2     3702   3702   3702 6709.8
#> 1264:  4 2012       356  1720         2     5180   5180   5180 7288.1
#> 1265:  5 2012       356  2689         2     4621   4621   4621 7645.1
#>                 t scaled
#>    1: 0.005479452      0
#>    2: 0.035616438      0
#>    3: 0.000000000      0
#>    4: 0.038356164      0
#>    5: 0.021917808      0
#>   ---                   
#> 1261: 0.964383562      0
#> 1262: 0.972602740      0
#> 1263: 0.972602740      0
#> 1264: 0.972602740      0
#> 1265: 0.972602740      0

# Guess starting parameters for xmidS and xmidA
model_start(ndvi)
#>       id   yr DayOfYear NDVI SummaryQA filtered winter rolled    top         t
#>    1:  2 2003        NA   NA        NA       NA   5382     NA 7462.9        NA
#>    2:  2 2009        NA   NA        NA       NA   5382     NA 7462.9        NA
#>    3:  2 2011        NA   NA        NA       NA   5382     NA 7462.9        NA
#>    4:  2 2011        NA   NA        NA       NA   5382     NA 7462.9        NA
#>    5:  4 2002        61  375         2       NA   5180     NA 7288.1 0.1643836
#>   ---                                                                         
#> 1261:  5 2011       247 7634         0     7634   4621   7727 7645.1 0.6739726
#> 1262:  4 2005       251 7554         0     7554   5180   7554 7288.1 0.6849315
#> 1263:  4 2009       253 7289         0     7289   5180   7289 7288.1 0.6904110
#> 1264:  2 2008       256 7581         0     7581   5382   7581 7462.9 0.6986301
#> 1265:  5 2012       262 7773         1     7773   4621   7905 7645.1 0.7150685
#>       scaled xmidS_start xmidA_start
#>    1:     NA   0.4767123   0.7150685
#>    2:     NA   0.4575342          NA
#>    3:     NA   0.4986301   0.7780822
#>    4:     NA   0.4986301   0.7780822
#>    5:     NA   0.4328767   0.8164384
#>   ---                               
#> 1261:      1   0.4000000   0.7890411
#> 1262:      1   0.4657534   0.7534247
#> 1263:      1   0.4547945   0.7479452
#> 1264:      1   0.4712329   0.8164384
#> 1265:      1   0.3342466          NA

## 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   yr DayOfYear NDVI SummaryQA filtered winter rolled    top         t
#>    1:  2 2003        NA   NA        NA       NA   5382     NA 7462.9        NA
#>    2:  2 2009        NA   NA        NA       NA   5382     NA 7462.9        NA
#>    3:  2 2011        NA   NA        NA       NA   5382     NA 7462.9        NA
#>    4:  2 2011        NA   NA        NA       NA   5382     NA 7462.9        NA
#>    5:  4 2002        61  375         2       NA   5180     NA 7288.1 0.1643836
#>   ---                                                                         
#> 1261:  5 2011       247 7634         0     7634   4621   7727 7645.1 0.6739726
#> 1262:  4 2005       251 7554         0     7554   5180   7554 7288.1 0.6849315
#> 1263:  4 2009       253 7289         0     7289   5180   7289 7288.1 0.6904110
#> 1264:  2 2008       256 7581         0     7581   5382   7581 7462.9 0.6986301
#> 1265:  5 2012       262 7773         1     7773   4621   7905 7645.1 0.7150685
#>       scaled xmidS_start xmidA_start     xmidS     xmidA      scalS       scalA
#>    1:     NA   0.4767123   0.7150685 0.4964268 0.7941240 0.05571006 0.020099805
#>    2:     NA   0.4575342          NA        NA        NA         NA          NA
#>    3:     NA   0.4986301   0.7780822 0.4755532 0.7792491 0.03967694 0.001239339
#>    4:     NA   0.4986301   0.7780822 0.4755532 0.7792491 0.03967694 0.001239339
#>    5:     NA   0.4328767   0.8164384 0.4575765 0.7936199 0.04381232 0.022093920
#>   ---                                                                          
#> 1261:      1   0.4000000   0.7890411 0.3849842 0.7958631 0.05821012 0.006832000
#> 1262:      1   0.4657534   0.7534247 0.4460866 0.7663753 0.04789319 0.015692077
#> 1263:      1   0.4547945   0.7479452 0.4135524 0.7681056 0.06652878 0.016852305
#> 1264:      1   0.4712329   0.8164384 0.4766004 0.8210523 0.02166666 0.007690347
#> 1265:      1   0.3342466          NA        NA        NA         NA          NA

# Fit double logistic curve to NDVI time series for the observed days
model_ndvi(ndvi, observed = TRUE)
#>       id   yr DayOfYear NDVI SummaryQA filtered winter rolled    top         t
#>    1:  2 2003        NA   NA        NA       NA   5382     NA 7462.9        NA
#>    2:  2 2009        NA   NA        NA       NA   5382     NA 7462.9        NA
#>    3:  2 2011        NA   NA        NA       NA   5382     NA 7462.9        NA
#>    4:  2 2011        NA   NA        NA       NA   5382     NA 7462.9        NA
#>    5:  4 2002        61  375         2       NA   5180     NA 7288.1 0.1643836
#>   ---                                                                         
#> 1261:  5 2011       247 7634         0     7634   4621   7727 7645.1 0.6739726
#> 1262:  4 2005       251 7554         0     7554   5180   7554 7288.1 0.6849315
#> 1263:  4 2009       253 7289         0     7289   5180   7289 7288.1 0.6904110
#> 1264:  2 2008       256 7581         0     7581   5382   7581 7462.9 0.6986301
#> 1265:  5 2012       262 7773         1     7773   4621   7905 7645.1 0.7150685
#>       scaled xmidS_start xmidA_start     xmidS     xmidA      scalS       scalA
#>    1:     NA   0.4767123   0.7150685 0.4964268 0.7941240 0.05571006 0.020099805
#>    2:     NA   0.4575342          NA        NA        NA         NA          NA
#>    3:     NA   0.4986301   0.7780822 0.4755532 0.7792491 0.03967694 0.001239339
#>    4:     NA   0.4986301   0.7780822 0.4755532 0.7792491 0.03967694 0.001239339
#>    5:     NA   0.4328767   0.8164384 0.4575765 0.7936199 0.04381232 0.022093920
#>   ---                                                                          
#> 1261:      1   0.4000000   0.7890411 0.3849842 0.7958631 0.05821012 0.006832000
#> 1262:      1   0.4657534   0.7534247 0.4460866 0.7663753 0.04789319 0.015692077
#> 1263:      1   0.4547945   0.7479452 0.4135524 0.7681056 0.06652878 0.016852305
#> 1264:      1   0.4712329   0.8164384 0.4766004 0.8210523 0.02166666 0.007690347
#> 1265:      1   0.3342466          NA        NA        NA         NA          NA
#>            fitted
#>    1:          NA
#>    2:          NA
#>    3:          NA
#>    4:          NA
#>    5: 0.001239236
#>   ---            
#> 1261: 0.993067449
#> 1262: 0.987679925
#> 1263: 0.974804222
#> 1264: 0.999964434
#> 1265:          NA