inbo / alien-species-portal

Portal for alien and invasive species indicators
MIT License
0 stars 0 forks source link

[Enhancement] add year slider to GAM indicators #85

Closed SanderDevisscher closed 2 months ago

SanderDevisscher commented 3 months ago

Feature title

species information > indicators > Emergence status (GAM) - Observations species information > indicators > Emergence status (GAM) - Occupancy (after #84)

Description

add a year range slider which filters the input data for the GAMs. Default (current year - 3) - (current year -1).

(Optional) Needed changes in backoffice

none

mvarewyck commented 2 months ago

@SanderDevisscher Which years you want to define?

SanderDevisscher commented 2 months ago

@SanderDevisscher Which years you want to define?

  • eval_years: reference period for the GAM estimation in trias

I mean this yes. So a slider to change the eval_years parameter of the apply_gam() function.

  • year: subset the data wrt to these years

not this

mvarewyck commented 2 months ago

@SanderDevisscher Which years you want to define?

  • eval_years: reference period for the GAM estimation in trias

I mean this yes. So a slider to change the eval_years parameter of the apply_gam() function.

  • year: subset the data wrt to these years

not this

The parameter eval_years doesn't have any effect on the results (output data + plot) we show. I have just tested using an example from trias. (It does change the returned em_summary, but this we don't use in the app)

    library(trias)
    library(dplyr)
    df_gam <- tibble(
      taxonKey = rep(3003709, 24),
      canonicalName = rep("Rosa glauca", 24),
      year = seq(1995, 2018),
      n = c(
        1, 1, 0, 0, 0, 2, 0, 0, 1, 3, 1, 2, 0, 5, 0, 5, 4, 2, 1,
        1, 3, 3, 8, 10
      ),
      n_class = c(
        229, 555, 1116, 939, 919, 853, 442, 532, 623, 1178, 732, 371, 1053,
        1001, 1550, 1142, 1076, 1310, 922, 1773, 1637,
        1866, 2234, 2013
      )
    )
    # apply GAM to n without baseline as covariate
    result1 <- apply_gam(df_gam,
      y_var = "n",
      eval_years = 2018,
      taxon_key = 3003709,
      name = "Rosa glauca",
      verbose = TRUE
    )
    result1$plot

    result2 <- apply_gam(df_gam,
      y_var = "n",
      eval_years = 2000,
      taxon_key = 3003709,
      name = "Rosa glauca",
      verbose = TRUE
    )
    all(result2$output == result1$output)
    # [1] "Analyzing: Rosa glauca(3003709)"
    # [1] "Analyzing: Rosa glauca(3003709)"
    # [1] TRUE

This is the expected behavior following the documentation of trias

@SanderDevisscher Could you explain what you want in the app?

SanderDevisscher commented 2 months ago

@mvarewyck in that case we can drop the year slider