inlabru-org / inlabru

inlabru
https://inlabru-org.github.io/inlabru/
73 stars 21 forks source link

Gorillas example is failing in UseMethod("fm_int") #203

Closed dmi3kno closed 10 months ago

dmi3kno commented 10 months ago

Gorillas example is failing in the latest version of INLA/inlabru

Brief description of the problem

library(inlabru)
#> Loading required package: fmesher
#> The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
#> which was just loaded, will retire in October 2023.
#> Please refer to R-spatial evolution reports for details, especially
#> https://r-spatial.org/r/2023/05/15/evolution4.html.
#> It may be desirable to make the sf package available;
#> package maintainers should consider adding sf to Suggests:.
#> The sp package is now running under evolution status 2
#>      (status 2 uses the sf package in place of rgdal)
library(INLA)
#> Loading required package: Matrix
#> Loading required package: foreach
#> Loading required package: parallel
#> Loading required package: sp
#> This is INLA_23.04.24 built 2023-04-24 19:15:35 UTC.
#>  - See www.r-inla.org/contact-us for how to get help.
#>  - To enable PARDISO sparse library; see inla.pardiso()
library(ggplot2)
bru_options_set(bru_verbose = TRUE,
                control.compute = list(dic = TRUE, waic = TRUE))
data(gorillas, package = "inlabru")

nests <- gorillas$nests
mesh <- gorillas$mesh
boundary <- gorillas$boundary

# fit LGCP model

matern <- inla.spde2.pcmatern(mesh,
            prior.sigma = c(0.1, 0.01),
            prior.range = c(5, 0.01))

cmp <- coordinates ~ mySmooth(main=coordinates, model=matern) + Intercept(1)

fit1<- lgcp(components=cmp, data=nests, samplers = boundary)
#> Error in UseMethod("fm_int"): no applicable method for 'fm_int' applied to an object of class "NULL"

Created on 2023-08-31 with reprex v2.0.2

