Giter Site home page Giter Site logo

Comments (6)

jeffreyhanson avatar jeffreyhanson commented on June 15, 2024 1

Brilliant - thanks! Yeah, I'm mainly interested in using INLA for the integrated modelling, so understanding how it uses the mesh and how that relates to psuedo-absences was my main question/uncertainty here. Sorry, I should have been more explicit about that in the original post.

from ibis.isdm.

jeffreyhanson avatar jeffreyhanson commented on June 15, 2024

For example, here's a reprex, where I try to manually specify pseudo-absences for a PPM model. It just occurred to me - I'm assuming PPM models actually use pseudo-absences, maybe I've got this wong and they don't use pseudo-absences so my question is invalid (e.g., something like asking "what is the best way to remove the scales from a bear? what do you mean, bears don't scales...")

# load packages
library(ibis.iSDM)

# load data
bg_data <- 
  system.file("extdata/europegrid_50km.tif", package = "ibis.iSDM") |>
  terra::rast()
spp_data <- 
  system.file("extdata/input_data.gpkg", package = "ibis.iSDM") |>
  sf::read_sf()
env_data <- 
  system.file("extdata/predictors/", package = "ibis.iSDM") |>
  list.files("*.tif", full.names = TRUE) |>
  terra::rast()

# add pseudo-absences
psa_sett <- pseudoabs_settings(background = bg_data, nrpoints = 200, method =  "random")
spp_data2 <- add_pseudoabsence(df = spp_data, field_occurrence = "Observed", settings = psa_sett)

# define model specification
model <- 
  distribution(bg_data)  |>  
  add_predictors(env = env_data, transform = "scale", derivates = "none")  |> 
  add_biodiversity_poipo(spp_data2, field_occurrence = "Observed") |>  
  engine_inlabru()
#> [Setup] 2024-02-02 11:55:49.360766 | Provide a background with a valid projection!
#> [Setup] 2024-02-02 11:55:49.376749 | Creating distribution object...
#> [Setup] 2024-02-02 11:55:49.41185 | Adding predictors...
#> [Setup] 2024-02-02 11:55:49.413278 | Transforming predictors...
#> [Setup] 2024-02-02 11:55:49.484272 | Adding poipo dataset...
#> [Setup] 2024-02-02 11:55:49.651038 | Absence points found. Potentially this data needs to be added as presence-absence instead?

from ibis.isdm.

Martin-Jung avatar Martin-Jung commented on June 15, 2024

Heya,
a few things:

  1. In your example you are taking a presence-only dataset and manually add pseudo-absence points to it. This changes the dataset to a presence-absence dataset and during model building the package correctly complains that there are Absence points found. If you want to manually add absence-points prior to fitting, then add the biodiversity dataset via add_biodiversity_poipa() instead of with add_biodiversity_poipo()
  2. There are some basic plotting functionalities in any BiodiversityDataset which you can simply access via x$plot(). For example if points are added as presence-absence in your above example this looks like this
model <- 
  distribution(bg_data)  |>  
  add_predictors(env = env_data, transform = "scale", derivates = "none")  |> 
  add_biodiversity_poipa(spp_data2, field_occurrence = "Observed") |>  
  engine_inlabru()

model$biodiversity$plot()

grafik

  1. If you need to control any pseudo-absence generation in add_biodiversity_poipo() you could pass a specific Settings object (created with pseudoabs_settings() there to the parameter pseudoabsence_settings). This changes the default behaviour for sampling any pseudo-absence data throughout. INLA for example treats every single node on a mesh that as background by default for any lgcp inferences...

  2. If you want to access the biodiversity data in your model object, this can be found in model$biodiversity. The respective functions for this (sorry for missing documentation still) would be to first query the id of the dataset and then return the data as sf object.
    Example:
    model$biodiversity$get_data( model$biodiversity$get_ids()[[1]] )
    Similar ways exist to query the point data from fitted DistributionModel objects by looking within the fit$model$biodiversity object which contains all data used for inference.

Hope that helps.

from ibis.isdm.

jeffreyhanson avatar jeffreyhanson commented on June 15, 2024

Thanks for explaining all that - that's really helpful!

Just to clarify, if I'm using presence-only data (via add_biodiversity_poipo()) with the inlabru engine (via engine_inlabru()), then the INLA mesh is used for the pseudo-absence points and the pseudoabsence_settings parameter of add_biodiversity_poipo() is ignored?

from ibis.isdm.

Martin-Jung avatar Martin-Jung commented on June 15, 2024

Thanks for explaining all that - that's really helpful!

Just to clarify, if I'm using presence-only data (via add_biodiversity_poipo()) with the inlabru engine (via engine_inlabru()), then the INLA mesh is used for the pseudo-absence points and the pseudoabsence_settings parameter of add_biodiversity_poipo() is ignored?

For INLA So far yes (code starting here), although I think this can actually be passed on as well somehow via method stack. TBD when I have time to think about the other INLA issue.
Will report back.
For other engines this is already the default behaviour (for a Bayesian engine you could try it out with engine_breg() and a single data type).

from ibis.isdm.

Martin-Jung avatar Martin-Jung commented on June 15, 2024

Aye, understand. INLA has so far been the hardest to maintain thus the many changes and relatively messy code still :D

from ibis.isdm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.