current session info ```r ─ Session info ─────────────────────────────────────────── setting value version R version 4.3.0 (2023-04-21) os Ubuntu 22.04.3 LTS system x86_64, linux-gnu ui RStudio language (EN) collate en_US.UTF-8 ctype en_US.UTF-8 tz Europe/Stockholm date 2023-08-31 rstudio 2023.06.1+524 Mountain Hydrangea (desktop) pandoc 3.1.1 @ /usr/lib/rstudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown) ─ Packages ─────────────────────────────────────────────── package * version date (UTC) lib source bit 4.0.5 2022-11-15 [1] CRAN (R 4.3.0) bit64 4.0.5 2020-08-30 [1] CRAN (R 4.3.0) blob 1.2.4 2023-03-17 [1] CRAN (R 4.3.0) cachem 1.0.8 2023-05-01 [1] CRAN (R 4.3.0) callr 3.7.3 2022-11-02 [1] CRAN (R 4.3.0) class 7.3-21 2023-01-23 [4] CRAN (R 4.2.2) classInt 0.4-9 2023-02-28 [1] CRAN (R 4.3.0) cli 3.6.1 2023-03-23 [1] CRAN (R 4.3.0) clipr 0.8.0 2022-02-22 [1] CRAN (R 4.3.0) codetools 0.2-19 2023-02-01 [4] CRAN (R 4.2.2) colorspace 2.1-0 2023-01-23 [1] CRAN (R 4.3.0) crancache 0.0.0.9001 2023-06-27 [1] Github (r-lib/crancache@7ea4e47) cranlike 1.0.2 2018-11-26 [1] CRAN (R 4.3.0) crayon 1.5.2 2022-09-29 [1] CRAN (R 4.3.0) curl 5.0.2 2023-08-14 [1] CRAN (R 4.3.0) DBI 1.1.3 2022-06-18 [1] CRAN (R 4.3.0) debugme 1.1.0 2017-10-22 [1] CRAN (R 4.3.0) desc 1.4.2 2022-09-08 [1] CRAN (R 4.3.0) details 0.3.0 2022-03-27 [1] CRAN (R 4.3.0) digest 0.6.33 2023-07-07 [1] CRAN (R 4.3.0) dplyr 1.1.2 2023-04-20 [1] CRAN (R 4.3.0) e1071 1.7-13 2023-02-01 [1] CRAN (R 4.3.0) evaluate 0.21 2023-05-05 [1] CRAN (R 4.3.0) fansi 1.0.4 2023-01-22 [1] CRAN (R 4.3.0) farver 2.1.1 2022-07-06 [1] CRAN (R 4.3.0) fastmap 1.1.1 2023-02-24 [1] CRAN (R 4.3.0) fmesher * 0.1.2 2023-08-25 [1] CRAN (R 4.3.0) foreach * 1.5.2 2022-02-02 [1] CRAN (R 4.3.0) fs 1.6.3 2023-07-20 [1] CRAN (R 4.3.0) generics 0.1.3 2022-07-05 [1] CRAN (R 4.3.0) ggplot2 * 3.4.3 2023-08-14 [1] CRAN (R 4.3.0) ggpolypath 0.2.0 2022-10-11 [1] CRAN (R 4.3.0) glue 1.6.2 2022-02-24 [1] CRAN (R 4.3.0) gtable 0.3.4 2023-08-21 [1] CRAN (R 4.3.0) htmltools 0.5.6 2023-08-10 [1] CRAN (R 4.3.0) httr 1.4.7 2023-08-15 [1] CRAN (R 4.3.0) INLA * 23.04.24 2023-04-24 [1] local inlabru * 2.9.0 2023-08-31 [1] Github (inlabru-org/inlabru@0ce8af3) iterators 1.0.14 2022-02-05 [1] CRAN (R 4.3.0) KernSmooth 2.23-20 2021-05-03 [4] CRAN (R 4.0.5) knitr 1.43 2023-05-25 [1] CRAN (R 4.3.0) labeling 0.4.3 2023-08-29 [1] CRAN (R 4.3.0) lattice 0.21-8 2023-04-05 [4] CRAN (R 4.3.0) lifecycle 1.0.3 2022-10-07 [1] CRAN (R 4.3.0) magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.3.0) Matrix * 1.6-1 2023-08-14 [1] CRAN (R 4.3.0) memoise 2.0.1 2021-11-26 [1] CRAN (R 4.3.0) munsell 0.5.0 2018-06-12 [1] CRAN (R 4.3.0) parsedate 1.3.1 2022-10-27 [1] CRAN (R 4.3.0) pillar 1.9.0 2023-03-22 [1] CRAN (R 4.3.0) pkgbuild 1.4.2 2023-06-26 [1] CRAN (R 4.3.0) pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.3.0) png 0.1-8 2022-11-29 [1] CRAN (R 4.3.0) prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.3.0) processx 3.8.2 2023-06-30 [1] CRAN (R 4.3.0) proxy 0.4-27 2022-06-09 [1] CRAN (R 4.3.0) ps 1.7.5 2023-04-18 [1] CRAN (R 4.3.0) R6 2.5.1 2021-08-19 [1] CRAN (R 4.3.0) rappdirs 0.3.3 2021-01-31 [1] CRAN (R 4.3.0) RColorBrewer 1.1-3 2022-04-03 [1] CRAN (R 4.3.0) Rcpp 1.0.11 2023-07-06 [1] CRAN (R 4.3.0) rematch2 2.1.2 2020-05-01 [1] CRAN (R 4.3.0) remotes 2.4.2.1 2023-07-18 [1] CRAN (R 4.3.0) reprex 2.0.2 2022-08-17 [1] CRAN (R 4.3.0) rlang 1.1.1 2023-04-28 [1] CRAN (R 4.3.0) rmarkdown 2.24 2023-08-14 [1] CRAN (R 4.3.0) rprojroot 2.0.3 2022-04-02 [1] CRAN (R 4.3.0) RSQLite 2.3.1 2023-04-03 [1] CRAN (R 4.3.0) rstudioapi 0.15.0 2023-07-07 [1] CRAN (R 4.3.0) scales 1.2.1 2022-08-20 [1] CRAN (R 4.3.0) sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.3.0) sf 1.0-14 2023-07-11 [1] CRAN (R 4.3.0) sp * 2.0-0 2023-06-22 [1] CRAN (R 4.3.0) tibble 3.2.1 2023-03-20 [1] CRAN (R 4.3.0) tidyselect 1.2.0 2022-10-10 [1] CRAN (R 4.3.0) units 0.8-3 2023-08-10 [1] CRAN (R 4.3.0) utf8 1.2.3 2023-01-31 [1] CRAN (R 4.3.0) vctrs 0.6.3 2023-06-14 [1] CRAN (R 4.3.0) withr 2.5.0 2022-03-03 [1] CRAN (R 4.3.0) xfun 0.40 2023-08-09 [1] CRAN (R 4.3.0) xml2 1.3.5 2023-07-06 [1] CRAN (R 4.3.0) yaml 2.3.7 2023-01-23 [1] CRAN (R 4.3.0) [1] /home/dm0737pe/R/x86_64-pc-linux-gnu-library/4.3 [2] /usr/local/lib/R/site-library [3] /usr/lib/R/site-library [4] /usr/lib/R/library ────────────────────────────────────────────────────────── ```
EDIT: I think I should add a traceback to indicate where the issue is. I suspect the default `domain=NULL` is not going very well with `like()` ```r traceback() #> 3: fm_int(domain = domain, samplers = samplers, int.args = options[["bru_int_args"]]) #> 2: like(family = "cp", formula = formula, data = data, samplers = samplers, #> ips = ips, domain = domain, ..., options = options, .envir = .envir) #> 1: lgcp(cmp, nests, samplers = boundary) ```
dmi3kno commented 10 months ago

I see that in the new format (oriented at sf format) the model specification is done with bru(...like(domain=)). I understand that this old format is soon to be retired. I am struggling to follow the documentation.

I am going to close this for now, in case folks want to discover this the new format is described on the front page of the repo.

finnlindgren commented 10 months ago

lgcp(..., domain = ...) will also work. The issue was just that a domain specification has been required for a while now (unless the user supplies ips information), but the error message didn't make that clear. The "new" syntax isn't actually new; we've just updated some examples to make less use of special cases like the lgcp() convenience wrapper, so that more complex models, e.g. with multiple observations models, become easier to explain.

I'm adding a hopefully more clear error message.

finnlindgren commented 10 months ago

The version without domain argument has been deprecated ever since version 2.3.0, see https://inlabru-org.github.io/inlabru/news/index.html#inlabru-230 Did you find the non-working example on a website? The examples on inlabru.org are still the old one and apply only to versions up to 2.1.13. For all later versions, the examples on https://inlabru-org.github.io/inlabru should be used instead.

finnlindgren commented 10 months ago

The 'sp' support will remain as long as it's practical, but due to how sp now internally converts to sf, and the rgdal and rgeos packages will retire in October, I would recommend to switch to sf and terra objects instead of sf.

The main difference in user code of inlabru is that where for sp data you needed domain=list(coordinates = mesh), for sf data you need domain=list(geometry=mesh). Almost all functions have been given interfaces that work exactly the same regardless of input type.

dmi3kno commented 10 months ago

Did you find the non-working example on a website?

yes, I have been working through the 1 day tutorial.

finnlindgren commented 10 months ago

Those examples are now very outdated, but the https://inlabru-org.github.io/inlabru/articles documents are mostly based on them (but updated to work with newer version), so going through the github.io Articles is likely a better option; the website menu categorises the examples into different sections.