├── .github ├── .gitignore ├── ISSUE_TEMPLATE │ └── issue_template.md └── workflows │ └── lint.yaml ├── vignettes ├── .gitignore ├── articles │ ├── .gitignore │ └── mermaid_updater.R └── articles.Rmd ├── R ├── 0_inlabru_envir.R ├── fmesher.R ├── deprecated.R ├── access_trace.R ├── data.toygroups.R ├── data.toypoints.R ├── data.mrsea.R ├── data.shrimp.R ├── data.Poisson1_1D.R ├── inlabru-package.R └── data.robins_subset.R ├── data ├── mrsea.rda ├── shrimp.rda ├── toygroups.rda ├── toypoints.rda ├── Poisson1_1D.rda ├── Poisson2_1D.rda ├── Poisson3_1D.rda ├── gorillas_sf.rda ├── mexdolphin_sf.rda └── robins_subset.rda ├── tests ├── testthat │ ├── setup.R │ ├── _snaps │ │ ├── latent_spde_1d.md │ │ ├── lgcp_2d_plotsample.md │ │ ├── lgcp_2d_covars.md │ │ ├── lgcp_1d.md │ │ └── 01_lgcp_2d.md │ ├── test-skips.R │ ├── test-environment.R │ ├── test-latent_clinear.R │ ├── test-additive.R │ ├── test-latent_spde_1d.R │ ├── test-offset.R │ ├── test-fmesher_pixels.R │ ├── test-latent_rw2.R │ ├── test-utils.R │ └── test-bru_sf.R └── testthat.R ├── misc ├── seals_sf.rda ├── .gitignore ├── dots_speed_test.R ├── full_join_with_sf.R ├── old_shapefile_code.R ├── obs.R ├── data.seals.R ├── apmaker.R └── mdata_testing.R ├── inst ├── extdata │ ├── gamba.Rdata │ └── gorillas_cov.tif ├── misc │ ├── Lambert_ocean.png │ └── Lambert_ocean_orig.png ├── figures │ └── inlabru_hex_sticker.png └── examples │ ├── rgl.R │ ├── gg.fm_mesh_2d.R │ ├── data.toygroups.R │ ├── generate.bru.R │ ├── prediction.bru.R │ ├── bru.R │ ├── spde.posterior.R │ ├── gg.sf.R │ ├── gg.sp.R │ └── bru_obs.R ├── sf ├── Data │ └── gorillas_sf.rds └── Sandpit │ └── gorillas.R ├── man ├── figures │ ├── README-plot-1.png │ ├── README-example-1.png │ ├── lifecycle-defunct.svg │ ├── lifecycle-archived.svg │ ├── lifecycle-maturing.svg │ ├── lifecycle-deprecated.svg │ ├── lifecycle-superseded.svg │ ├── lifecycle-questioning.svg │ ├── lifecycle-experimental.svg │ ├── lifecycle-soft-deprecated.svg │ └── lifecycle-stable.svg ├── bru_env_get.Rd ├── gorillas.Rd ├── mexdolphin.Rd ├── bru_formula_to_bru_obs_code.Rd ├── reexports.Rd ├── expand_labels.Rd ├── bru_timings.Rd ├── inla_subset_eval.Rd ├── bru_call_options.Rd ├── bru_timings_plot.Rd ├── bru_inla_formula.Rd ├── bru_standardise_names.Rd ├── as_bru_mapper.Rd ├── parse_inclusion.Rd ├── bru_names.Rd ├── bru_log_new.Rd ├── bm_mesh_B.Rd ├── gg.matrix.Rd ├── toypoints.Rd ├── bru_make_stack.Rd ├── bru_used_update.Rd ├── bru_is_rowwise.Rd ├── bru_inla.stack.mexpand.Rd ├── mrsea.Rd ├── gg.SpatRaster.Rd ├── summary.bru_options.Rd ├── bru_mapper_generics.Rd ├── bru_obs_print.Rd ├── cv_hex.Rd ├── summary.bru_input.Rd ├── bru_inla.stack.mjoin.Rd ├── cv_partition.Rd ├── bru_is_additive.Rd ├── bm_fm_mesh_old.Rd ├── bm_list.Rd ├── spatial.to.ppp.Rd ├── extract_property.Rd ├── bm_const.Rd ├── bru_safe_inla.Rd ├── bm_linear.Rd ├── bru_safe_sp.Rd ├── gg.SpatialPixels.Rd ├── shrimp.Rd ├── bru_is_linear.Rd ├── ibm_is_rowwise.Rd ├── deltaIC.Rd ├── add_mappers.Rd ├── bm_index.Rd ├── gg.fm_mesh_1d.Rd ├── gg.RasterLayer.Rd ├── bru_summarise.Rd ├── bru_transformation.Rd ├── globe.Rd ├── bru_log_reset.Rd ├── as_bru_obs.Rd ├── point2count.Rd ├── eval_spatial.Rd ├── evaluate_effect.Rd ├── Poisson1_1D.Rd ├── iinla.Rd ├── bru_log_offset.Rd ├── bru_log_bookmark.Rd ├── ibm_inla_subset.Rd ├── multiplot.Rd ├── bru_eval_in_data_context.Rd ├── plot.bru.Rd ├── bm_scale.Rd ├── bm_reparam.Rd ├── bm_shift.Rd ├── bru_used_vars.Rd ├── bm_matrix.Rd ├── as_bru_comp.Rd ├── spoly.Rd ├── toygroups.Rd ├── ibm_input.Rd ├── gg.Rd ├── bru_convergence_plot.Rd ├── bru_model_mapper_methods.Rd ├── bm_pipe.Rd ├── bm_repeat_indexing.Rd ├── robins_subset.Rd ├── summary.bru_comp.Rd ├── inlabru-package.Rd ├── plotsample.Rd ├── bru_fill_missing.Rd ├── sline.Rd ├── materncov.bands.Rd └── bru_comp_eval.Rd ├── .gitignore ├── codecov.yml ├── inlabru.Rproj ├── .Rbuildignore ├── data-raw ├── robins_subset.R ├── toygroups.R └── shrimp.R └── cran-comments.md /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | *.R 3 | -------------------------------------------------------------------------------- /vignettes/articles/.gitignore: -------------------------------------------------------------------------------- 1 | cache 2 | *_cache 3 | -------------------------------------------------------------------------------- /R/0_inlabru_envir.R: -------------------------------------------------------------------------------- 1 | .inlabru_envir <- new.env(parent = emptyenv()) 2 | -------------------------------------------------------------------------------- /data/mrsea.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inlabru-org/inlabru/HEAD/data/mrsea.rda -------------------------------------------------------------------------------- /data/shrimp.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inlabru-org/inlabru/HEAD/data/shrimp.rda -------------------------------------------------------------------------------- /tests/testthat/setup.R: -------------------------------------------------------------------------------- 1 | local_bru_testthat_setup(envir = testthat::teardown_env()) 2 | -------------------------------------------------------------------------------- /data/toygroups.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inlabru-org/inlabru/HEAD/data/toygroups.rda -------------------------------------------------------------------------------- /data/toypoints.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inlabru-org/inlabru/HEAD/data/toypoints.rda -------------------------------------------------------------------------------- /misc/seals_sf.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inlabru-org/inlabru/HEAD/misc/seals_sf.rda -------------------------------------------------------------------------------- /data/Poisson1_1D.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inlabru-org/inlabru/HEAD/data/Poisson1_1D.rda -------------------------------------------------------------------------------- /data/Poisson2_1D.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inlabru-org/inlabru/HEAD/data/Poisson2_1D.rda -------------------------------------------------------------------------------- /data/Poisson3_1D.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inlabru-org/inlabru/HEAD/data/Poisson3_1D.rda -------------------------------------------------------------------------------- /data/gorillas_sf.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inlabru-org/inlabru/HEAD/data/gorillas_sf.rda -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | if (require(testthat, quietly = TRUE)) { 2 | test_check("inlabru") 3 | } 4 | -------------------------------------------------------------------------------- /data/mexdolphin_sf.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inlabru-org/inlabru/HEAD/data/mexdolphin_sf.rda -------------------------------------------------------------------------------- /data/robins_subset.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inlabru-org/inlabru/HEAD/data/robins_subset.rda -------------------------------------------------------------------------------- /inst/extdata/gamba.Rdata: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inlabru-org/inlabru/HEAD/inst/extdata/gamba.Rdata -------------------------------------------------------------------------------- /sf/Data/gorillas_sf.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inlabru-org/inlabru/HEAD/sf/Data/gorillas_sf.rds -------------------------------------------------------------------------------- /inst/extdata/gorillas_cov.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inlabru-org/inlabru/HEAD/inst/extdata/gorillas_cov.tif -------------------------------------------------------------------------------- /inst/misc/Lambert_ocean.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inlabru-org/inlabru/HEAD/inst/misc/Lambert_ocean.png -------------------------------------------------------------------------------- /man/figures/README-plot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inlabru-org/inlabru/HEAD/man/figures/README-plot-1.png -------------------------------------------------------------------------------- /misc/.gitignore: -------------------------------------------------------------------------------- 1 | harmonic_tests.png 2 | hierarchical.html 3 | profile.html 4 | profile_files 5 | *.html 6 | *.pdf 7 | -------------------------------------------------------------------------------- /inst/misc/Lambert_ocean_orig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inlabru-org/inlabru/HEAD/inst/misc/Lambert_ocean_orig.png -------------------------------------------------------------------------------- /man/figures/README-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inlabru-org/inlabru/HEAD/man/figures/README-example-1.png -------------------------------------------------------------------------------- /inst/figures/inlabru_hex_sticker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inlabru-org/inlabru/HEAD/inst/figures/inlabru_hex_sticker.png -------------------------------------------------------------------------------- /tests/testthat/_snaps/latent_spde_1d.md: -------------------------------------------------------------------------------- 1 | # Latent models: SPDE 1D 2 | 3 | WAoAAAACAAQCAgACAwAAAAAOAAAAAz/g3WoquAOEP/P8MKp89di/+T+Xj2q5RA== 4 | 5 | -------------------------------------------------------------------------------- /R/fmesher.R: -------------------------------------------------------------------------------- 1 | #' @export 2 | fmesher::fm_cprod 3 | #' @export 4 | fmesher::fm_crs 5 | #' @export 6 | fmesher::fm_int 7 | #' @export 8 | fmesher::fm_pixels 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rhistory 2 | .Rproj.user 3 | inst/doc 4 | tmp 5 | check 6 | docs 7 | doc 8 | Meta 9 | revdep 10 | inla.model 11 | inla.model-* 12 | /doc/ 13 | /Meta/ 14 | *_cache 15 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/lgcp_2d_plotsample.md: -------------------------------------------------------------------------------- 1 | # 2D LGCP fitting and prediction: Plot sampling 2 | 3 | WAoAAAACAAQEAQACAwAAAAAOAAAAA0AEC+TkCdoSQAggf3H+vxNAFKSdz4/ALg== 4 | 5 | --- 6 | 7 | WAoAAAACAAQBAgACAwAAAAAOAAAAAz/zArZgAAAAP/LS7jAAAAA/8qk8MAAAAA== 8 | 9 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | 3 | coverage: 4 | status: 5 | project: 6 | default: 7 | target: auto 8 | threshold: 1% 9 | informational: true 10 | patch: 11 | default: 12 | target: auto 13 | threshold: 1% 14 | informational: true 15 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/lgcp_2d_covars.md: -------------------------------------------------------------------------------- 1 | # 2D LGCP fitting 2 | 3 | WAoAAAACAAQBAgACAwAAAAAOAAAABkAPbj5gAAAAQAGuY6AAAAA/+GXxgAAAAEAR0NjgAAAA 4 | QAxnLkAAAABAEIVmYAAAAA== 5 | 6 | --- 7 | 8 | WAoAAAACAAQBAgACAwAAAAAOAAAABj/jnpzgAAAAP7xLGQAAAAA/zKoYQAAAAD+m7c9AAAAA 9 | P8t3OQAAAAA/zCn6oAAAAA== 10 | 11 | -------------------------------------------------------------------------------- /R/deprecated.R: -------------------------------------------------------------------------------- 1 | #' Deprecated functions in inlabru 2 | #' 3 | #' Some of these functions may still attempt to do their job, but will be 4 | #' removed in a future version. 5 | #' 6 | #' @param \dots Usually passed on to other methods 7 | #' 8 | #' @author Finn Lindgren \email{finn.lindgren@@gmail.com} 9 | #' 10 | #' @name inlabru-deprecated 11 | NULL 12 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/lgcp_1d.md: -------------------------------------------------------------------------------- 1 | # 1D LGCP fitting 2 | 3 | c(0.0692068948621532, 0.638856076362609, -1.48202735600019) 4 | 5 | --- 6 | 7 | c(0.326825878084925, 0.183791391512224, 0.174461400896902) 8 | 9 | # 1D LGCP fitting, discrete point domain 10 | 11 | c(0.134797324643949, 0.763307064042203, -1.2492241963966) 12 | 13 | --- 14 | 15 | c(0.318805138537762, 0.179475644878133, 0.172582851395201) 16 | 17 | -------------------------------------------------------------------------------- /man/bru_env_get.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/environment.R 3 | \name{bru_env_get} 4 | \alias{bru_env_get} 5 | \title{Get access to the internal environment} 6 | \usage{ 7 | bru_env_get() 8 | } 9 | \description{ 10 | Get access to the internal environment 11 | } 12 | \details{ 13 | The environment is defined in \verb{0_inlabru_envir.R} which is loaded 14 | first. 15 | } 16 | \keyword{internal} 17 | -------------------------------------------------------------------------------- /man/gorillas.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.gorillas.R 3 | \name{gorillas} 4 | \alias{gorillas} 5 | \title{Deprecated alias for sp version of the gorillas dataset} 6 | \description{ 7 | Deprecated dataset name for the \code{sp} version 8 | of \link{gorillas_sf}. Use \code{\link[=gorillas_sp]{gorillas_sp()}} instead. 9 | } 10 | \seealso{ 11 | \link{gorillas_sf} 12 | } 13 | \keyword{internal} 14 | -------------------------------------------------------------------------------- /man/mexdolphin.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.mexdolphin.R 3 | \name{mexdolphin} 4 | \alias{mexdolphin} 5 | \title{Deprecated alias for sp version of the mexdolphin dataset} 6 | \description{ 7 | Deprecated dataset name for the \code{sp} version 8 | of \link{mexdolphin_sf}. Use \code{\link[=mexdolphin_sp]{mexdolphin_sp()}} instead. 9 | } 10 | \seealso{ 11 | \link{mexdolphin_sf} 12 | } 13 | \keyword{internal} 14 | -------------------------------------------------------------------------------- /inlabru.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | ProjectId: 75e30fae-25a5-4b8d-b06c-dff839a3795a 3 | 4 | RestoreWorkspace: Default 5 | SaveWorkspace: Default 6 | AlwaysSaveHistory: Default 7 | 8 | EnableCodeIndexing: Yes 9 | UseSpacesForTab: Yes 10 | NumSpacesForTab: 2 11 | Encoding: UTF-8 12 | 13 | RnwWeave: knitr 14 | LaTeX: pdfLaTeX 15 | 16 | AutoAppendNewline: Yes 17 | StripTrailingWhitespace: Yes 18 | 19 | BuildType: Package 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^_pkgdown\.yaml$ 2 | ^.*\.Rproj$ 3 | ^\.Rproj\.user$ 4 | ^\.travis\.yml$ 5 | ^README\.Rmd$ 6 | ^README-.*\.png$ 7 | ^cran-comments\.md$ 8 | ^docs$ 9 | ^vignettes/web$ 10 | ^codecov\.yml$ 11 | ^\.github$ 12 | ^tmp$ 13 | ^check$ 14 | ^_pkgdown\.yml$ 15 | ^pkgdown$ 16 | ^vignettes/articles$ 17 | ^doc$ 18 | ^Meta$ 19 | ^CRAN-RELEASE$ 20 | ^\.lintr$ 21 | ^CRAN-SUBMISSION$ 22 | ^revdep$ 23 | ^data-raw$ 24 | ^inst/misc/Lambert_ocean_orig.png$ 25 | ^sf$ 26 | ^misc$ 27 | ^inla.model 28 | ^man/chk$ 29 | ^man/chk_all$ 30 | ^man/chk_found$ 31 | ^cache$ 32 | -------------------------------------------------------------------------------- /man/bru_formula_to_bru_obs_code.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/effect.R 3 | \name{bru_formula_to_bru_obs_code} 4 | \alias{bru_formula_to_bru_obs_code} 5 | \title{Convert components to R code} 6 | \usage{ 7 | bru_formula_to_bru_obs_code(components, add = "") 8 | } 9 | \arguments{ 10 | \item{components}{A \link{formula} describing latent model components.} 11 | } 12 | \description{ 13 | Convert components to R code 14 | } 15 | \author{ 16 | Fabian E. Bachl \email{bachlfab@gmail.com} 17 | } 18 | \keyword{internal} 19 | -------------------------------------------------------------------------------- /sf/Sandpit/gorillas.R: -------------------------------------------------------------------------------- 1 | # convert the gorillas dataset to sf format 2 | # to use for testing 3 | 4 | library(inlabru) 5 | library(sf) 6 | 7 | data(gorillas, package = "inlabru") 8 | gorillas_sf <- list() 9 | 10 | gorillas_sf$nests <- st_as_sf(gorillas$nests) 11 | gorillas_sf$mesh <- gorillas$mesh 12 | gorillas_sf$boundary <- st_as_sf(gorillas$boundary) 13 | gorillas_sf$gcov <- lapply(gorillas$gcov, st_as_sf) 14 | gorillas_sf$plotsample <- lapply(gorillas$plotsample, st_as_sf) 15 | 16 | saveRDS( 17 | gorillas_sf, 18 | here::here("sf", "Data", "gorillas_sf.RDS") 19 | ) 20 | -------------------------------------------------------------------------------- /inst/examples/rgl.R: -------------------------------------------------------------------------------- 1 | \donttest{ 2 | if (interactive() && 3 | require("rgl", quietly = TRUE) && 4 | require("sphereplot", quietly = TRUE) && 5 | bru_safe_sp() && 6 | require("sp")) { 7 | # Show the globe 8 | globe() 9 | 10 | # Load pantropoical dolphin data 11 | mexdolphin <- inlabru::mexdolphin_sp() 12 | 13 | # Add mesh, ship transects and dolphin sightings stored 14 | # as fm_mesh_2d, SpatialLines and SpatialPoints objects, respectively 15 | 16 | glplot(mexdolphin$mesh, alpha = 0.2) 17 | glplot(mexdolphin$samplers, lwd = 5) 18 | glplot(mexdolphin$points, size = 10) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /man/reexports.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fmesher.R 3 | \docType{import} 4 | \name{reexports} 5 | \alias{reexports} 6 | \alias{fm_cprod} 7 | \alias{fm_crs} 8 | \alias{fm_int} 9 | \alias{fm_pixels} 10 | \title{Objects exported from other packages} 11 | \keyword{internal} 12 | \description{ 13 | These objects are imported from other packages. Follow the links 14 | below to see their documentation. 15 | 16 | \describe{ 17 | \item{fmesher}{\code{\link[fmesher]{fm_cprod}}, \code{\link[fmesher]{fm_crs}}, \code{\link[fmesher]{fm_int}}, \code{\link[fmesher]{fm_pixels}}} 18 | }} 19 | 20 | -------------------------------------------------------------------------------- /tests/testthat/test-skips.R: -------------------------------------------------------------------------------- 1 | # Note: 2 | # On non-CRAN systems, INLA should be installed when running the tests 3 | # but all inla-requiring tests should be protected specifically for missing 4 | # INLA. The check below should NOT be done, as it will fail when testing 5 | # without Suggests packages, which includes INLA. 6 | # The test is now disabled since it's empty 7 | # 8 | # Note 2: This test was likely dubious, as testthat might run it in the same 9 | # thread as some previous tests. 10 | 11 | # test_that("INLA loading", { 12 | # skip_on_cran() 13 | # # expect_error(local_bru_safe_inla(), NA, class = "skip") 14 | # }) 15 | -------------------------------------------------------------------------------- /man/expand_labels.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{expand_labels} 4 | \alias{expand_labels} 5 | \title{Expand labels} 6 | \usage{ 7 | expand_labels(labels, expand, suffix) 8 | } 9 | \arguments{ 10 | \item{labels}{character vector; original labels} 11 | 12 | \item{expand}{character vector; subset of labels to expand} 13 | 14 | \item{suffix}{character; the suffix to add to the labels selected by \code{expand}} 15 | } 16 | \value{ 17 | a vector of labels with suffix appended to the selected labels 18 | } 19 | \description{ 20 | Expand labels 21 | } 22 | \keyword{internal} 23 | -------------------------------------------------------------------------------- /man/bru_timings.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bru.inference.R 3 | \name{bru_timings} 4 | \alias{bru_timings} 5 | \alias{bru_timings.bru} 6 | \title{Extract timing information from fitted \link{bru} object} 7 | \usage{ 8 | bru_timings(object, ...) 9 | 10 | \method{bru_timings}{bru}(object, ...) 11 | } 12 | \arguments{ 13 | \item{object}{A fitted \code{bru} object} 14 | 15 | \item{\dots}{unused} 16 | } 17 | \description{ 18 | Extracts a data.frame or tibble with information about the \code{Time} (CPU), 19 | \code{System}, and \code{Elapsed} time for each step of a \code{bru()} run. 20 | } 21 | -------------------------------------------------------------------------------- /man/inla_subset_eval.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bru_index.R 3 | \name{inla_subset_eval} 4 | \alias{inla_subset_eval} 5 | \alias{inla_subset_eval.bru_comp_list} 6 | \title{Obtain inla index subset information} 7 | \usage{ 8 | inla_subset_eval(...) 9 | 10 | \method{inla_subset_eval}{bru_comp_list}(components, ...) 11 | } 12 | \arguments{ 13 | \item{\dots}{Passed on to submethods.} 14 | 15 | \item{components}{A component list.} 16 | } 17 | \description{ 18 | Subsets for \code{INLA::f()} compatible indexing 19 | } 20 | \author{ 21 | Finn Lindgren \email{finn.lindgren@gmail.com} 22 | } 23 | \keyword{internal} 24 | -------------------------------------------------------------------------------- /misc/dots_speed_test.R: -------------------------------------------------------------------------------- 1 | a_old <- function(...) { 2 | A <- list(...) 3 | Anames <- names(A) 4 | Alength <- length(A) 5 | B <- A[[20]] 6 | invisible() 7 | } 8 | a_new <- function(...) { 9 | A <- list(...) 10 | Anames <- ...names() 11 | Alength <- ...length() 12 | B <- ..20 13 | invisible() 14 | } 15 | 16 | a_new2 <- function(...) { 17 | Anames <- ...names() 18 | Alength <- ...length() 19 | B <- ..20 20 | invisible() 21 | } 22 | 23 | L <- as.list(seq_len(100)) 24 | names(L) <- as.character(L) 25 | profvis::profvis({ 26 | bench::mark( 27 | old = do.call(a_old, L), 28 | new = do.call(a_new, L), 29 | new = do.call(a_new2, L) 30 | ) 31 | }) 32 | -------------------------------------------------------------------------------- /data-raw/robins_subset.R: -------------------------------------------------------------------------------- 1 | ## code to prepare `robins_subset` dataset goes here 2 | 3 | library(tidyverse) 4 | 5 | # get data from tmmeeha/inlaSVCBC 6 | download_dat <- read.csv(paste0( 7 | "https://raw.github.com/tmeeha/inlaSVCBC/master/code/modeling_data.csv" 8 | )) 9 | 10 | robins_subset <- download_dat |> 11 | select( 12 | circle, bcr, state, year, std_yr, count, log_hrs, 13 | lon, lat, obs 14 | ) |> 15 | mutate(year = year + 1899) |> 16 | filter( 17 | state %in% c( 18 | "TEXAS", "OKLAHOMA", "KANSAS", "MISSOURI", 19 | "ARKANSAS", "LOUISIANA" 20 | ), 21 | year >= 1987 22 | ) 23 | 24 | usethis::use_data(robins_subset, overwrite = TRUE) 25 | -------------------------------------------------------------------------------- /misc/full_join_with_sf.R: -------------------------------------------------------------------------------- 1 | library(tidyverse) 2 | library(sf) 3 | 4 | X <- 5 | data.frame( 6 | x = 1:3, 7 | y = 2:4, 8 | time = 101:103, 9 | w = 1:3, 10 | grp = c(1, 1, 2) 11 | ) 12 | Y <- 13 | data.frame( 14 | x = 11:14, 15 | y = 22:25, 16 | z = c("A", "B", "C", "A"), 17 | w = 1:4, 18 | grp = c(1, 2, 1, 2) 19 | ) 20 | 21 | full_join(X, Y, by = "grp") 22 | 23 | X <- st_as_sf(X, coords = c("x", "y")) 24 | Y <- st_as_sf(Y, coords = c("x", "y")) 25 | st_geometry(Y) <- "something" 26 | Y 27 | 28 | Z <- full_join(as_tibble(X), as_tibble(Y), by = "grp") 29 | st_as_sf(Z) 30 | 31 | # This doesn't do what we want: 32 | st_join(X, Y, by = "grp") 33 | -------------------------------------------------------------------------------- /tests/testthat/test-environment.R: -------------------------------------------------------------------------------- 1 | test_that("bru_log", { 2 | bru_options_set_local( 3 | # Show messages up to and including level 2 (default 0) 4 | bru_verbose = 2, 5 | # Store messages to an including level 3 (default Inf, storing all) 6 | bru_verbose_store = 3 7 | ) 8 | 9 | bru_log_bookmark("bookmark 1") 10 | bru_log_message("Test message 1", verbosity = 1) 11 | bru_log_message("Test message 2", verbosity = 2) 12 | bru_log_bookmark("bookmark 2") 13 | bru_log_message("Test message 3", verbosity = 3) 14 | bru_log_message("Test message 4", verbosity = 4) 15 | 16 | expect_equal(length(bru_log()["bookmark 1"]), 2L) 17 | expect_equal(length(bru_log()["bookmark 2"]), 1L) 18 | }) 19 | -------------------------------------------------------------------------------- /misc/old_shapefile_code.R: -------------------------------------------------------------------------------- 1 | # Construct a covariate (function) returning region identifiers of locations 2 | # 3 | # @export 4 | # @param shapefile Either a character array identifying the shapefile or a shapefile 5 | # @param coords Coordinates to to be extracted from the location data provided to the constructed covariate 6 | # @examples \dontrun{ } 7 | # @author Fabian E. Bachl <\email{f.e.bachl@@bath.ac.uk}> 8 | # 9 | 10 | shapefile.to.covariate <- function(shapefile, coords = c("x", "y")) { 11 | if (is.character(shapefile)) { 12 | shapefile <- maptools::readShapeSpatial(shapefile) 13 | } 14 | 15 | fun <- function(loc) { 16 | sp::over(sp::SpatialPoints(as.data.frame(loc[, coords])), shapefile, fn = NULL)[, 1] 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /man/bru_call_options.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/environment.R 3 | \name{bru_call_options} 4 | \alias{bru_call_options} 5 | \title{Additional bru options} 6 | \usage{ 7 | bru_call_options(...) 8 | } 9 | \arguments{ 10 | \item{\dots}{Options passed on to \code{\link[=as.bru_options]{as.bru_options()}}} 11 | } 12 | \value{ 13 | A \code{bru_options} object 14 | } 15 | \description{ 16 | Construct a \code{bru_options} object including the default and global options, 17 | and converting deprecated option names. 18 | } 19 | \examples{ 20 | \donttest{ 21 | 22 | opts <- bru_call_options() 23 | 24 | # Print them: 25 | opts 26 | } 27 | 28 | } 29 | \author{ 30 | Finn Lindgren \email{finn.lindgren@gmail.com} 31 | } 32 | \keyword{internal} 33 | -------------------------------------------------------------------------------- /man/bru_timings_plot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/track_plotting.R 3 | \name{bru_timings_plot} 4 | \alias{bru_timings_plot} 5 | \title{Plot inlabru iteration timings} 6 | \usage{ 7 | bru_timings_plot(x) 8 | } 9 | \arguments{ 10 | \item{x}{a \link{bru} object, typically a result from \code{\link[=bru]{bru()}} for a nonlinear 11 | predictor model} 12 | } 13 | \description{ 14 | Draws the time per iteration for preprocessing (including linearisation), 15 | \code{inla()} calls, and 16 | line search. Iteration \code{0} is the time used for defining the model structure. 17 | } 18 | \details{ 19 | Requires the "ggplot2" package to be installed. 20 | } 21 | \examples{ 22 | \dontrun{ 23 | fit <- bru(...) 24 | bru_timings_plot(fit) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /vignettes/articles/mermaid_updater.R: -------------------------------------------------------------------------------- 1 | install.packages("DiagrammeR") 2 | #' Update the mermaid library in the package 3 | #' @param version A [character] of the desired version (the latest by default) 4 | #' @return See value returned by [download.file] 5 | updateMermaid <- function(version = "") { 6 | url <- "https://cdn.jsdelivr.net/npm/mermaid@version/dist/mermaid.min.js" 7 | if (version != "") { 8 | stopifnot(grepl("^[[:digit:]]+\\.[[:digit:]]+\\.[[:digit:]]+$", version)) 9 | version <- paste0("@", version) 10 | } 11 | url <- gsub("@version", version, url) 12 | try( 13 | download.file( 14 | url, 15 | system.file("htmlwidgets/lib/mermaid/dist/mermaid.slim.min.js", 16 | package = "DiagrammeR" 17 | ) 18 | ) 19 | ) 20 | } 21 | updateMermaid() 22 | -------------------------------------------------------------------------------- /man/bru_inla_formula.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bru.inference.R 3 | \name{bru_inla_formula} 4 | \alias{bru_inla_formula} 5 | \alias{bru_inla_formula.bru} 6 | \alias{bru_inla_formula.bru_info} 7 | \alias{bru_inla_formula.bru_comp_list} 8 | \title{Extract INLA formula} 9 | \usage{ 10 | bru_inla_formula(x, ...) 11 | 12 | \method{bru_inla_formula}{bru}(x, ...) 13 | 14 | \method{bru_inla_formula}{bru_info}(x, ...) 15 | 16 | \method{bru_inla_formula}{bru_comp_list}(x, ...) 17 | } 18 | \arguments{ 19 | \item{x}{An object containing information about an INLA formula} 20 | 21 | \item{\dots}{Additional arguments passed on to submethods} 22 | } 23 | \description{ 24 | Extracts the INLA formula used in a \code{bru} model 25 | } 26 | \keyword{internal} 27 | -------------------------------------------------------------------------------- /man/bru_standardise_names.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/inla.R 3 | \name{bru_standardise_names} 4 | \alias{bru_standardise_names} 5 | \title{Standardise inla hyperparameter names} 6 | \usage{ 7 | bru_standardise_names(x) 8 | } 9 | \arguments{ 10 | \item{x}{character vector; names to be standardised} 11 | } 12 | \value{ 13 | A character vector with standardised names 14 | } 15 | \description{ 16 | The inla hyperparameter output uses parameter names that can include 17 | whitespace and special characters. This function replaces those characters 18 | with underscores. 19 | } 20 | \examples{ 21 | bru_standardise_names("Precision for the Gaussian observations") 22 | } 23 | \seealso{ 24 | \code{\link[=bru_names]{bru_names()}} 25 | } 26 | \keyword{internal} 27 | -------------------------------------------------------------------------------- /man/as_bru_mapper.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mappers.R 3 | \name{as_bru_mapper} 4 | \alias{as_bru_mapper} 5 | \alias{as_bru_mapper.bru_mapper} 6 | \alias{as_bru_mapper.bru_comp} 7 | \alias{as_bru_mapper.bru_subcomp} 8 | \title{Methods for mapper extraction} 9 | \usage{ 10 | as_bru_mapper(x) 11 | 12 | \method{as_bru_mapper}{bru_mapper}(x) 13 | 14 | \method{as_bru_mapper}{bru_comp}(x) 15 | 16 | \method{as_bru_mapper}{bru_subcomp}(x) 17 | } 18 | \arguments{ 19 | \item{x}{Object to convert/extract} 20 | } 21 | \value{ 22 | A \code{bru_mapper} object 23 | } 24 | \description{ 25 | Extract a mapper from another object 26 | } 27 | \examples{ 28 | # Extract a mapper from a `bru_subcomp` object 29 | as_bru_mapper(bru_comp("x", x, mapper = bm_index(4))$main) 30 | 31 | } 32 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | ## Submission notes 2 | 3 | * Feature and bugfix release 2.13.0 4 | 5 | ## R CMD check results and comments 6 | 7 | * No change in RMD CMD check results 8 | * The non-CRAN Suggested package INLA has been extensively tested with inlabru 9 | locally and in github actions for both Linux, Windows, and macOS. 10 | The needed repository specification is included in the package DESCRIPTION: 11 | ``` 12 | Suggests or Enhances not in mainstream repositories: 13 | INLA 14 | Availability using Additional_repositories specification: 15 | INLA yes https://inla.r-inla-download.org/R/testing 16 | ``` 17 | 18 | ## revdepcheck results 19 | 20 | We checked all 7 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package. 21 | 22 | * We saw 0 new problems 23 | * We failed to check 0 packages 24 | -------------------------------------------------------------------------------- /R/access_trace.R: -------------------------------------------------------------------------------- 1 | access_trace <- function(name) { 2 | method <- fmesher::fm_caller_name(-1) 3 | access_method <- if (grepl("\\$", method)) { 4 | "$" 5 | } else if (grepl("\\[\\[", method)) { 6 | "[[" 7 | } else { 8 | NA_character_ 9 | } 10 | method_text <- if (access_method == "$") { 11 | "\\$" 12 | } else if (access_method == "[[") { 13 | "\\[\\[" 14 | } else { 15 | "" 16 | } 17 | open_text <- if (access_method == "$") { 18 | "$" 19 | } else if (access_method == "[[") { 20 | "[['" 21 | } else { 22 | "" 23 | } 24 | close_text <- if (access_method == "$") { 25 | "" 26 | } else if (access_method == "[[") { 27 | "]]'" 28 | } else { 29 | "" 30 | } 31 | class_name <- sub(paste0("^", method_text, "\\."), "", method) 32 | caller <- fmesher::fm_caller_name(-3) 33 | print(glue::glue("{caller}: {class_name}{open_text}{name}{close_text}")) 34 | } 35 | -------------------------------------------------------------------------------- /R/data.toygroups.R: -------------------------------------------------------------------------------- 1 | #' @name toygroups 2 | #' @title Simulated 1D animal group locations and group sizes 3 | #' @docType data 4 | #' @description 5 | #' 6 | #' This data set serves to teach the concept of modelling species that gather in 7 | #' groups and where the grouping behaviour depends on space. 8 | #' 9 | #' @usage data(toygroups) 10 | #' 11 | #' @format The data are a list that contains these elements: 12 | #' \describe{ 13 | #' \item{`groups`:}{ A `data.frame` of group locations `x` and size `size`} 14 | #' \item{`df.size`:}{ IGNORE THIS } 15 | #' \item{`df.intensity`:}{ A `data.frame` with Poisson process 16 | #' intensity `d.lambda` at locations `x`} 17 | #' \item{`df.rate`:}{ A `data.frame` the locations `x` and associated `rate` 18 | #' which parameterized the exponential distribution from which the group 19 | #' sizes were drawn.} 20 | #' } 21 | #' 22 | #' 23 | #' @example inst/examples/data.toygroups.R 24 | "toygroups" 25 | -------------------------------------------------------------------------------- /R/data.toypoints.R: -------------------------------------------------------------------------------- 1 | #' @name toypoints 2 | #' @title Simulated 2D point process data 3 | #' @docType data 4 | #' @description 5 | #' 6 | #' This data set serves as an example for basic inlabru. 7 | #' 8 | #' @usage data(toypoints) 9 | #' 10 | #' @format The data are a list that contains these elements: 11 | #' \describe{ 12 | #' \item{`points`}{An `sf` object of point locations and and `z` 13 | #' measurements} 14 | #' \item{`mesh`}{An `fm_mesh_2d` object} 15 | #' \item{`boundary`}{An `sf` polygon denting the region of interest} 16 | #' \item{`pred_locs`}{A `sf` object with prediction point locations} 17 | #' } 18 | #' 19 | #' 20 | #' @examples 21 | #' if (require("ggplot2")) { 22 | #' ggplot() + 23 | #' fmesher::geom_fm(data = toypoints$mesh, alpha = 0) + 24 | #' geom_sf(data = toypoints$boundary, fill = "blue", alpha = 0.1) + 25 | #' geom_sf(data = toypoints$points, aes(color = z)) + 26 | #' scale_color_viridis_c() 27 | #' } 28 | "toypoints" 29 | -------------------------------------------------------------------------------- /man/parse_inclusion.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bru.inference.R 3 | \name{parse_inclusion} 4 | \alias{parse_inclusion} 5 | \title{Parse inclusion of component labels in a predictor expression} 6 | \usage{ 7 | parse_inclusion(thenames, include = NULL, exclude = NULL) 8 | } 9 | \arguments{ 10 | \item{thenames}{Set of labels to restrict} 11 | 12 | \item{include}{Character vector of component labels that are needed by the 13 | predictor expression; Default: NULL (include all components that are not 14 | explicitly excluded)} 15 | 16 | \item{exclude}{Character vector of component labels that are not used by the 17 | predictor expression. The exclusion list is applied to the list 18 | as determined by the \code{include} parameter; Default: NULL (do not remove 19 | any components from the inclusion list)} 20 | } 21 | \description{ 22 | Parse inclusion of component labels in a predictor expression 23 | } 24 | \keyword{internal} 25 | -------------------------------------------------------------------------------- /inst/examples/gg.fm_mesh_2d.R: -------------------------------------------------------------------------------- 1 | \donttest{ 2 | if (require(fmesher, quietly = TRUE) && 3 | require(ggplot2, quietly = TRUE)) { 4 | 5 | # Load Gorilla data 6 | gorillas <- inlabru::gorillas_sf 7 | 8 | # Plot mesh using default edge colors 9 | 10 | ggplot() + 11 | gg(gorillas$mesh) 12 | 13 | # Don't show interior and exterior boundaries 14 | 15 | ggplot() + 16 | gg(gorillas$mesh, interior = FALSE, exterior = FALSE) 17 | 18 | # Change the edge colors 19 | 20 | ggplot() + 21 | gg(gorillas$mesh, 22 | edge.color = "green", 23 | int.color = "black", 24 | ext.color = "blue" 25 | ) 26 | 27 | # Use the x-coordinate of the vertices to colorize the triangles and 28 | # mask the plotted area by the survey boundary, i.e. only plot the inside 29 | 30 | xcoord <- gorillas$mesh$loc[, 1] 31 | ggplot() + 32 | gg(gorillas$mesh, color = (xcoord - 580), mask = gorillas$boundary) + 33 | gg(gorillas$boundary, alpha = 0) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /man/bru_names.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/inla.R 3 | \name{bru_names} 4 | \alias{bru_names} 5 | \alias{bru_names.inla} 6 | \alias{bru_names.bru} 7 | \title{Extract standardised names from a bru or inla result object} 8 | \usage{ 9 | bru_names(x) 10 | 11 | \method{bru_names}{inla}(x) 12 | 13 | \method{bru_names}{bru}(x) 14 | } 15 | \arguments{ 16 | \item{x}{an \code{inla} or \code{\link[=bru]{bru()}} result object} 17 | } 18 | \value{ 19 | A character vector with standardised names 20 | } 21 | \description{ 22 | Extracts the names of fixed effects, random effects, and hyperparameters, 23 | converted with \code{\link[=bru_standardise_names]{bru_standardise_names()}} 24 | } 25 | \examples{ 26 | if (bru_safe_inla()) { 27 | fit <- bru(y ~ 1 + x + z(z, model = "iid"), 28 | data = data.frame( 29 | y = rnorm(10), 30 | x = rnorm(10), 31 | z = rep(seq_len(2), 5) 32 | ) 33 | ) 34 | bru_names(fit) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /man/bru_log_new.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/environment.R 3 | \name{bru_log_new} 4 | \alias{bru_log_new} 5 | \title{Create a \code{bru_log} object} 6 | \usage{ 7 | bru_log_new(x = NULL, bookmarks = NULL) 8 | } 9 | \arguments{ 10 | \item{x}{An optional character vector of log messages, or \code{data.frame} 11 | with columns \code{message}, \code{timestamp}, and \code{verbosity}.} 12 | 13 | \item{bookmarks}{An optional \code{integer} vector of named bookmarks 14 | message in \code{x}.} 15 | } 16 | \description{ 17 | Create a \code{bru_log} object, by default empty. 18 | } 19 | \examples{ 20 | x <- bru_log_new() 21 | x <- bru_log_message("Test message", x = x) 22 | print(x) 23 | } 24 | \seealso{ 25 | Other inlabru log methods: 26 | \code{\link{bru_log}()}, 27 | \code{\link{bru_log_bookmark}()}, 28 | \code{\link{bru_log_message}()}, 29 | \code{\link{bru_log_offset}()}, 30 | \code{\link{bru_log_reset}()} 31 | } 32 | \concept{inlabru log methods} 33 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/01_lgcp_2d.md: -------------------------------------------------------------------------------- 1 | # 2D LGCP fitting (sf) 2 | 3 | WAoAAAACAAQFAQACAwAAAAAOAAAABcAAMB9BLvhTP9nu+U8+C6W/2JYxeu6ZJT/dNrUrVuA4 4 | v/q0CczPq/k= 5 | 6 | --- 7 | 8 | WAoAAAACAAQFAQACAwAAAAAOAAAABT/5fI8uHB+6P+xKwGpjIms/6oeMjjE2qz/pEgxnGDLz 9 | P/DdqkowbyU= 10 | 11 | --- 12 | 13 | WAoAAAACAAQFAQACAwAAAAAOAAAABMACemdQ6reXwADCZLMILSK/+37sMnSf97/nA41gF9wU 14 | 15 | 16 | --- 17 | 18 | WAoAAAACAAQFAQACAwAAAAAOAAAABD/lvtZhqfQWP+tl+nXWUrw/9LjvMOUXAEABA9yVDC5v 19 | 20 | 21 | # 2D LGCP fitting (sp) 22 | 23 | WAoAAAACAAQFAQACAwAAAAAOAAAABcAAMB9BLvhTP9nu+U8+C6W/2JYxeu6ZJT/dNrUrVuA4 24 | v/q0CczPq/k= 25 | 26 | --- 27 | 28 | WAoAAAACAAQFAQACAwAAAAAOAAAABT/5fI8uHB+6P+xKwGpjIms/6oeMjjE2qz/pEgxnGDLz 29 | P/DdqkowbyU= 30 | 31 | --- 32 | 33 | WAoAAAACAAQFAQACAwAAAAAOAAAABMACemdQ6reXwADCZLMILSK/+37sMnSf97/nA41gF9wU 34 | 35 | 36 | --- 37 | 38 | WAoAAAACAAQFAQACAwAAAAAOAAAABD/lvtZhqfQWP+tl+nXWUrw/9LjvMOUXAEABA9yVDC5v 39 | 40 | 41 | -------------------------------------------------------------------------------- /inst/examples/data.toygroups.R: -------------------------------------------------------------------------------- 1 | \donttest{ 2 | if (require(ggplot2, quietly = TRUE)) { 3 | # Load the data 4 | 5 | data("toygroups", package = "inlabru") 6 | 7 | # The data set is a simulation of animal groups residing in a 1D space. Their 8 | # locations in x-space are sampled from a Cox process with intensity 9 | 10 | ggplot(toygroups$df.intensity) + 11 | geom_line(aes(x = x, y = g.lambda)) 12 | 13 | # Adding the simulated group locations to this plot we obtain 14 | 15 | ggplot(toygroups$df.intensity) + 16 | geom_line(aes(x = x, y = g.lambda)) + 17 | geom_point(data = toygroups$groups, aes(x, y = 0), pch = "|") 18 | 19 | # Each group has a size mark attached to it. 20 | # These group sizes are sampled from an exponential distribution 21 | # for which the rate parameter depends on the x-coordinate 22 | 23 | ggplot(toygroups$groups) + 24 | geom_point(aes(x = x, y = size)) 25 | 26 | ggplot(toygroups$df.rate) + 27 | geom_line(aes(x, rate)) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/issue_template.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report or feature request 3 | about: Describe a bug you've seen or make a case for a new feature 4 | --- 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | Brief description of the problem 19 | 20 | ```r 21 | # insert reprex here 22 | ``` 23 | -------------------------------------------------------------------------------- /.github/workflows/lint.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [devel, release/*, feature/*] 6 | pull_request: 7 | branches: [devel] 8 | 9 | name: lint 10 | 11 | jobs: 12 | lint: 13 | runs-on: ubuntu-latest 14 | env: 15 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 16 | steps: 17 | - uses: actions/checkout@v4 18 | 19 | - uses: r-lib/actions/setup-r@v2 20 | with: 21 | use-public-rspm: true 22 | extra-repositories: 'https://inla.r-inla-download.org/R/testing https://inlabru-org.r-universe.dev' 23 | 24 | - uses: r-lib/actions/setup-r-dependencies@v2 25 | with: 26 | extra-packages: any::lintr, local::. 27 | needs: lint 28 | 29 | - name: Lint 30 | run: lintr::lint_package() 31 | shell: Rscript {0} 32 | env: 33 | LINTR_ERROR_ON_LINT: true 34 | -------------------------------------------------------------------------------- /misc/obs.R: -------------------------------------------------------------------------------- 1 | method_classes <- function(f) { 2 | gsub( 3 | pattern = paste0("^", f, "\\.([^*]*)\\*?"), 4 | replacement = "\\1", 5 | x = format(utils::.S3methods(f)) 6 | ) 7 | } 8 | 9 | 10 | #' Observation model objects 11 | #' 12 | #' Construct an observation model object; new modular alternative to [like()] 13 | #' @param \dots Arguments passed on to submethods 14 | #' @export 15 | bru_obs <- function(...) { 16 | UseMethod("bru_obs") 17 | } 18 | 19 | #' @export 20 | #' @rdname bru_obs 21 | bru_obs.character <- function(x, ...) { 22 | proto_class <- paste0("proto_bru_obs_", x) 23 | if (proto_class %in% setdiff(method_classes("bru_obs"), "character")) { 24 | return(do.call(bru_obs, list(structure(list(), class = proto_class), ...))) 25 | } 26 | return(structure(list(model = x), class = c("bru_obs_character", "bru_obs"))) 27 | } 28 | 29 | #' @export 30 | #' @rdname bru_obs 31 | bru_obs.proto_bru_obs_cp <- function(x, E, ...) { 32 | return(structure(list(model = "possion", E = E), class = c("bru_obs_cp", "bru_obs"))) 33 | } 34 | -------------------------------------------------------------------------------- /man/bm_mesh_B.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mappers.R 3 | \name{bm_mesh_B} 4 | \alias{bm_mesh_B} 5 | \alias{bru_mapper_mesh_B} 6 | \title{Deprecated basis conversion mapper} 7 | \usage{ 8 | bm_mesh_B(mesh, B) 9 | 10 | bru_mapper_mesh_B(...) 11 | } 12 | \arguments{ 13 | \item{mesh}{Object supported by a \code{\link[=bru_mapper]{bru_mapper()}} method.} 14 | 15 | \item{B}{a square or tall basis conversion matrix} 16 | } 17 | \description{ 18 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} 19 | Old deprecated name for \code{\link[=bm_reparam]{bm_reparam()}} 20 | } 21 | \section{Functions}{ 22 | \itemize{ 23 | \item \code{bru_mapper_mesh_B()}: \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} 24 | Deprecated name for \code{bm_mesh_B} 25 | 26 | }} 27 | \keyword{internal} 28 | -------------------------------------------------------------------------------- /man/gg.matrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ggplot.R 3 | \name{gg.matrix} 4 | \alias{gg.matrix} 5 | \title{Geom for matrix} 6 | \usage{ 7 | \method{gg}{matrix}(data, mapping = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{data}{A \code{matrix} object.} 11 | 12 | \item{mapping}{a set of aesthetic mappings created by \code{aes}. These are passed 13 | on to \code{geom_tile}.} 14 | 15 | \item{\dots}{Arguments passed on to \code{geom_tile}.} 16 | } 17 | \value{ 18 | A \code{geom_tile} with reversed y scale. 19 | } 20 | \description{ 21 | Creates a tile geom for plotting a matrix 22 | } 23 | \details{ 24 | Requires the \code{ggplot2} package. 25 | } 26 | \examples{ 27 | if (require("ggplot2", quietly = TRUE)) { 28 | A <- matrix(runif(100), nrow = 10) 29 | ggplot() + 30 | gg(A) 31 | } 32 | } 33 | \seealso{ 34 | Other geomes for inla and inlabru predictions: 35 | \code{\link{gg}()}, 36 | \code{\link{gg.bru_prediction}()}, 37 | \code{\link{gg.data.frame}()} 38 | } 39 | \concept{geomes for inla and inlabru predictions} 40 | -------------------------------------------------------------------------------- /man/toypoints.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.toypoints.R 3 | \docType{data} 4 | \name{toypoints} 5 | \alias{toypoints} 6 | \title{Simulated 2D point process data} 7 | \format{ 8 | The data are a list that contains these elements: 9 | \describe{ 10 | \item{\code{points}}{An \code{sf} object of point locations and and \code{z} 11 | measurements} 12 | \item{\code{mesh}}{An \code{fm_mesh_2d} object} 13 | \item{\code{boundary}}{An \code{sf} polygon denting the region of interest} 14 | \item{\code{pred_locs}}{A \code{sf} object with prediction point locations} 15 | } 16 | } 17 | \usage{ 18 | data(toypoints) 19 | } 20 | \description{ 21 | This data set serves as an example for basic inlabru. 22 | } 23 | \examples{ 24 | if (require("ggplot2")) { 25 | ggplot() + 26 | fmesher::geom_fm(data = toypoints$mesh, alpha = 0) + 27 | geom_sf(data = toypoints$boundary, fill = "blue", alpha = 0.1) + 28 | geom_sf(data = toypoints$points, aes(color = z)) + 29 | scale_color_viridis_c() 30 | } 31 | } 32 | \keyword{datasets} 33 | -------------------------------------------------------------------------------- /tests/testthat/test-latent_clinear.R: -------------------------------------------------------------------------------- 1 | test_that("bru: clinear component", { 2 | skip_on_cran() 3 | local_bru_safe_inla() 4 | 5 | # Seed influences data as well as predict()! 6 | withr::local_seed(123) 7 | 8 | input.df <- data.frame(x = cos(1:100)) 9 | input.df <- within(input.df, y <- 5 + 2 * x + rnorm(100, mean = 0, sd = 0.1)) 10 | 11 | fit <- bru( 12 | y ~ myLin(main = x, model = "clinear", range = c(0, Inf)) + 13 | Intercept(1), 14 | family = "gaussian", 15 | data = input.df, 16 | options = list(bru_initial = list(myLin = 2)) 17 | ) 18 | 19 | expect_equal( 20 | fit$summary.random[["myLin"]][1, "mean"], 21 | 2.002517, 22 | tolerance = hitol 23 | ) 24 | expect_equal( 25 | fit$summary.random[["myLin"]][1, "sd"], 26 | 0.013, 27 | tolerance = hitol 28 | ) 29 | 30 | skip_if_not_installed("sn") 31 | pr <- predict( 32 | fit, 33 | data.frame(x = c(1, 2)), 34 | ~ myLin + 2, 35 | n.samples = 5, 36 | seed = 1L 37 | ) 38 | 39 | expect_equal(pr[, "mean"], c(4.0, 6.0), tolerance = midtol) 40 | }) 41 | -------------------------------------------------------------------------------- /inst/examples/generate.bru.R: -------------------------------------------------------------------------------- 1 | \donttest{ 2 | if (bru_safe_inla() && 3 | require("sn", quietly = TRUE)) { 4 | 5 | # Generate data for a simple linear model 6 | 7 | input.df <- data.frame(x = cos(1:10)) 8 | input.df <- within(input.df, y <- 5 + 2 * cos(1:10) + rnorm(10, mean = 0, sd = 0.1)) 9 | 10 | # Fit the model 11 | 12 | fit <- bru(y ~ xeff(main = x, model = "linear"), 13 | family = "gaussian", data = input.df 14 | ) 15 | summary(fit) 16 | 17 | # Generate samples for some predefined x 18 | 19 | df <- data.frame(x = seq(-4, 4, by = 0.1)) 20 | smp <- generate(fit, df, ~ xeff + Intercept, n.samples = 10) 21 | 22 | # Plot the resulting realizations 23 | 24 | plot(df$x, smp[, 1], type = "l") 25 | for (k in 2:ncol(smp)) points(df$x, smp[, k], type = "l") 26 | 27 | # We can also draw samples form the joint posterior 28 | 29 | df <- data.frame(x = 1) 30 | smp <- generate(fit, df, ~ data.frame(xeff, Intercept), n.samples = 10) 31 | smp[[1]] 32 | 33 | # ... and plot them 34 | if (require(ggplot2, quietly = TRUE)) { 35 | plot(do.call(rbind, smp)) 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /man/bru_make_stack.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/stack.R 3 | \name{bru_make_stack} 4 | \alias{bru_make_stack} 5 | \alias{bru_make_stack.bru_obs} 6 | \alias{bru_make_stack.bru_obs_list} 7 | \title{Build an inla data stack from linearisation information} 8 | \usage{ 9 | bru_make_stack(...) 10 | 11 | \method{bru_make_stack}{bru_obs}(lhood, lin, idx, ..., family_index = 1L) 12 | 13 | \method{bru_make_stack}{bru_obs_list}(lhoods, lin, idx, ...) 14 | } 15 | \arguments{ 16 | \item{\dots}{Arguments passed on to other methods} 17 | 18 | \item{lhood}{A \code{bru_obs} object} 19 | 20 | \item{lin}{Linearisation information 21 | \itemize{ 22 | \item For \code{.bru_obs}, a \code{bm_taylor} object 23 | \item For \code{.bru_obs_list}, a list of \code{bm_taylor} objects 24 | }} 25 | 26 | \item{idx}{Output from \code{\link[=bru_index.bru_model]{bru_index.bru_model()}}} 27 | 28 | \item{family_index}{integer specifying the family sequence index of the 29 | observation model} 30 | 31 | \item{lhoods}{A \code{bru_obs_list} object} 32 | } 33 | \description{ 34 | Combine linearisation for multiple likelihoods 35 | } 36 | \keyword{internal} 37 | -------------------------------------------------------------------------------- /man/bru_used_update.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/used.R 3 | \name{bru_used_update} 4 | \alias{bru_used_update} 5 | \alias{bru_used_update.bru_obs_list} 6 | \alias{bru_used_update.bru_obs} 7 | \alias{bru_used_update.bru_pred_expr} 8 | \alias{bru_used_update.bru_used} 9 | \title{Update used_component information objects} 10 | \usage{ 11 | bru_used_update(x, labels, ...) 12 | 13 | \method{bru_used_update}{bru_obs_list}(x, labels, ...) 14 | 15 | \method{bru_used_update}{bru_obs}(x, labels, ...) 16 | 17 | \method{bru_used_update}{bru_pred_expr}(x, labels, ...) 18 | 19 | \method{bru_used_update}{bru_used}(x, labels, ...) 20 | } 21 | \arguments{ 22 | \item{x}{Object to be updated} 23 | 24 | \item{labels}{character vector of component labels} 25 | 26 | \item{\dots}{Unused} 27 | } 28 | \value{ 29 | An updated version of \code{x} 30 | } 31 | \description{ 32 | Merge available component labels information with used components 33 | information. 34 | } 35 | \seealso{ 36 | Other bru_used: 37 | \code{\link{bru_used}()}, 38 | \code{\link{bru_used_vars}()}, 39 | \code{\link{new_bru_used}()} 40 | } 41 | \concept{bru_used} 42 | \keyword{internal} 43 | -------------------------------------------------------------------------------- /R/data.mrsea.R: -------------------------------------------------------------------------------- 1 | #' @name mrsea 2 | #' @title Marine renewables strategic environmental assessment 3 | #' @docType data 4 | #' @description Data imported from package MRSea, see 5 | #' 6 | #' 7 | #' @format A list of objects: 8 | #' \describe{ 9 | #' \item{`points`}{ A `sf` object containing the locations of 10 | #' XXXXX.} 11 | #' \item{`samplers`}{ A `sf` object containing the transect lines 12 | #' that were surveyed.} 13 | #' \item{`mesh`}{ An `fm_mesh_2d` object containing a Delaunay triangulation 14 | #' mesh (a type of discretization of continuous space) covering the survey 15 | #' region.} 16 | #' \item{`boundary`}{ An `sf` object defining the boundary polygon of the 17 | #' survey region.} 18 | #' \item{`covar`}{ An `sf` containing sea depth estimates.} 19 | #' } 20 | #' @source 21 | #' Library `MRSea`. 22 | #' 23 | #' @references 24 | #' 25 | #' NONE YET 26 | #' 27 | #' @examples 28 | #' if (require(ggplot2, quietly = TRUE)) { 29 | #' ggplot() + 30 | #' geom_fm(data = mrsea$mesh) + 31 | #' gg(mrsea$samplers) + 32 | #' gg(mrsea$points) + 33 | #' gg(mrsea$boundary) 34 | #' } 35 | "mrsea" 36 | -------------------------------------------------------------------------------- /man/bru_is_rowwise.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bru_is.R 3 | \name{bru_is_rowwise} 4 | \alias{bru_is_rowwise} 5 | \alias{bru_is_rowwise.bru_pred_expr} 6 | \alias{bru_is_rowwise.bru_obs} 7 | \alias{bru_is_rowwise.bru_obs_list} 8 | \alias{bru_is_rowwise.bru_comp_list} 9 | \alias{bru_is_rowwise.bru_comp} 10 | \alias{bru_is_rowwise.bru_mapper} 11 | \title{Check for predictor rowwise evaluability} 12 | \usage{ 13 | bru_is_rowwise(x, ...) 14 | 15 | \method{bru_is_rowwise}{bru_pred_expr}(x, ...) 16 | 17 | \method{bru_is_rowwise}{bru_obs}(x, ...) 18 | 19 | \method{bru_is_rowwise}{bru_obs_list}(x, ...) 20 | 21 | \method{bru_is_rowwise}{bru_comp_list}(x, ...) 22 | 23 | \method{bru_is_rowwise}{bru_comp}(x, ...) 24 | 25 | \method{bru_is_rowwise}{bru_mapper}(x, ...) 26 | } 27 | \arguments{ 28 | \item{x}{An object containing a predictor definition} 29 | 30 | \item{\dots}{Arguments passed on to submethods.} 31 | } 32 | \value{ 33 | \code{TRUE} if the expression is believed to be rowwise, \code{FALSE} 34 | otherwise. 35 | } 36 | \description{ 37 | Checks if a predictor expression may be evaluated rowwise 38 | } 39 | \examples{ 40 | bru_is_rowwise(new_bru_pred_expr(~ x + y)) 41 | 42 | } 43 | -------------------------------------------------------------------------------- /man/bru_inla.stack.mexpand.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/inla.R 3 | \name{bru_inla.stack.mexpand} 4 | \alias{bru_inla.stack.mexpand} 5 | \title{Backwards compatibility to handle mexpand for INLA <= 24.06.02} 6 | \usage{ 7 | bru_inla.stack.mexpand( 8 | ..., 9 | old.names = "BRU.response", 10 | new.name = "BRU.response" 11 | ) 12 | } 13 | \arguments{ 14 | \item{\dots}{List of stacks that contain vector observations (existing 15 | multilikelihood observation matrices are also permitted)} 16 | 17 | \item{old.names}{A vector of strings with the names of the observation 18 | vector/matrix for each stack. If a single string, this is assumed for all 19 | the stacks. (default "BRU.response")} 20 | 21 | \item{new.name}{The name to be used for the expanded observation matrix, 22 | possibly the same as an old name. (default "BRU.response")} 23 | } 24 | \value{ 25 | a list of modified stacks with multicolumn observations 26 | } 27 | \description{ 28 | Expand observation vectors/matrices in stacks into to a multicolumn matrix 29 | for multiple likelihoods 30 | } 31 | \author{ 32 | Fabian E. Bachl \email{f.e.bachl@bath.ac.uk} and Finn Lindgren 33 | \email{finn.lindgren@gmail.com} 34 | } 35 | \keyword{internal} 36 | -------------------------------------------------------------------------------- /tests/testthat/test-additive.R: -------------------------------------------------------------------------------- 1 | test_that("Additivity: Additive predictor with nonlinear components", { 2 | skip_on_cran() 3 | local_bru_safe_inla() 4 | 5 | withr::local_seed(12345L) 6 | 7 | df <- tibble::tibble( 8 | u = 2, 9 | x = qexp(pnorm(u)), 10 | y = rpois(10, exp(x)) 11 | ) 12 | 13 | # Linear 14 | cmp <- ~ x(1, mean.linear = 0, prec.linear = 1) + 0 15 | form <- y ~ x 16 | fit <- bru( 17 | components = cmp, 18 | bru_obs( 19 | formula = form, 20 | family = "poisson", 21 | data = df 22 | ) 23 | ) 24 | 25 | # The latent variable should match x 26 | expect_equal( 27 | fit$summary.fixed["x", "mean"], 28 | 3.821398, 29 | tolerance = midtol 30 | ) 31 | 32 | # Nonlinear 33 | cmp <- ~ x( 34 | 1, 35 | mean.linear = 0, 36 | prec.linear = 1, 37 | marginal = bm_marginal(qexp, pexp, dexp, rate = 1) 38 | ) + 0 39 | form <- y ~ x 40 | fit <- bru( 41 | components = cmp, 42 | bru_obs( 43 | formula = form, 44 | family = "poisson", 45 | data = df 46 | ) 47 | ) 48 | 49 | # The latent variable should match u 50 | expect_equal( 51 | fit$summary.fixed["x", "mean"], 52 | 2.007725, 53 | tolerance = midtol 54 | ) 55 | }) 56 | -------------------------------------------------------------------------------- /misc/data.seals.R: -------------------------------------------------------------------------------- 1 | #' @name seals_sf 2 | #' @title Seal pups 3 | #' @docType data 4 | #' @description This is a single transect of an aereal photo seal pup survey in the Greenland Sea 5 | #' 6 | #' @usage data(seals_sf) 7 | #' 8 | #' @format The data contain these objects: 9 | #' \describe{ 10 | #' \item{`points`:}{ An `sf` object with center locations of the photos} 11 | #' \item{`mesh`:}{ An `fm_mesh_2d` enclosing the plane's transect} 12 | #' \item{`ice.data`:}{ An `sf` with MODIS ice concentration estimates} 13 | #' \item{`ice.cv`:}{ An `covdata` object with interpolated ice coverage data} 14 | #' } 15 | #' @source 16 | #' Martin Jullum \email{Martin.Jullum@@nr.no} 17 | #' 18 | #' @references 19 | #' Oigard, T. A. (2013) From pup production to quotas: current status of harp seals in the Greenland Sea. 20 | #' ICES Journal of Marine Science, doi.10.1093/icesjms/fst155. 21 | #' 22 | #' Oigard, T. A. (2014) Current status of hooded seals in the Greenland Sea. Victims of climate change and predation?, 23 | #' Biological Conservation , 2014, 172, 29 - 36. 24 | #' 25 | #' @examples 26 | #' if (require(ggplot2, quietly = TRUE)) { 27 | #' ggplot() + 28 | #' geom_fm(data = seals_sf$mesh) + 29 | #' gg(seals_sf$points) 30 | #' } 31 | "seals_sf" 32 | -------------------------------------------------------------------------------- /tests/testthat/test-latent_spde_1d.R: -------------------------------------------------------------------------------- 1 | latent_spde1D_testdata <- function() { 2 | local_bru_safe_inla() 3 | data(Poisson2_1D, package = "inlabru", envir = environment()) 4 | x <- seq(0, 55, length.out = 50) 5 | mesh1D <- fm_mesh_1d(x, boundary = "free") 6 | 7 | matern <- INLA::inla.spde2.pcmatern(mesh1D, 8 | prior.range = c(1, 0.01), 9 | prior.sigma = c(1, 0.01) 10 | ) 11 | 12 | cmp <- count ~ field(main = x, model = matern) + Intercept(1) 13 | # This model is sensitive to the integration strategy; "eb" is too smooth. 14 | fit <- bru(cmp, 15 | data = countdata2, family = "poisson", 16 | options = list( 17 | E = countdata2$exposure, 18 | control.inla = list(h = 0.005) 19 | ) 20 | ) 21 | 22 | list( 23 | data = countdata2, 24 | matern = matern, 25 | cmp = cmp, 26 | fit = fit 27 | ) 28 | } 29 | 30 | test_that("Latent models: SPDE 1D", { 31 | skip_on_cran() 32 | local_bru_safe_inla() 33 | data <- latent_spde1D_testdata() 34 | 35 | # Check Intercept + SPDE (highly negatively correlated) 36 | expect_snapshot_value( 37 | data$fit$summary.fixed["Intercept", "mean"] + 38 | data$fit$summary.random$field$mean[c(1, 25, 50)], 39 | tolerance = hitol, 40 | style = "serialize" 41 | ) 42 | }) 43 | -------------------------------------------------------------------------------- /man/mrsea.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.mrsea.R 3 | \docType{data} 4 | \name{mrsea} 5 | \alias{mrsea} 6 | \title{Marine renewables strategic environmental assessment} 7 | \format{ 8 | A list of objects: 9 | \describe{ 10 | \item{\code{points}}{ A \code{sf} object containing the locations of 11 | XXXXX.} 12 | \item{\code{samplers}}{ A \code{sf} object containing the transect lines 13 | that were surveyed.} 14 | \item{\code{mesh}}{ An \code{fm_mesh_2d} object containing a Delaunay triangulation 15 | mesh (a type of discretization of continuous space) covering the survey 16 | region.} 17 | \item{\code{boundary}}{ An \code{sf} object defining the boundary polygon of the 18 | survey region.} 19 | \item{\code{covar}}{ An \code{sf} containing sea depth estimates.} 20 | } 21 | } 22 | \source{ 23 | Library \code{MRSea}. 24 | } 25 | \usage{ 26 | mrsea 27 | } 28 | \description{ 29 | Data imported from package MRSea, see 30 | \url{https://www.creem.st-andrews.ac.uk/software/} 31 | } 32 | \examples{ 33 | if (require(ggplot2, quietly = TRUE)) { 34 | ggplot() + 35 | geom_fm(data = mrsea$mesh) + 36 | gg(mrsea$samplers) + 37 | gg(mrsea$points) + 38 | gg(mrsea$boundary) 39 | } 40 | } 41 | \references{ 42 | NONE YET 43 | } 44 | \keyword{datasets} 45 | -------------------------------------------------------------------------------- /man/gg.SpatRaster.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ggplot.R 3 | \name{gg.SpatRaster} 4 | \alias{gg.SpatRaster} 5 | \title{Geom wrapper for SpatRaster objects} 6 | \usage{ 7 | \method{gg}{SpatRaster}(data, ...) 8 | } 9 | \arguments{ 10 | \item{data}{A SpatRaster object.} 11 | 12 | \item{\dots}{Arguments passed on to \code{geom_spatraster}.} 13 | } 14 | \value{ 15 | The output from `geom_spatraster. 16 | } 17 | \description{ 18 | Convenience wrapper function for \code{tidyterra::geom_spatraster()}. 19 | Requires the \code{ggplot2} and \code{tidyterra} packages. 20 | } 21 | \examples{ 22 | if (require("ggplot2", quietly = TRUE) && 23 | requireNamespace("terra", quietly = TRUE) && 24 | require("tidyterra", quietly = TRUE)) { 25 | # Load Gorilla covariates 26 | 27 | gcov <- gorillas_sf_gcov() 28 | 29 | # Plot the pixel centers 30 | ggplot() + 31 | gg(gcov$elevation) 32 | } 33 | } 34 | \seealso{ 35 | Other geomes for spatial data: 36 | \code{\link{gg}()}, 37 | \code{\link{gg.SpatialGridDataFrame}()}, 38 | \code{\link{gg.SpatialLines}()}, 39 | \code{\link{gg.SpatialPixels}()}, 40 | \code{\link{gg.SpatialPixelsDataFrame}()}, 41 | \code{\link{gg.SpatialPoints}()}, 42 | \code{\link{gg.SpatialPolygons}()}, 43 | \code{\link{gg.sf}()} 44 | } 45 | \concept{geomes for spatial data} 46 | -------------------------------------------------------------------------------- /man/summary.bru_options.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/environment.R 3 | \name{summary.bru_options} 4 | \alias{summary.bru_options} 5 | \alias{print.summary_bru_options} 6 | \title{Print inlabru options} 7 | \usage{ 8 | \method{summary}{bru_options}( 9 | object, 10 | legend = TRUE, 11 | include_global = TRUE, 12 | include_default = TRUE, 13 | ... 14 | ) 15 | 16 | \method{print}{summary_bru_options}(x, ...) 17 | } 18 | \arguments{ 19 | \item{object}{A \link{bru_options} object to be summarised} 20 | 21 | \item{legend}{logical; If \code{TRUE}, include explanatory text, Default: \code{TRUE}} 22 | 23 | \item{include_global}{logical; If \code{TRUE}, include global override options} 24 | 25 | \item{include_default}{logical; If \code{TRUE}, include default options} 26 | 27 | \item{\dots}{Further parameters, currently ignored} 28 | 29 | \item{x}{A \code{summary_bru_options} object to be printed} 30 | } 31 | \description{ 32 | Print inlabru options 33 | } 34 | \examples{ 35 | if (interactive()) { 36 | options <- bru_options(verbose = TRUE) 37 | 38 | # Don't print options only set in default: 39 | print(options, include_default = FALSE) 40 | 41 | # Only include options set in the object: 42 | print(options, include_default = FALSE, include_global = FALSE) 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /man/bru_mapper_generics.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mappers.R 3 | \name{bru_mapper_generics} 4 | \alias{bru_mapper_generics} 5 | \title{Generic methods for bru_mapper objects} 6 | \description{ 7 | A \code{bru_mapper} sub-class implementation must provide an 8 | \code{\link[=ibm_jacobian]{ibm_jacobian()}} method. If the model size 'n' and definition 9 | values 'values' are stored in the object itself, default methods \code{\link[=ibm_n]{ibm_n()}} 10 | and \code{\link[=ibm_values]{ibm_values()}} are 11 | available. Otherwise the 12 | \code{\link[=ibm_n]{ibm_n()}} and \code{\link[=ibm_values]{ibm_values()}} methods also need to be provided. 13 | } 14 | \seealso{ 15 | \link{bru_mapper} for constructor methods, and 16 | \link{bru_get_mapper} for hooks to extract mappers from latent model object 17 | class objects. 18 | 19 | Other mapper methods: 20 | \code{\link{ibm_eval}()}, 21 | \code{\link{ibm_eval2}()}, 22 | \code{\link{ibm_inla_subset}()}, 23 | \code{\link{ibm_invalid_output}()}, 24 | \code{\link{ibm_is_linear}()}, 25 | \code{\link{ibm_is_rowwise}()}, 26 | \code{\link{ibm_jacobian}()}, 27 | \code{\link{ibm_linear}()}, 28 | \code{\link{ibm_n}()}, 29 | \code{\link{ibm_n_output}()}, 30 | \code{\link{ibm_names}()}, 31 | \code{\link{ibm_simplify}()}, 32 | \code{\link{ibm_values}()} 33 | } 34 | \concept{mapper methods} 35 | -------------------------------------------------------------------------------- /man/bru_obs_print.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bru.inference.R 3 | \name{summary.bru_obs} 4 | \alias{summary.bru_obs} 5 | \alias{summary.bru_obs_list} 6 | \alias{print.summary_bru_obs} 7 | \alias{print.summary_bru_obs_list} 8 | \alias{print.bru_obs} 9 | \alias{print.bru_obs_list} 10 | \title{Summary and print methods for observation models} 11 | \usage{ 12 | \method{summary}{bru_obs}(object, verbose = TRUE, ...) 13 | 14 | \method{summary}{bru_obs_list}(object, verbose = TRUE, ...) 15 | 16 | \method{print}{summary_bru_obs}(x, ...) 17 | 18 | \method{print}{summary_bru_obs_list}(x, ...) 19 | 20 | \method{print}{bru_obs}(x, ...) 21 | 22 | \method{print}{bru_obs_list}(x, ...) 23 | } 24 | \arguments{ 25 | \item{object}{Object to operate on} 26 | 27 | \item{verbose}{logical; If \code{TRUE}, include more details of the 28 | component definitions. If \code{FALSE}, only show basic component 29 | definition information. Default: \code{TRUE}} 30 | 31 | \item{\dots}{Arguments passed on to other \code{summary} methods} 32 | 33 | \item{x}{Object to be printed} 34 | } 35 | \description{ 36 | Summary and print methods for observation models 37 | } 38 | \examples{ 39 | obs <- bru_obs(y ~ ., data = data.frame(y = rnorm(10))) 40 | summary(obs) 41 | print(obs) 42 | 43 | } 44 | \seealso{ 45 | \code{\link[=bru_obs]{bru_obs()}} 46 | } 47 | -------------------------------------------------------------------------------- /man/cv_hex.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/hexagon_tiling.R 3 | \name{cv_hex} 4 | \alias{cv_hex} 5 | \title{Hexagon tiling of region} 6 | \usage{ 7 | cv_hex(samplers, cellsize = 0.5, n_group = 3, ...) 8 | } 9 | \arguments{ 10 | \item{samplers}{A sf object containing region for which 11 | partitions to be created} 12 | 13 | \item{cellsize}{hexagon cellsize, see \code{\link[sf:st_make_grid]{sf::st_make_grid()}} description} 14 | 15 | \item{n_group}{number of cv folds} 16 | 17 | \item{\dots}{Passed on to \code{fm_nonconvex_hull()}, e.g. \code{resolution} 18 | Output:} 19 | } 20 | \value{ 21 | a partitioned sf object as required 22 | } 23 | \description{ 24 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} Both the interface and function name 25 | may change in future versions. 26 | 27 | Partitions the region based on the hexagon tiling 28 | 29 | Input: 30 | } 31 | \examples{ 32 | if (interactive()) { 33 | bnd <- gorillas_sf$boundary 34 | hex_cv <- cv_hex(bnd, cellsize = 0.5, n_group = 3, resolution = 100) 35 | plot(hex_cv) 36 | 37 | chess <- cv_partition(bnd, resolution = 0.5, chess = TRUE) 38 | plot(chess$white) 39 | } 40 | 41 | } 42 | \author{ 43 | Man Ho Suen 44 | } 45 | \keyword{internal} 46 | -------------------------------------------------------------------------------- /man/figures/lifecycle-defunct.svg: -------------------------------------------------------------------------------- 1 | 2 | lifecycle: defunct 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | lifecycle 18 | 19 | defunct 20 | 21 | 22 | -------------------------------------------------------------------------------- /man/figures/lifecycle-archived.svg: -------------------------------------------------------------------------------- 1 | 2 | lifecycle: archived 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | lifecycle 18 | 19 | archived 20 | 21 | 22 | -------------------------------------------------------------------------------- /man/figures/lifecycle-maturing.svg: -------------------------------------------------------------------------------- 1 | 2 | lifecycle: maturing 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | lifecycle 18 | 19 | maturing 20 | 21 | 22 | -------------------------------------------------------------------------------- /man/summary.bru_input.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bru_input.R 3 | \name{format.bru_input} 4 | \alias{format.bru_input} 5 | \alias{summary.bru_input} 6 | \alias{print.bru_input} 7 | \title{Summarise component inputs} 8 | \usage{ 9 | \method{format}{bru_input}(x, verbose = TRUE, ..., label.override = NULL, type = NULL) 10 | 11 | \method{summary}{bru_input}(object, verbose = TRUE, ..., label.override = NULL) 12 | 13 | \method{print}{bru_input}(x, verbose = TRUE, ..., label.override = NULL) 14 | } 15 | \arguments{ 16 | \item{x}{Object to be printed} 17 | 18 | \item{verbose}{logical; If \code{TRUE}, includes more details of the 19 | component definitions. When \code{FALSE}, only show basic component 20 | definition information. Default \code{TRUE}.} 21 | 22 | \item{\dots}{Passed on to other summary methods.} 23 | 24 | \item{label.override}{character; If not \code{NULL}, use this label instead of 25 | the object's label.} 26 | 27 | \item{type}{character; if non-NULL, added to the output'; \code{label = type(input)}.} 28 | 29 | \item{object}{Object to be summarised.} 30 | } 31 | \description{ 32 | Summarise component inputs 33 | } 34 | \seealso{ 35 | \code{\link[=bru_input]{bru_input()}}, \code{\link[=bru_comp]{bru_comp()}} 36 | } 37 | \author{ 38 | Fabian E. Bachl \email{bachlfab@gmail.com} 39 | 40 | Finn Lindgren \email{finn.lindgren@gmail.com} 41 | } 42 | -------------------------------------------------------------------------------- /man/bru_inla.stack.mjoin.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/inla.R 3 | \name{bru_inla.stack.mjoin} 4 | \alias{bru_inla.stack.mjoin} 5 | \title{Join stacks intended to be run with different likelihoods} 6 | \usage{ 7 | bru_inla.stack.mjoin( 8 | ..., 9 | compress = TRUE, 10 | remove.unused = TRUE, 11 | old.names = "BRU.response", 12 | new.name = "BRU.response" 13 | ) 14 | } 15 | \arguments{ 16 | \item{\dots}{List of stacks that contain vector observations (existing 17 | multi-likelihood observation matrices are also permitted)} 18 | 19 | \item{compress}{If \code{TRUE}, compress the model by removing duplicated rows of 20 | effects, replacing the corresponding A-matrix columns with a single column 21 | containing the sum.} 22 | 23 | \item{remove.unused}{If \code{TRUE}, compress the model by removing rows of 24 | effects corresponding to all-zero columns in the A matrix (and removing 25 | those columns).} 26 | 27 | \item{old.names}{A vector of strings with the names of the observation 28 | vector/matrix for each stack. If a single string, this is assumed for all 29 | the stacks. (default "BRU.response")} 30 | 31 | \item{new.name}{The name to be used for the expanded observation matrix, 32 | possibly the same as an old name. (default "BRU.response")} 33 | } 34 | \description{ 35 | Helper functions for multi-likelihood models 36 | } 37 | \keyword{internal} 38 | -------------------------------------------------------------------------------- /man/cv_partition.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/hexagon_tiling.R 3 | \name{cv_partition} 4 | \alias{cv_partition} 5 | \title{Grid partitioning} 6 | \usage{ 7 | cv_partition( 8 | samplers, 9 | resolution = NULL, 10 | nrows = NULL, 11 | ncols = NULL, 12 | chess = TRUE, 13 | ... 14 | ) 15 | } 16 | \arguments{ 17 | \item{samplers}{A sf object containing region for which 18 | partitions to be created} 19 | 20 | \item{resolution}{resolution of the grids that are required} 21 | 22 | \item{nrows}{number of rows of grids that are required} 23 | 24 | \item{ncols}{number of columns of grids that are required} 25 | 26 | \item{chess}{chessboard partitioning} 27 | 28 | \item{\dots}{Unused.} 29 | } 30 | \value{ 31 | a partitioned sf object as required or a list of partitioned sf 32 | objects if chess is TRUE 33 | } 34 | \description{ 35 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} Both the interface and function name 36 | may change in future versions. 37 | 38 | Partitions the region based on the given criteria for calculating residuals 39 | in each partition. Parts of this function are taken from concepts in 40 | https://rpubs.com/huanfaChen/grid_from_polygon 41 | } 42 | \author{ 43 | Man Ho Suen 44 | } 45 | \keyword{internal} 46 | -------------------------------------------------------------------------------- /man/figures/lifecycle-deprecated.svg: -------------------------------------------------------------------------------- 1 | 2 | lifecycle: deprecated 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | lifecycle 18 | 19 | deprecated 20 | 21 | 22 | -------------------------------------------------------------------------------- /man/figures/lifecycle-superseded.svg: -------------------------------------------------------------------------------- 1 | 2 | lifecycle: superseded 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | lifecycle 18 | 19 | superseded 20 | 21 | 22 | -------------------------------------------------------------------------------- /man/figures/lifecycle-questioning.svg: -------------------------------------------------------------------------------- 1 | 2 | lifecycle: questioning 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | lifecycle 18 | 19 | questioning 20 | 21 | 22 | -------------------------------------------------------------------------------- /man/bru_is_additive.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bru_is.R 3 | \name{bru_is_additive} 4 | \alias{bru_is_additive} 5 | \alias{bru_is_additive.character} 6 | \alias{bru_is_additive.expression} 7 | \alias{bru_is_additive.formula} 8 | \alias{bru_is_additive.bru_pred_expr} 9 | \alias{bru_is_additive.bru_obs} 10 | \alias{bru_is_additive.bru_obs_list} 11 | \title{Check for predictor expression additivity} 12 | \usage{ 13 | bru_is_additive(x, ...) 14 | 15 | \method{bru_is_additive}{character}(x, ..., verbose = FALSE) 16 | 17 | \method{bru_is_additive}{expression}(x, ..., verbose = FALSE) 18 | 19 | \method{bru_is_additive}{formula}(x, ..., verbose = FALSE) 20 | 21 | \method{bru_is_additive}{bru_pred_expr}(x, ...) 22 | 23 | \method{bru_is_additive}{bru_obs}(x, ...) 24 | 25 | \method{bru_is_additive}{bru_obs_list}(x, ...) 26 | } 27 | \arguments{ 28 | \item{x}{A predictor \code{expression}, \code{formula}, or parse information 29 | \code{data.frame}.} 30 | 31 | \item{\dots}{Arguments passed on recursively.} 32 | 33 | \item{verbose}{logical; if \code{TRUE}, print diagnostic parsing information.} 34 | } 35 | \value{ 36 | \code{TRUE} if the expression is detected to be additive, \code{FALSE} 37 | otherwise. 38 | } 39 | \description{ 40 | Checks if a predictor expression is additive or not 41 | } 42 | \examples{ 43 | bru_is_additive(~ x + y) 44 | bru_is_additive(~ x * y) 45 | 46 | } 47 | -------------------------------------------------------------------------------- /man/figures/lifecycle-experimental.svg: -------------------------------------------------------------------------------- 1 | 2 | lifecycle: experimental 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | lifecycle 18 | 19 | experimental 20 | 21 | 22 | -------------------------------------------------------------------------------- /man/bm_fm_mesh_old.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mappers.R 3 | \name{bm_fm_mesh_old} 4 | \alias{bm_fm_mesh_old} 5 | \alias{ibm_n.bm_fm_mesh_2d} 6 | \alias{ibm_values.bm_fm_mesh_2d} 7 | \alias{ibm_jacobian.bm_fm_mesh_2d} 8 | \alias{ibm_n.bm_inla_mesh_2d} 9 | \alias{ibm_values.bm_inla_mesh_2d} 10 | \alias{ibm_jacobian.bm_inla_mesh_2d} 11 | \alias{ibm_n.bm_inla_mesh_1d} 12 | \alias{ibm_values.bm_inla_mesh_1d} 13 | \alias{ibm_jacobian.bm_inla_mesh_1d} 14 | \title{Deprecated methods} 15 | \usage{ 16 | \method{ibm_n}{bm_fm_mesh_2d}(mapper, ...) 17 | 18 | \method{ibm_values}{bm_fm_mesh_2d}(mapper, ...) 19 | 20 | \method{ibm_jacobian}{bm_fm_mesh_2d}(mapper, input, ...) 21 | 22 | \method{ibm_n}{bm_inla_mesh_2d}(mapper, ...) 23 | 24 | \method{ibm_values}{bm_inla_mesh_2d}(mapper, ...) 25 | 26 | \method{ibm_jacobian}{bm_inla_mesh_2d}(mapper, input, ...) 27 | 28 | \method{ibm_n}{bm_inla_mesh_1d}(mapper, ...) 29 | 30 | \method{ibm_values}{bm_inla_mesh_1d}(mapper, ...) 31 | 32 | \method{ibm_jacobian}{bm_inla_mesh_1d}(mapper, input, ...) 33 | } 34 | \description{ 35 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} 36 | Deprecated methods only used for old stored 37 | \code{bru_mapper_fm_mesh_1d} and \code{bru_mapper_fm_mesh_2d} objects. 38 | } 39 | \keyword{internal} 40 | -------------------------------------------------------------------------------- /man/bm_list.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mappers.R 3 | \name{bm_list} 4 | \alias{bm_list} 5 | \alias{as_bm_list} 6 | \alias{as_bm_list.list} 7 | \alias{as_bm_list.bm_list} 8 | \alias{as_bm_list.bru_comp_list} 9 | \alias{c.bru_mapper} 10 | \alias{c.bm_list} 11 | \alias{[.bm_list} 12 | \title{Methods for mapper lists} 13 | \usage{ 14 | as_bm_list(x) 15 | 16 | \method{as_bm_list}{list}(x) 17 | 18 | \method{as_bm_list}{bm_list}(x) 19 | 20 | \method{as_bm_list}{bru_comp_list}(x) 21 | 22 | \method{c}{bru_mapper}(...) 23 | 24 | \method{c}{bm_list}(...) 25 | 26 | \method{[}{bm_list}(x, i) 27 | } 28 | \arguments{ 29 | \item{x}{\code{bm_list} object from which to extract element(s)} 30 | 31 | \item{\dots}{Objects to be combined.} 32 | 33 | \item{i}{indices specifying elements to extract} 34 | } 35 | \value{ 36 | A \code{bm_list} object 37 | } 38 | \description{ 39 | \code{bru_mapper} lists can be combined into \code{bm_list} lists. 40 | } 41 | \section{Methods (by generic)}{ 42 | \itemize{ 43 | \item \code{c(bm_list)}: The \code{...} arguments should be \code{bm_list} 44 | objects. 45 | 46 | \item \code{[}: Extract sub-list 47 | 48 | }} 49 | \section{Functions}{ 50 | \itemize{ 51 | \item \code{c(bru_mapper)}: The \code{...} arguments should be \code{bru_mapper} 52 | objects. 53 | 54 | }} 55 | \examples{ 56 | m <- c(A = bm_const(), B = bm_scale()) 57 | str(m) 58 | str(m[2]) 59 | } 60 | -------------------------------------------------------------------------------- /man/spatial.to.ppp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/spatstat.R 3 | \name{spatial.to.ppp} 4 | \alias{spatial.to.ppp} 5 | \title{Convert SpatialPoints and boundary polygon to spatstat ppp object} 6 | \usage{ 7 | spatial.to.ppp(points, samplers) 8 | } 9 | \arguments{ 10 | \item{points}{A \code{SpatialPoints[DataFrame]} object describing the point 11 | pattern.} 12 | 13 | \item{samplers}{A \code{SpatialPolygons[DataFrame]} object describing the 14 | observation window.} 15 | } 16 | \value{ 17 | A spatstat \code{spatstat} \code{ppp} object 18 | } 19 | \description{ 20 | Spatstat point pattern objects consist of points and an observation windows. 21 | This function uses a \code{SpatialPoints} object and a \code{SpatialPolygon} object to 22 | generate the points and the window. Lastly, the \code{ppp()} function is called to 23 | create the \code{ppp} object. 24 | } 25 | \examples{ 26 | \donttest{ 27 | if (require("spatstat.geom") && 28 | bru_safe_sp() && 29 | require("sp") && 30 | require("terra", quietly = TRUE) && 31 | require("sf", quietly = TRUE)) { 32 | # Load Gorilla data 33 | 34 | gorillas <- gorillas_sp() 35 | 36 | # Use nest locations and survey boundary to create a spatstat ppp object 37 | 38 | gp <- spatial.to.ppp(gorillas$nests, gorillas$boundary) 39 | class(gp) 40 | 41 | # Plot it 42 | 43 | plot(gp) 44 | } 45 | } 46 | 47 | } 48 | \keyword{internal} 49 | -------------------------------------------------------------------------------- /man/extract_property.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/inla.R 3 | \name{extract_property} 4 | \alias{extract_property} 5 | \title{Extract a summary property from all results of an inla result} 6 | \usage{ 7 | extract_property(result, property, internal_hyperpar = FALSE) 8 | } 9 | \arguments{ 10 | \item{result}{an \code{inla} result object with a \code{bru_info} element} 11 | 12 | \item{property}{character; "mean", "sd", "mode", or some other column 13 | identifier for inla result \verb{$summary.fixed}, \verb{$summary.random$label}, and 14 | \verb{$summary.hyperpar}, or "joint_mode". For "joint_mode", the joint latent mode 15 | is extracted, and the joint hyperparameter mode, in the internal scale. 16 | For "predictor_sd" the posterior standard deviations of the linear predictor 17 | are returned.} 18 | 19 | \item{internal_hyperpar}{logical; if \code{TRUE}, use internal scale for 20 | hyperparamter properties. Default is \code{FALSE}, except when \code{property} is 21 | "joint_mode" which forces \code{internal_hyperpar=TRUE}.} 22 | } 23 | \value{ 24 | named list for each estimated fixed effect coefficient, 25 | random effect vector, and hyperparameter. The hyperparameter names are 26 | standardised with \code{\link[=bru_standardise_names]{bru_standardise_names()}} 27 | } 28 | \description{ 29 | Extract a summary property from all results of an inla result 30 | } 31 | \keyword{internal} 32 | -------------------------------------------------------------------------------- /tests/testthat/test-offset.R: -------------------------------------------------------------------------------- 1 | test_that("Linear predictor offset", { 2 | skip_on_cran() 3 | local_bru_safe_inla() 4 | 5 | dat <- data.frame( 6 | id = c(1:8), 7 | deaths = c(5, 30, 2, 4, 5, 4, 7, 10), 8 | pop = c(1000, 2300, 300, 400, 500, 700, 1000, 700) 9 | ) 10 | 11 | # Used to fail 12 | m1 <- bru( 13 | deaths ~ 1 + myoffset(log(pop), model = "offset"), 14 | data = dat, 15 | family = "poisson" 16 | ) 17 | m2 <- bru( 18 | ~ 1 + myoffset(log(pop), model = "offset"), 19 | formula = deaths ~ Intercept + myoffset, 20 | data = dat, 21 | family = "poisson" 22 | ) 23 | 24 | expect_equal( 25 | m1$summary.fixed$mean, 26 | m2$summary.fixed$mean, 27 | ignore_attr = TRUE, 28 | tolerance = lowtol 29 | ) 30 | expect_equal( 31 | m1$summary.fixed$sd, 32 | m2$summary.fixed$sd, 33 | ignore_attr = TRUE, 34 | tolerance = midtol 35 | ) 36 | 37 | # Give an error if an 'offset' option is specified. 38 | # Note the since 2.11.1.9013 there is no need to make the have the full 39 | # predictor length for a non-linear model. 40 | expect_error( 41 | { 42 | m3 <- bru( 43 | ~ Intercept(1), 44 | formula = deaths ~ Intercept, 45 | data = dat, 46 | family = "poisson", 47 | options = list(offset = log(dat$pop)) 48 | ) 49 | }, 50 | "An offset option was specified which may interfere" 51 | ) 52 | }) 53 | -------------------------------------------------------------------------------- /man/figures/lifecycle-soft-deprecated.svg: -------------------------------------------------------------------------------- 1 | 2 | lifecycle: soft-deprecated 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | lifecycle 18 | 19 | soft-deprecated 20 | 21 | 22 | -------------------------------------------------------------------------------- /R/data.shrimp.R: -------------------------------------------------------------------------------- 1 | #' @name shrimp 2 | #' @title Blue and red shrimp in the Western Mediterranean Sea 3 | #' @docType data 4 | #' @description Blue and red shrimp in the Western Mediterranean Sea. 5 | #' 6 | #' @usage data(shrimp) 7 | #' 8 | #' @format A list of objects: 9 | #' \describe{ 10 | #' \item{`hauls`:}{ An `sf` object containing haul locations} 11 | #' \item{`mesh`:}{ An `fm_mesh_2d` object containing a Delaunay triangulation 12 | #' mesh (a type of discretization of continuous space) covering the haul 13 | #' locations.} 14 | #' \describe{ 15 | #' \item{`catch`}{Catch in Kg.} 16 | #' \item{`landing`}{Landing in Kg.} 17 | #' \item{`depth`}{Mean depth (in metres) of the fishery haul.} 18 | #' } 19 | #' } 20 | #' @source 21 | #' Pennino, Maria Grazia. Personal communication. 22 | #' 23 | #' @references 24 | #' Pennino, M. G., Paradinas, I., Munoz, F., Illian, J.,Quilez-Lopez, A., 25 | #' Bellido, J.M., Conesa, D. Accounting for preferential sampling in species 26 | #' distribution models. Ecology and Evolution, 9(1), p653-663, 2019 27 | #' \doi{10.1002/ece3.4789} 28 | #' 29 | #' @examples 30 | #' \donttest{ 31 | #' if (require(ggplot2, quietly = TRUE)) { 32 | #' data(shrimp, package = "inlabru", envir = environment()) 33 | #' ggplot() + 34 | #' geom_fm(data = shrimp$mesh) + 35 | #' gg(shrimp$hauls, aes(col = catch)) + 36 | #' coord_sf(datum = fm_crs(shrimp$hauls)) 37 | #' } 38 | #' } 39 | "shrimp" 40 | -------------------------------------------------------------------------------- /man/figures/lifecycle-stable.svg: -------------------------------------------------------------------------------- 1 | 2 | lifecycle: stable 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 19 | 20 | lifecycle 21 | 22 | 25 | 26 | stable 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /man/bm_const.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mappers.R 3 | \name{bm_const} 4 | \alias{bm_const} 5 | \alias{bru_mapper_const} 6 | \title{Constant mapper} 7 | \usage{ 8 | bm_const() 9 | 10 | bru_mapper_const() 11 | } 12 | \description{ 13 | Create a constant mapper 14 | } 15 | \examples{ 16 | m <- bm_const() 17 | ibm_eval2(m, input = 1:4) 18 | 19 | } 20 | \seealso{ 21 | \link{bru_mapper}, \link{bru_mapper_generics} 22 | 23 | Other mappers: 24 | \code{\link{bm_aggregate}()}, 25 | \code{\link{bm_collect}()}, 26 | \code{\link{bm_factor}()}, 27 | \code{\link{bm_fm_mesh_1d}}, 28 | \code{\link{bm_fmesher}()}, 29 | \code{\link{bm_harmonics}()}, 30 | \code{\link{bm_index}()}, 31 | \code{\link{bm_linear}()}, 32 | \code{\link{bm_logitaverage}()}, 33 | \code{\link{bm_logsumexp}()}, 34 | \code{\link{bm_marginal}()}, 35 | \code{\link{bm_matrix}()}, 36 | \code{\link{bm_multi}()}, 37 | \code{\link{bm_pipe}()}, 38 | \code{\link{bm_reparam}()}, 39 | \code{\link{bm_repeat}()}, 40 | \code{\link{bm_scale}()}, 41 | \code{\link{bm_shift}()}, 42 | \code{\link{bm_sum}()}, 43 | \code{\link{bm_taylor}()}, 44 | \code{\link{bru_get_mapper}()}, 45 | \code{\link{bru_mapper}()} 46 | 47 | Other specific \link{bm_const} method implementations: 48 | \code{\link{ibm_eval}()}, 49 | \code{\link{ibm_jacobian}()}, 50 | \code{\link{ibm_n}()}, 51 | \code{\link{ibm_values}()} 52 | } 53 | \concept{mappers} 54 | \concept{specific \link{bm_const} method implementations} 55 | -------------------------------------------------------------------------------- /man/bru_safe_inla.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{bru_safe_inla} 4 | \alias{bru_safe_inla} 5 | \title{Load INLA safely for examples and tests} 6 | \usage{ 7 | bru_safe_inla(multicore = NULL, quietly = FALSE, minimum_version = "23.1.31") 8 | } 9 | \arguments{ 10 | \item{multicore}{logical; if \code{TRUE}, multiple cores are allowed, and the 11 | INLA \code{num.threads} option is not checked or altered. 12 | If \code{FALSE}, forces \code{num.threads="1:1"}. Default: NULL, checks 13 | if running in testthat or non-interactively, in which case sets 14 | \code{multicore=FALSE}, otherwise \code{TRUE}.} 15 | 16 | \item{quietly}{logical; if \code{FALSE} and \code{multicore} is \code{FALSE}, 17 | prints a message if the \code{num.threads} option 18 | isn't already "1.1" to alert the user to the change. 19 | Default: FALSE.} 20 | 21 | \item{minimum_version}{character; the minimum required INLA version. 22 | Default 23.1.31 (should always match the requirement in the package 23 | DESCRIPTION)} 24 | } 25 | \value{ 26 | logical; \code{TRUE} if INLA was loaded safely, otherwise FALSE 27 | } 28 | \description{ 29 | Loads the INLA package with \code{requireNamespace("INLA", quietly = TRUE)}, and 30 | optionally checks and sets the multicore \code{num.threads} INLA option. 31 | } 32 | \examples{ 33 | \dontrun{ 34 | if (bru_safe_inla()) { 35 | # Run inla dependent calculations 36 | } 37 | } 38 | 39 | } 40 | \keyword{internal} 41 | -------------------------------------------------------------------------------- /man/bm_linear.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mappers.R 3 | \name{bm_linear} 4 | \alias{bm_linear} 5 | \alias{bru_mapper_linear} 6 | \title{Mapper for a linear effect} 7 | \usage{ 8 | bm_linear() 9 | 10 | bru_mapper_linear() 11 | } 12 | \description{ 13 | Create a mapper for linear effects 14 | } 15 | \examples{ 16 | m <- bm_linear() 17 | ibm_eval(m, input = 1:4, state = 2) 18 | 19 | } 20 | \seealso{ 21 | \link{bru_mapper}, \link{bru_mapper_generics} 22 | 23 | Other mappers: 24 | \code{\link{bm_aggregate}()}, 25 | \code{\link{bm_collect}()}, 26 | \code{\link{bm_const}()}, 27 | \code{\link{bm_factor}()}, 28 | \code{\link{bm_fm_mesh_1d}}, 29 | \code{\link{bm_fmesher}()}, 30 | \code{\link{bm_harmonics}()}, 31 | \code{\link{bm_index}()}, 32 | \code{\link{bm_logitaverage}()}, 33 | \code{\link{bm_logsumexp}()}, 34 | \code{\link{bm_marginal}()}, 35 | \code{\link{bm_matrix}()}, 36 | \code{\link{bm_multi}()}, 37 | \code{\link{bm_pipe}()}, 38 | \code{\link{bm_reparam}()}, 39 | \code{\link{bm_repeat}()}, 40 | \code{\link{bm_scale}()}, 41 | \code{\link{bm_shift}()}, 42 | \code{\link{bm_sum}()}, 43 | \code{\link{bm_taylor}()}, 44 | \code{\link{bru_get_mapper}()}, 45 | \code{\link{bru_mapper}()} 46 | 47 | Other specific \link{bm_linear} method implementations: 48 | \code{\link{ibm_jacobian}()}, 49 | \code{\link{ibm_n}()}, 50 | \code{\link{ibm_values}()} 51 | } 52 | \concept{mappers} 53 | \concept{specific \link{bm_linear} method implementations} 54 | -------------------------------------------------------------------------------- /man/bru_safe_sp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{bru_safe_sp} 4 | \alias{bru_safe_sp} 5 | \title{Check for potential \code{sp} version compatibility issues} 6 | \usage{ 7 | bru_safe_sp(quietly = FALSE, force = FALSE, minimum_version = "1.4-5") 8 | } 9 | \arguments{ 10 | \item{quietly}{logical; if \code{TRUE}, prints diagnostic messages. Default 11 | \code{FALSE}} 12 | 13 | \item{force}{logical; If \code{rgdal} is unavailable 14 | and evolution status is less that \code{2L}, return \code{FALSE} if \code{force} is \code{FALSE}. 15 | If \code{force} is \code{TRUE}, return \code{TRUE} if the package configuration is safe, 16 | potentially after forcing the evolution status to \code{2L}. 17 | Default \code{FALSE}} 18 | 19 | \item{minimum_version}{character; the minimum required INLA version. 20 | Default 1.4-5 (should always match the requirement in the package 21 | DESCRIPTION)} 22 | } 23 | \value{ 24 | Returns (invisibly) \code{FALSE} if a potential issue is detected, and 25 | give a message if \code{quietly} is \code{FALSE}. Otherwise returns \code{TRUE} 26 | } 27 | \description{ 28 | Loads the sp package with \code{requireNamespace("sp", quietly = TRUE)}, and 29 | checks and optionally sets the \code{sp} evolution status flag if \code{rgdal} is 30 | unavailable. 31 | } 32 | \examples{ 33 | \dontrun{ 34 | if (bru_safe_sp() && 35 | require("sp")) { 36 | # Run sp dependent calculations 37 | } 38 | } 39 | 40 | } 41 | \keyword{internal} 42 | -------------------------------------------------------------------------------- /man/gg.SpatialPixels.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ggplot.R 3 | \name{gg.SpatialPixels} 4 | \alias{gg.SpatialPixels} 5 | \title{Geom for SpatialPixels objects} 6 | \usage{ 7 | \method{gg}{SpatialPixels}(data, ...) 8 | } 9 | \arguments{ 10 | \item{data}{A \code{sp::SpatialPixels} object.} 11 | 12 | \item{\dots}{Arguments passed on to \code{geom_tile}.} 13 | } 14 | \value{ 15 | A \code{geom_tile} return value. 16 | } 17 | \description{ 18 | Uses \code{geom_point} to plot the pixel centers. 19 | Requires the \code{ggplot2} package. 20 | } 21 | \examples{ 22 | if (require("ggplot2", quietly = TRUE) && 23 | requireNamespace("terra", quietly = TRUE) && 24 | bru_safe_sp()) { 25 | # Load Gorilla data 26 | 27 | gcov <- gorillas_sf_gcov() 28 | elev <- terra::as.data.frame(gcov$elevation, xy = TRUE) 29 | pxl <- sf::as_Spatial(sf::st_as_sf(elev, coords = c("x", "y"))) 30 | 31 | # Turn elevation covariate into SpatialPixels 32 | pxl <- sp::SpatialPixels(pxl) 33 | 34 | # Plot the pixel centers 35 | ggplot() + 36 | gg(pxl, size = 0.1) 37 | } 38 | } 39 | \seealso{ 40 | Other geomes for spatial data: 41 | \code{\link{gg}()}, 42 | \code{\link{gg.SpatRaster}()}, 43 | \code{\link{gg.SpatialGridDataFrame}()}, 44 | \code{\link{gg.SpatialLines}()}, 45 | \code{\link{gg.SpatialPixelsDataFrame}()}, 46 | \code{\link{gg.SpatialPoints}()}, 47 | \code{\link{gg.SpatialPolygons}()}, 48 | \code{\link{gg.sf}()} 49 | } 50 | \concept{geomes for spatial data} 51 | -------------------------------------------------------------------------------- /man/shrimp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.shrimp.R 3 | \docType{data} 4 | \name{shrimp} 5 | \alias{shrimp} 6 | \title{Blue and red shrimp in the Western Mediterranean Sea} 7 | \format{ 8 | A list of objects: 9 | \describe{ 10 | \item{\code{hauls}:}{ An \code{sf} object containing haul locations} 11 | \item{\code{mesh}:}{ An \code{fm_mesh_2d} object containing a Delaunay triangulation 12 | mesh (a type of discretization of continuous space) covering the haul 13 | locations.} 14 | \describe{ 15 | \item{\code{catch}}{Catch in Kg.} 16 | \item{\code{landing}}{Landing in Kg.} 17 | \item{\code{depth}}{Mean depth (in metres) of the fishery haul.} 18 | } 19 | } 20 | } 21 | \source{ 22 | Pennino, Maria Grazia. Personal communication. 23 | } 24 | \usage{ 25 | data(shrimp) 26 | } 27 | \description{ 28 | Blue and red shrimp in the Western Mediterranean Sea. 29 | } 30 | \examples{ 31 | \donttest{ 32 | if (require(ggplot2, quietly = TRUE)) { 33 | data(shrimp, package = "inlabru", envir = environment()) 34 | ggplot() + 35 | geom_fm(data = shrimp$mesh) + 36 | gg(shrimp$hauls, aes(col = catch)) + 37 | coord_sf(datum = fm_crs(shrimp$hauls)) 38 | } 39 | } 40 | } 41 | \references{ 42 | Pennino, M. G., Paradinas, I., Munoz, F., Illian, J.,Quilez-Lopez, A., 43 | Bellido, J.M., Conesa, D. Accounting for preferential sampling in species 44 | distribution models. Ecology and Evolution, 9(1), p653-663, 2019 45 | \doi{10.1002/ece3.4789} 46 | } 47 | \keyword{datasets} 48 | -------------------------------------------------------------------------------- /inst/examples/prediction.bru.R: -------------------------------------------------------------------------------- 1 | \donttest{ 2 | if (bru_safe_inla() && 3 | require(ggplot2, quietly = TRUE)) { 4 | 5 | # Generate some data 6 | input.df <- data.frame(x = cos(1:10)) 7 | input.df <- within(input.df, y <- 5 + 2 * cos(1:10) + rnorm(10, mean = 0, sd = 0.1)) 8 | 9 | # Fit a model with fixed effect 'x' and intercept 'Intercept' 10 | 11 | fit <- bru(y ~ x, family = "gaussian", data = input.df) 12 | 13 | # Predict posterior statistics of 'x' 14 | 15 | xpost <- predict(fit, formula = ~x) 16 | 17 | # The result is a data.frame inheriting from class 'prediction' 18 | 19 | class(xpost) 20 | 21 | # The statistics include mean, standard deviation, the 2.5% quantile, the median, 22 | # the 97.5% quantile, minimum and maximum sample drawn from the posterior as well as 23 | # the coefficient of variation and the variance. 24 | 25 | xpost 26 | 27 | # For a single variable like 'x' the default plotting method invoked by gg() will 28 | # show these statistics in a fashion similar to a box plot: 29 | 30 | ggplot() + 31 | gg(xpost) 32 | 33 | 34 | # The predict function can also be used to simultaneously estimate posteriors 35 | # of multiple variables: 36 | 37 | xipost <- predict(fit, formula = ~ data.frame(post = c(x, Intercept))) 38 | xipost 39 | 40 | # If we still want a plot in the previous style we have to set the 'bar' parameter to TRUE: 41 | 42 | rownames(xipost) <- c("x", "Intercept") 43 | ggplot() + 44 | gg(xipost, bar = TRUE) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /inst/examples/bru.R: -------------------------------------------------------------------------------- 1 | \donttest{ 2 | if (bru_safe_inla()) { 3 | # Simulate some covariates x and observations y 4 | input.df <- data.frame(x = cos(1:10)) 5 | input.df <- within(input.df, { 6 | y <- 5 + 2 * x + rnorm(10, mean = 0, sd = 0.1) 7 | }) 8 | 9 | # Fit a Gaussian likelihood model 10 | fit <- bru(y ~ x + Intercept(1), family = "gaussian", data = input.df) 11 | 12 | # Obtain summary 13 | fit$summary.fixed 14 | } 15 | 16 | 17 | if (bru_safe_inla()) { 18 | # Alternatively, we can use the bru_obs() function to construct the likelihood: 19 | 20 | lik <- bru_obs(family = "gaussian", 21 | formula = y ~ x + Intercept, 22 | data = input.df) 23 | fit <- bru(~ x + Intercept(1), lik) 24 | fit$summary.fixed 25 | } 26 | 27 | # An important addition to the INLA methodology is bru's ability to use 28 | # non-linear predictors. Such a predictor can be formulated via bru_obs()'s 29 | # \code{formula} parameter. The z(1) notation is needed to ensure that 30 | # the z component should be interpreted as single latent variable and not 31 | # a covariate: 32 | 33 | if (bru_safe_inla()) { 34 | z <- 2 35 | input.df <- within(input.df, { 36 | y <- 5 + exp(z) * x + rnorm(10, mean = 0, sd = 0.1) 37 | }) 38 | lik <- bru_obs( 39 | family = "gaussian", data = input.df, 40 | formula = y ~ exp(z) * x + Intercept 41 | ) 42 | fit <- bru(~ z(1) + Intercept(1), lik) 43 | 44 | # Check the result (z posterior should be around 2) 45 | fit$summary.fixed 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /data-raw/toygroups.R: -------------------------------------------------------------------------------- 1 | make.toygroups <- function() { 2 | set.seed(123) 3 | 4 | xx <- seq(-10, 10, length.out = 300) 5 | 6 | # Sample group locations 7 | mesh1D <- fm_mesh_1d(xx) 8 | g.lambda <- function(x) 60 * dnorm(0.2 * (x - 10)) + 20 9 | groups <- sample.lgcp(mesh1D, log(g.lambda(mesh1D$loc))) 10 | 11 | # Sample group size 12 | rate <- function(x) 1.5 * dnorm(0.1 * (x - 10)) 13 | gsize <- function(x) { 14 | rexp(length(x), rate = rate(x)) 15 | } 16 | groups$size <- gsize(groups$x) 17 | 18 | # Some data for easier plotting 19 | df.intensity <- data.frame(x = xx, g.lambda = g.lambda(xx)) 20 | df.rate <- data.frame(x = xx, rate = rate(xx)) 21 | sz <- seq(0, 50, length.out = 100) 22 | df.size <- data.frame(size = sz, dexp = dexp(sz, rate = 0.29)) 23 | 24 | ##### Binned data 25 | # breaks = seq(-10,10,length.out = 16) 26 | # groups$bin = findInterval(groups$x, breaks) 27 | # hst = hist(groups$x, breaks = breaks, plot = FALSE) 28 | # hst = data.frame( 29 | # bin = 1:(length(breaks)-1), 30 | # nanimals = 0, 31 | # ngroups = hst$counts 32 | # ) 33 | # agg = aggregate(groups$size, by = list(bin = groups$bin), sum) 34 | # hst$nanimals[agg$bin] = agg$x 35 | # hst$x = breaks[1:(length(breaks)-1)] 36 | 37 | toygroups <- list( 38 | groups = groups, 39 | df.rate = df.rate, 40 | df.size = df.size, 41 | df.intensity = df.intensity 42 | ) 43 | toygroups 44 | } 45 | 46 | # toygroups <- make.toygroups() 47 | # usethis::use_data(toygroups, overwrite = TRUE) 48 | -------------------------------------------------------------------------------- /man/bru_is_linear.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bru_is.R 3 | \name{bru_is_linear} 4 | \alias{bru_is_linear} 5 | \alias{bru_is_linear.bru} 6 | \alias{bru_is_linear.bru_info} 7 | \alias{bru_is_linear.bru_model} 8 | \alias{bru_is_linear.bru_obs} 9 | \alias{bru_is_linear.bru_obs_list} 10 | \alias{bru_is_linear.bru_pred_expr} 11 | \alias{bru_is_linear.bru_comp_list} 12 | \alias{bru_is_linear.bru_comp} 13 | \alias{bru_is_linear.bru_mapper} 14 | \title{Check for predictor linearity} 15 | \usage{ 16 | bru_is_linear(x, ...) 17 | 18 | \method{bru_is_linear}{bru}(x, ...) 19 | 20 | \method{bru_is_linear}{bru_info}(x, ...) 21 | 22 | \method{bru_is_linear}{bru_model}(x, ...) 23 | 24 | \method{bru_is_linear}{bru_obs}(x, ...) 25 | 26 | \method{bru_is_linear}{bru_obs_list}(x, ...) 27 | 28 | \method{bru_is_linear}{bru_pred_expr}(x, ...) 29 | 30 | \method{bru_is_linear}{bru_comp_list}(x, ...) 31 | 32 | \method{bru_is_linear}{bru_comp}(x, ...) 33 | 34 | \method{bru_is_linear}{bru_mapper}(x, ...) 35 | } 36 | \arguments{ 37 | \item{x}{A object containing a predictor definition} 38 | 39 | \item{\dots}{Arguments passed on recursively.} 40 | } 41 | \value{ 42 | \code{TRUE} if the expression is detected to be linear, \code{FALSE} 43 | otherwise. 44 | } 45 | \description{ 46 | Checks if a predictor expression is linear (or affine) 47 | } 48 | \examples{ 49 | bru_is_linear(new_bru_pred_expr(~ x + y)) 50 | bru_is_linear(new_bru_pred_expr(~ x * y)) 51 | bru_is_linear(bm_scale()) 52 | bru_is_linear(bm_logsumexp()) 53 | 54 | } 55 | -------------------------------------------------------------------------------- /man/ibm_is_rowwise.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mappers.R 3 | \name{ibm_is_rowwise} 4 | \alias{ibm_is_rowwise} 5 | \alias{ibm_is_rowwise.default} 6 | \title{Check if a mapper is rowwise} 7 | \usage{ 8 | ibm_is_rowwise(mapper, ...) 9 | 10 | \method{ibm_is_rowwise}{default}(mapper, ...) 11 | } 12 | \arguments{ 13 | \item{mapper}{A mapper S3 object, inheriting from \code{bru_mapper}.} 14 | 15 | \item{...}{Arguments passed on to other methods} 16 | } 17 | \description{ 18 | Implementations must return \code{TRUE} or \code{FALSE}. 19 | If \code{TRUE} (returned by the default method unless the mapper 20 | contains an \code{is_rowwise} variable), users of the mapper 21 | may assume the mapper uses its inputs in "rowwise" manner, so that 22 | blockwise evaluation is always possible. 23 | } 24 | \section{Methods (by class)}{ 25 | \itemize{ 26 | \item \code{ibm_is_rowwise(default)}: Returns logical 27 | \code{is_rowwise} from the mapper object if it exists, and otherwise \code{TRUE}. 28 | 29 | }} 30 | \seealso{ 31 | Other mapper methods: 32 | \code{\link{bru_mapper_generics}}, 33 | \code{\link{ibm_eval}()}, 34 | \code{\link{ibm_eval2}()}, 35 | \code{\link{ibm_inla_subset}()}, 36 | \code{\link{ibm_invalid_output}()}, 37 | \code{\link{ibm_is_linear}()}, 38 | \code{\link{ibm_jacobian}()}, 39 | \code{\link{ibm_linear}()}, 40 | \code{\link{ibm_n}()}, 41 | \code{\link{ibm_n_output}()}, 42 | \code{\link{ibm_names}()}, 43 | \code{\link{ibm_simplify}()}, 44 | \code{\link{ibm_values}()} 45 | } 46 | \concept{mapper methods} 47 | -------------------------------------------------------------------------------- /man/deltaIC.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/deltaIC.R 3 | \name{deltaIC} 4 | \alias{deltaIC} 5 | \title{Summarise DIC and WAIC from \code{lgcp} objects.} 6 | \usage{ 7 | deltaIC(..., criterion = "DIC") 8 | } 9 | \arguments{ 10 | \item{\dots}{Comma-separated objects inheriting from class \code{inla} and 11 | obtained from a run of \code{INLA::inla()}, \code{\link[=bru]{bru()}} or \code{\link[=lgcp]{lgcp()}}} 12 | 13 | \item{criterion}{character vector. 14 | If it includes 'DIC', computes DIC differences; 15 | If it contains 'WAIC', computes WAIC differences. Default: 'DIC'} 16 | } 17 | \value{ 18 | A data frame with each row containing the Model name, 19 | DIC and Delta.DIC, and/or WAIC and Delta.WAIC. 20 | } 21 | \description{ 22 | Calculates DIC and/or WAIC differences and produces an ordered summary. 23 | } 24 | \examples{ 25 | \donttest{ 26 | if (bru_safe_inla()) { 27 | # Generate some data 28 | input.df <- data.frame(idx = 1:10, x = cos(1:10)) 29 | input.df <- within( 30 | input.df, 31 | y <- rpois(10, 5 + 2 * cos(1:10) + rnorm(10, mean = 0, sd = 0.1)) 32 | ) 33 | 34 | # Fit two models 35 | fit1 <- bru( 36 | y ~ x, 37 | family = "poisson", 38 | data = input.df, 39 | options = list(control.compute = list(dic = TRUE)) 40 | ) 41 | fit2 <- bru( 42 | y ~ x + rand(idx, model = "iid"), 43 | family = "poisson", 44 | data = input.df, 45 | options = list(control.compute = list(dic = TRUE)) 46 | ) 47 | 48 | # Compare DIC 49 | 50 | deltaIC(fit1, fit2) 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /man/add_mappers.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/effect.R 3 | \name{add_mappers} 4 | \alias{add_mappers} 5 | \alias{add_mappers.bru_comp} 6 | \alias{add_mappers.bru_comp_list} 7 | \title{Add component input/latent mappers} 8 | \usage{ 9 | add_mappers(...) 10 | 11 | \method{add_mappers}{bru_comp}(component, lhoods, inputs = NULL, lh_data = NULL, ...) 12 | 13 | \method{add_mappers}{bru_comp_list}(components, lhoods, inputs = NULL, lh_data = NULL, ...) 14 | } 15 | \arguments{ 16 | \item{\dots}{Parameters passed on to other methods} 17 | 18 | \item{component}{A \link{component} object} 19 | 20 | \item{lhoods}{A \link{bru_obs_list} object} 21 | 22 | \item{inputs}{A precomputed list of inputs, as returned by 23 | \code{\link[=bru_input.bru_comp_list]{bru_input.bru_comp_list()}}} 24 | 25 | \item{lh_data}{A list of data object, one for each likelihood in \code{lhoods} 26 | that is used to determine the mapper(s). If \code{NULL}, the data is 27 | or inputs are used instead.} 28 | 29 | \item{components}{A \code{bru_comp_list} object} 30 | } 31 | \value{ 32 | A \code{component} object with completed mapper information 33 | } 34 | \description{ 35 | Add missing mappers between input data and latent variables, 36 | based on likelihood data 37 | 38 | Equip component(s) with mappers for subcomponents that do not 39 | have predefined mappers. When needed, the data in \code{lhoods} is used to 40 | determine the appropriate mapper(s). 41 | } 42 | \examples{ 43 | \dontrun{ 44 | if (interactive() && bru_safe_inla()) {} 45 | } 46 | } 47 | \keyword{internal} 48 | -------------------------------------------------------------------------------- /man/bm_index.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mappers.R 3 | \name{bm_index} 4 | \alias{bm_index} 5 | \alias{bru_mapper_index} 6 | \title{Mapper for indexed variables} 7 | \usage{ 8 | bm_index(n = 1L) 9 | 10 | bru_mapper_index(...) 11 | } 12 | \arguments{ 13 | \item{n}{Size of a model for \code{bm_index}} 14 | 15 | \item{\dots}{Arguments passed on to \code{\link[=bm_index]{bm_index()}}} 16 | } 17 | \description{ 18 | Create a an indexing mapper 19 | } 20 | \examples{ 21 | m <- bm_index(4) 22 | ibm_eval(m, -2:6, 1:4) 23 | } 24 | \seealso{ 25 | \link{bru_mapper}, \link{bru_mapper_generics} 26 | 27 | Other mappers: 28 | \code{\link{bm_aggregate}()}, 29 | \code{\link{bm_collect}()}, 30 | \code{\link{bm_const}()}, 31 | \code{\link{bm_factor}()}, 32 | \code{\link{bm_fm_mesh_1d}}, 33 | \code{\link{bm_fmesher}()}, 34 | \code{\link{bm_harmonics}()}, 35 | \code{\link{bm_linear}()}, 36 | \code{\link{bm_logitaverage}()}, 37 | \code{\link{bm_logsumexp}()}, 38 | \code{\link{bm_marginal}()}, 39 | \code{\link{bm_matrix}()}, 40 | \code{\link{bm_multi}()}, 41 | \code{\link{bm_pipe}()}, 42 | \code{\link{bm_reparam}()}, 43 | \code{\link{bm_repeat}()}, 44 | \code{\link{bm_scale}()}, 45 | \code{\link{bm_shift}()}, 46 | \code{\link{bm_sum}()}, 47 | \code{\link{bm_taylor}()}, 48 | \code{\link{bru_get_mapper}()}, 49 | \code{\link{bru_mapper}()} 50 | 51 | Other specific \link{bm_index} method implementations: 52 | \code{\link{ibm_invalid_output}()}, 53 | \code{\link{ibm_jacobian}()} 54 | } 55 | \concept{mappers} 56 | \concept{specific \link{bm_index} method implementations} 57 | -------------------------------------------------------------------------------- /man/gg.fm_mesh_1d.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ggplot.R 3 | \name{gg.fm_mesh_1d} 4 | \alias{gg.fm_mesh_1d} 5 | \title{Geom for fm_mesh_1d objects} 6 | \usage{ 7 | \method{gg}{fm_mesh_1d}( 8 | data, 9 | mapping = ggplot2::aes(.data[["x"]], .data[["y"]]), 10 | y = 0, 11 | shape = 4, 12 | ... 13 | ) 14 | } 15 | \arguments{ 16 | \item{data}{An \link[fmesher:fm_mesh_1d]{fmesher::fm_mesh_1d} object.} 17 | 18 | \item{mapping}{aesthetic mappings created by \code{aes}. These are passed on to 19 | \code{geom_point}.} 20 | 21 | \item{y}{Single or vector numeric defining the y-coordinates of the mesh 22 | knots to plot.} 23 | 24 | \item{shape}{Shape of the knot markers.} 25 | 26 | \item{\dots}{parameters passed on to \code{geom_point}.} 27 | } 28 | \value{ 29 | An object generated by \code{geom_point}. 30 | } 31 | \description{ 32 | This function generates a \code{geom_point} object showing the knots (vertices) 33 | of a 1D mesh. 34 | Requires the \code{ggplot2} package. 35 | } 36 | \examples{ 37 | \donttest{ 38 | if (require("fmesher", quietly = TRUE) && 39 | require("ggplot2", quietly = TRUE)) { 40 | # Create a 1D mesh 41 | 42 | mesh <- fm_mesh_1d(seq(0, 10, by = 0.5)) 43 | 44 | # Plot it 45 | 46 | ggplot() + 47 | gg(mesh) 48 | 49 | # Plot it using a different shape and size for the mesh nodes 50 | 51 | ggplot() + 52 | gg(mesh, shape = "|", size = 5) 53 | } 54 | } 55 | 56 | } 57 | \seealso{ 58 | Other geomes for meshes: 59 | \code{\link{gg}()}, 60 | \code{\link{gg.fm_mesh_2d}()} 61 | } 62 | \concept{geomes for meshes} 63 | -------------------------------------------------------------------------------- /man/gg.RasterLayer.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ggplot.R 3 | \name{gg.RasterLayer} 4 | \alias{gg.RasterLayer} 5 | \title{Geom for RasterLayer objects} 6 | \usage{ 7 | \method{gg}{RasterLayer}( 8 | data, 9 | mapping = ggplot2::aes(x = .data[["x"]], y = .data[["y"]], fill = .data[["layer"]]), 10 | ... 11 | ) 12 | } 13 | \arguments{ 14 | \item{data}{A RasterLayer object.} 15 | 16 | \item{mapping}{aesthetic mappings created by \code{aes}. These are passed on to 17 | \code{geom_tile}.} 18 | 19 | \item{\dots}{Arguments passed on to \code{geom_tile}.} 20 | } 21 | \value{ 22 | An object returned by \code{geom_tile} 23 | } 24 | \description{ 25 | This function takes a RasterLayer object, converts it into a 26 | \code{SpatialPixelsDataFrame} and uses \code{geom_tile} to plot the data. 27 | } 28 | \details{ 29 | This function requires the \code{raster} and \code{ggplot2} packages. 30 | } 31 | \examples{ 32 | \dontrun{ 33 | # Some features require the raster and spatstat.data packages. 34 | if (require("spatstat.data", quietly = TRUE) && 35 | require("raster", quietly = TRUE) && 36 | require("ggplot2", quietly = TRUE)) { 37 | # Load Gorilla data 38 | data("gorillas", package = "spatstat.data", envir = environment()) 39 | 40 | # Convert elevation covariate to RasterLayer 41 | 42 | elev <- as(gorillas.extra$elevation, "RasterLayer") 43 | 44 | # Plot the elevation 45 | 46 | ggplot() + 47 | gg(elev) 48 | } 49 | } 50 | } 51 | \seealso{ 52 | Other geomes for Raster data: 53 | \code{\link{gg}()} 54 | } 55 | \concept{geomes for Raster data} 56 | -------------------------------------------------------------------------------- /man/bru_summarise.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bru.inference.R 3 | \name{bru_summarise} 4 | \alias{bru_summarise} 5 | \title{Summarise and annotate data} 6 | \usage{ 7 | bru_summarise( 8 | data, 9 | probs = c(0.025, 0.5, 0.975), 10 | x = NULL, 11 | cbind.only = FALSE, 12 | max_moment = 2 13 | ) 14 | } 15 | \arguments{ 16 | \item{data}{A list of samples, each either numeric or a \code{data.frame}} 17 | 18 | \item{probs}{A numeric vector of probabilities with values in \verb{[0, 1]}, 19 | passed to \code{stats::quantile}} 20 | 21 | \item{x}{A \code{data.frame} of data columns that should be added to the summary 22 | data frame} 23 | 24 | \item{cbind.only}{If TRUE, only \code{cbind} the samples and return a matrix where 25 | each column is a sample} 26 | 27 | \item{max_moment}{integer, at least 2. Determines the largest moment 28 | order information to include in the output. If \code{max_moment > 2}, 29 | includes "skew" (skewness, \code{E[(x-m)^3/s^3]}), and 30 | if \code{max_moment > 3}, includes 31 | "ekurtosis" (excess kurtosis, \code{E[(x-m)^4/s^4] - 3}). Default 2. 32 | Note that the Monte Carlo variability of the \code{ekurtois} estimate may be 33 | large.} 34 | } 35 | \value{ 36 | A \code{data.frame} or \verb{Spatial[Points/Pixels]DataFrame} with summary 37 | statistics, "mean", "sd", \code{paste0("q", probs)}, "mean.mc_std_err", 38 | "sd.mc_std_err" 39 | } 40 | \description{ 41 | Summarise and annotate data 42 | } 43 | \examples{ 44 | bru_summarise(matrix(rexp(10000), 10, 1000), max_moment = 4, probs = NULL) 45 | 46 | } 47 | \keyword{internal} 48 | -------------------------------------------------------------------------------- /data-raw/shrimp.R: -------------------------------------------------------------------------------- 1 | #' Shrimp data import 2 | #' 3 | #' Load `shrimp` data stored as file `gamba.Rdata` and construct spatial object 4 | #' 5 | #' @keywords internal 6 | #' @return The [shrimp] data set 7 | #' @author Fabian E. Bachl \email{bachlfab@@gmail.com} 8 | #' 9 | import.shrimp <- function() { 10 | # Load the raw data 11 | load(file = file.path( 12 | system.file("extdata", package = "inlabru"), 13 | "gamba.Rdata" 14 | )) 15 | 16 | # Use lat/lon which is actually in a utm system 17 | gamba <- gamba[, c( 18 | "Peso.Capturado..Kg.", 19 | "Peso.Retenido..Kg.", 20 | "Prof.Media", 21 | "lat", 22 | "lon" 23 | )] 24 | 25 | # Rename columns 26 | colnames(gamba) <- c("catch", "landing", "depth", "northing", "easting") 27 | 28 | original_crs <- fm_crs("+proj=utm +zone=30 +datum=WGS84 +units=m +no_defs") 29 | new_crs <- fm_crs("+proj=utm +zone=30 +datum=WGS84 +units=km +no_defs") 30 | 31 | # Turn into spatial object 32 | gamba1 <- sf::st_as_sf( 33 | gamba, 34 | coords = c("easting", "northing"), 35 | crs = original_crs 36 | ) 37 | gamba1 <- fm_transform( 38 | gamba1, 39 | new_crs 40 | ) 41 | 42 | # Make a mesh 43 | bnd <- fm_nonconvex_hull_inla(gamba1, 20) 44 | bnd2 <- fm_nonconvex_hull_inla(gamba1, 50) 45 | mesh <- fm_mesh_2d_inla( 46 | boundary = list(bnd, bnd2), 47 | max.edge = c(5, 20), 48 | crs = fm_crs(gamba1) 49 | ) 50 | 51 | # Final shrimp object 52 | shrimp <- list(hauls = gamba1, mesh = mesh) 53 | 54 | shrimp 55 | } 56 | 57 | # shrimp <- import.shrimp() 58 | # usethis::use_data(shrimp, compress = "xz", overwrite = TRUE) 59 | -------------------------------------------------------------------------------- /man/bru_transformation.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/transformation.R 3 | \name{bru_transformation} 4 | \alias{bru_transformation} 5 | \alias{bru_forward_transformation} 6 | \alias{bru_inverse_transformation} 7 | \title{Transformation tools} 8 | \usage{ 9 | bru_forward_transformation(qfun, x, ..., tail.split. = 0) 10 | 11 | bru_inverse_transformation(pfun, x, ..., tail.split. = NULL) 12 | } 13 | \arguments{ 14 | \item{qfun}{A quantile function object, such as \code{qexp}} 15 | 16 | \item{x}{Values to be transformed} 17 | 18 | \item{\dots}{Distribution parameters passed on to the \code{qfun} and \code{pfun} 19 | functions} 20 | 21 | \item{tail.split.}{For x-values larger than \code{tail.split.}, upper quantile 22 | calculations are used internally, and for smaller values lower quantile 23 | calculations are used. This can avoid lack of accuracy in the distribution 24 | tails. If \code{NULL}, forward calculations split at 0, and inverse calculations 25 | use lower tails only, potentially losing accuracy in the upper tails.} 26 | 27 | \item{pfun}{A CDF function object, such as \code{pexp}} 28 | } 29 | \value{ 30 | \itemize{ 31 | \item For \code{bru_forward_transformation}, a numeric vector 32 | } 33 | 34 | \itemize{ 35 | \item For \code{bru_inverse_transformation}, a numeric vector 36 | } 37 | } 38 | \description{ 39 | Tools for transforming between N(0,1) variables and other 40 | distributions in predictor expressions 41 | } 42 | \examples{ 43 | u <- rnorm(5, 0, 1) 44 | y <- bru_forward_transformation(qexp, u, rate = 2) 45 | v <- bru_inverse_transformation(pexp, y, rate = 2) 46 | rbind(u, y, v) 47 | 48 | } 49 | -------------------------------------------------------------------------------- /man/globe.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rgl.R 3 | \name{globe} 4 | \alias{globe} 5 | \title{Visualize a globe using RGL} 6 | \usage{ 7 | globe( 8 | R = 1, 9 | R.grid = 1.05, 10 | specular = "black", 11 | axes = FALSE, 12 | box = FALSE, 13 | xlab = "", 14 | ylab = "", 15 | zlab = "" 16 | ) 17 | } 18 | \arguments{ 19 | \item{R}{Radius of the globe} 20 | 21 | \item{R.grid}{Radius of the annotation sphere.} 22 | 23 | \item{specular}{Light color of specular effect.} 24 | 25 | \item{axes}{If TRUE, plot x, y and z axes.} 26 | 27 | \item{box}{If TRUE, plot a box around the globe.} 28 | 29 | \item{xlab, ylab, zlab}{Axes labels} 30 | } 31 | \value{ 32 | No value, used for plotting side effect. 33 | } 34 | \description{ 35 | Creates a textured sphere and lon/lat coordinate annotations. 36 | This function requires the \code{rgl} and \code{sphereplot} packages. 37 | } 38 | \examples{ 39 | \donttest{ 40 | if (interactive() && 41 | require("rgl", quietly = TRUE) && 42 | require("sphereplot", quietly = TRUE) && 43 | bru_safe_sp() && 44 | require("sp")) { 45 | # Show the globe 46 | globe() 47 | 48 | # Load pantropoical dolphin data 49 | mexdolphin <- inlabru::mexdolphin_sp() 50 | 51 | # Add mesh, ship transects and dolphin sightings stored 52 | # as fm_mesh_2d, SpatialLines and SpatialPoints objects, respectively 53 | 54 | glplot(mexdolphin$mesh, alpha = 0.2) 55 | glplot(mexdolphin$samplers, lwd = 5) 56 | glplot(mexdolphin$points, size = 10) 57 | } 58 | } 59 | } 60 | \seealso{ 61 | Other inlabru RGL tools: 62 | \code{\link{glplot}()} 63 | } 64 | \concept{inlabru RGL tools} 65 | -------------------------------------------------------------------------------- /tests/testthat/test-fmesher_pixels.R: -------------------------------------------------------------------------------- 1 | test_that("fm_pixels sp vs sf", { 2 | skip_on_cran() 3 | local_bru_safe_inla() 4 | skip_if_not(bru_safe_sp()) 5 | skip_if_not_installed("sn") 6 | withr::local_options(lifecycle_verbosity = "quiet") 7 | 8 | mesh <- fm_mesh_2d_inla(cbind(0, 0), 9 | offset = 10, max.edge = 1, 10 | crs = fm_CRS("longlat_globe") 11 | ) 12 | 13 | mydata <- sp::SpatialPointsDataFrame( 14 | mesh$loc, 15 | data = data.frame(y = rnorm(mesh$n) + 10), 16 | proj4string = fm_CRS("longlat_globe") 17 | ) 18 | 19 | fit <- bru( 20 | ~ 0 + 21 | Intercept(1) + 22 | field( 23 | sp::coordinates, 24 | model = INLA::inla.spde2.pcmatern( 25 | mesh, 26 | prior.range = c(1, 0.01), 27 | prior.sigma = c(1, 0.01) 28 | ) 29 | ), 30 | bru_obs( 31 | y ~ ., 32 | family = "gaussian", 33 | data = mydata 34 | ) 35 | ) 36 | 37 | system.time({ 38 | withr::local_seed(1234L) 39 | surface1 <- fm_pixels(mesh, dims = c(5, 5), mask = TRUE, format = "sp") 40 | density1 <- predict(fit, 41 | surface1, 42 | ~ exp(field_eval(sp::coordinates(.data.)) + Intercept), 43 | n.samples = 10, 44 | seed = 12345L 45 | ) 46 | }) 47 | 48 | system.time({ 49 | withr::local_seed(1234L) 50 | surface2 <- fm_pixels(mesh, dims = c(5, 5), mask = TRUE, format = "sf") 51 | density2 <- predict(fit, 52 | surface2, 53 | ~ exp(field_eval(geometry) + Intercept), 54 | n.samples = 10, 55 | seed = 12345L 56 | ) 57 | }) 58 | 59 | expect_equal( 60 | density1$mean, 61 | density2$mean 62 | ) 63 | }) 64 | -------------------------------------------------------------------------------- /inst/examples/spde.posterior.R: -------------------------------------------------------------------------------- 1 | \donttest{ 2 | if (bru_safe_inla() && require(ggplot2, quietly = TRUE)) { 3 | 4 | # Load 1D Poisson process data 5 | 6 | data(Poisson2_1D, package = "inlabru") 7 | 8 | 9 | # Take a look at the point (and frequency) data 10 | 11 | ggplot(pts2) + 12 | geom_histogram(aes(x = x), binwidth = 55 / 20, boundary = 0, fill = NA, color = "black") + 13 | geom_point(aes(x), y = 0, pch = "|", cex = 4) + 14 | coord_fixed(ratio = 1) 15 | 16 | # Fit an LGCP model with and SPDE component 17 | 18 | x <- seq(0, 55, length.out = 20) 19 | mesh1D <- fm_mesh_1d(x, boundary = "free") 20 | mdl <- x ~ spde1D(x, model = INLA::inla.spde2.matern(mesh1D, constr = TRUE)) + Intercept(1) 21 | fit <- lgcp(mdl, data = pts2, domain = list(x = mesh1D)) 22 | 23 | # Calculate and plot the posterior range 24 | 25 | range <- spde.posterior(fit, "spde1D", "range") 26 | plot(range) 27 | 28 | # Calculate and plot the posterior log range 29 | 30 | lrange <- spde.posterior(fit, "spde1D", "log.range") 31 | plot(lrange) 32 | 33 | # Calculate and plot the posterior variance 34 | 35 | variance <- spde.posterior(fit, "spde1D", "variance") 36 | plot(variance) 37 | 38 | # Calculate and plot the posterior log variance 39 | 40 | lvariance <- spde.posterior(fit, "spde1D", "log.variance") 41 | plot(lvariance) 42 | 43 | # Calculate and plot the posterior Matern correlation 44 | 45 | matcor <- spde.posterior(fit, "spde1D", "matern.correlation") 46 | plot(matcor) 47 | 48 | # Calculate and plot the posterior Matern covariance 49 | 50 | matcov <- spde.posterior(fit, "spde1D", "matern.covariance") 51 | plot(matcov) 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /man/bru_log_reset.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/environment.R 3 | \name{bru_log_reset} 4 | \alias{bru_log_reset} 5 | \title{Clear log contents} 6 | \usage{ 7 | bru_log_reset(x = NULL, bookmark = NULL, offset = NULL) 8 | } 9 | \arguments{ 10 | \item{x}{A \code{bru_log} object, or in some cases, and object that can be 11 | converted/extracted to a \code{bru_log} object. \code{NULL} denotes the global 12 | \code{inlabru} log object.} 13 | 14 | \item{bookmark}{character; The label for a bookmark with a stored offset.} 15 | 16 | \item{offset}{integer; a position offset in the log, with \code{0L} pointing at 17 | the start of the log. If negative, denotes the point \code{abs(offset)} elements 18 | from tail of the log. When \code{bookmark} is non-NULL, the \code{offset} applies a 19 | shift (forwards or backwards) to the bookmark list.} 20 | } 21 | \value{ 22 | Returns (invisibly) the modified \code{bru_log} object, or \code{NULL} (when 23 | \code{x} is \code{NULL}) 24 | } 25 | \description{ 26 | Clears the log contents up to 27 | a given \code{offset} or \code{bookmark}. Default: clear the entire log. 28 | When \code{x} is NULL, the global \code{inlabru} log is updated, and \code{invisible(NULL)} 29 | is returned. Otherwise the updated object is returned (invisibly). 30 | } 31 | \examples{ 32 | \dontrun{ 33 | if (interactive()) { 34 | bru_log_reset() 35 | } 36 | } 37 | } 38 | \seealso{ 39 | Other inlabru log methods: 40 | \code{\link{bru_log}()}, 41 | \code{\link{bru_log_bookmark}()}, 42 | \code{\link{bru_log_message}()}, 43 | \code{\link{bru_log_new}()}, 44 | \code{\link{bru_log_offset}()} 45 | } 46 | \concept{inlabru log methods} 47 | -------------------------------------------------------------------------------- /man/as_bru_obs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bru_conversion.R 3 | \name{as_bru_obs} 4 | \alias{as_bru_obs} 5 | \alias{as_bru_obs_list} 6 | \alias{as_bru_obs.bru_obs} 7 | \alias{as_bru_obs_list.bru_obs} 8 | \alias{as_bru_obs_list.list} 9 | \alias{as_bru_obs_list.bru_obs_list} 10 | \alias{as_bru_obs_list.bru} 11 | \alias{as_bru_obs_list.bru_info} 12 | \alias{as_bru_obs_list.bru_model} 13 | \title{Conversion methods for \code{bru_obs} and \code{bru_obs_list} objects} 14 | \usage{ 15 | as_bru_obs(x, ...) 16 | 17 | as_bru_obs_list(x, .tag = NULL) 18 | 19 | \method{as_bru_obs}{bru_obs}(x, ...) 20 | 21 | \method{as_bru_obs_list}{bru_obs}(x, .tag = NULL) 22 | 23 | \method{as_bru_obs_list}{list}(x, .tag = NULL) 24 | 25 | \method{as_bru_obs_list}{bru_obs_list}(x, .tag = NULL) 26 | 27 | \method{as_bru_obs_list}{bru}(x, .tag = NULL) 28 | 29 | \method{as_bru_obs_list}{bru_info}(x, .tag = NULL) 30 | 31 | \method{as_bru_obs_list}{bru_model}(x, .tag = NULL) 32 | } 33 | \arguments{ 34 | \item{x}{An object to convert to \link{bru_obs} or \link{bru_obs_list}} 35 | 36 | \item{\dots}{Additional arguments passed to sub-methods.} 37 | 38 | \item{.tag}{character; optional name for the single observation model in the 39 | returned \link{bru_obs_list} object. Default is \code{NULL}, which results in 40 | automatic naming based on the \code{tag} attribute of \code{x}, if present.} 41 | } 42 | \value{ 43 | An object of class \link{bru_obs} or \link{bru_obs_list}. 44 | } 45 | \description{ 46 | Methods for converting to \code{bru_obs} and \code{bru_obs_list} 47 | objects. 48 | } 49 | \seealso{ 50 | \code{\link[=as_bru_comp_list]{as_bru_comp_list()}} 51 | } 52 | -------------------------------------------------------------------------------- /man/point2count.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plotsample.R 3 | \name{point2count} 4 | \alias{point2count} 5 | \title{Convert a plot sample of points into one of counts.} 6 | \usage{ 7 | point2count(plots, dets) 8 | } 9 | \arguments{ 10 | \item{plots}{A \code{SpatialPolygonsDataFrame} object containing the plots that 11 | were sampled.} 12 | 13 | \item{dets}{A \code{SpatialPointsDataFrame} object containing the locations of the 14 | points within the plots.} 15 | } 16 | \value{ 17 | A \code{SpatialPolygonsDataFrame} with counts in each plot contained in 18 | slot \verb{@data$n}. 19 | } 20 | \description{ 21 | Converts a plot sample with locations of each point within each plot, into a 22 | plot sample with only the count within each plot. 23 | } 24 | \examples{ 25 | \donttest{ 26 | # Some features require the raster package 27 | if (bru_safe_sp() && 28 | require("sp") && 29 | require("raster", quietly = TRUE) && 30 | require("ggplot2", quietly = TRUE) && 31 | require("terra", quietly = TRUE) && 32 | require("sf", quietly = TRUE)) { 33 | gorillas <- gorillas_sp() 34 | plotpts <- plotsample(gorillas$nests, gorillas$boundary, 35 | x.ppn = 0.4, y.ppn = 0.4, nx = 5, ny = 5 36 | ) 37 | p1 <- ggplot() + 38 | gg(plotpts$plots) + 39 | gg(plotpts$dets) + 40 | gg(gorillas$boundary) 41 | countdata <- point2count(plotpts$plots, plotpts$dets) 42 | x <- sp::coordinates(countdata)[, 1] 43 | y <- sp::coordinates(countdata)[, 2] 44 | count <- countdata@data$n 45 | p2 <- ggplot() + 46 | gg(gorillas$boundary) + 47 | gg(plotpts$plots) + 48 | geom_text(aes(label = count, x = x, y = y)) 49 | multiplot(p1, p2, cols = 2) 50 | } 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /inst/examples/gg.sf.R: -------------------------------------------------------------------------------- 1 | \donttest{ 2 | if (require("ggplot2", quietly = TRUE) && 3 | requireNamespace("terra", quietly = TRUE) && 4 | require("tidyterra", quietly = TRUE)) { 5 | # Load Gorilla data 6 | 7 | gorillas <- inlabru::gorillas_sf 8 | gorillas$gcov <- gorillas_sf_gcov() 9 | 10 | # Plot Gorilla elevation covariate provided as terra::rast. 11 | 12 | ggplot() + 13 | gg(gorillas$gcov$elevation) 14 | 15 | # Add Gorilla survey boundary and nest sightings 16 | 17 | ggplot() + 18 | gg(gorillas$gcov$elevation) + 19 | gg(gorillas$boundary, alpha = 0) + 20 | gg(gorillas$nests) 21 | 22 | # Load pantropical dolphin data 23 | 24 | mexdolphin <- inlabru::mexdolphin_sf 25 | 26 | # Plot the pantropical survey boundary, ship transects and dolphin sightings 27 | 28 | ggplot() + 29 | gg(mexdolphin$ppoly, alpha = 0.5) + # survey boundary 30 | gg(mexdolphin$samplers) + # ship transects 31 | gg(mexdolphin$points) # dolphin sightings 32 | 33 | # Change color 34 | 35 | ggplot() + 36 | gg(mexdolphin$ppoly, color = "green", alpha = 0.5) + # survey boundary 37 | gg(mexdolphin$samplers, color = "red") + # ship transects 38 | gg(mexdolphin$points, color = "blue") # dolphin sightings 39 | 40 | 41 | # Visualize data annotations: line width by segment number 42 | 43 | names(mexdolphin$samplers) # 'seg' holds the segment number 44 | ggplot() + 45 | gg(mexdolphin$samplers, aes(color = seg)) 46 | 47 | # Visualize data annotations: point size by dolphin group size 48 | 49 | names(mexdolphin$points) # 'size' holds the group size 50 | ggplot() + 51 | gg(mexdolphin$points, aes(size = size)) 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /R/data.Poisson1_1D.R: -------------------------------------------------------------------------------- 1 | #' @name Poisson1_1D 2 | #' @title 1-Dimensional Homogeneous Poisson example. 3 | #' @docType data 4 | #' @description Point data and count data, together with intensity function and 5 | #' expected counts for a homogeneous 1-dimensional Poisson process example. 6 | #' 7 | #' @aliases lambda1_1D E_nc1 pts1 countdata1 8 | #' 9 | #' @usage data(Poisson1_1D) 10 | #' 11 | #' @format The data contain the following `R` objects: 12 | #' \describe{ 13 | #' \item{`lambda1_1D`}{ A function defining the intensity function of a 14 | #' nonhomogeneous Poisson process. Note that this function is only defined on 15 | #' the interval (0,55).} 16 | #' \item{`E_nc1`}{ The expected counts of the gridded data.} 17 | #' \item{`pts1`}{ The locations of the observed points (a data frame with 18 | #' one column, named `x`).} 19 | #' \item{`countdata1`}{ A data frame with three columns, containing the 20 | #' count data:} 21 | #' \describe{ 22 | #' \item{`x`}{ The grid cell midpoint.} 23 | #' \item{`count`}{ The number of detections in the cell.} 24 | #' \item{`exposure`}{ The width of the cell.} 25 | #' } 26 | #' } 27 | #' 28 | #' @examples 29 | #' \donttest{ 30 | #' if (require("ggplot2", quietly = TRUE)) { 31 | #' data(Poisson1_1D) 32 | #' ggplot(countdata1) + 33 | #' geom_point(data = countdata1, aes(x = x, y = count), col = "blue") + 34 | #' ylim(0, max(countdata1$count)) + 35 | #' geom_point(data = pts1, aes(x = x), y = 0.2, shape = "|", cex = 4) + 36 | #' geom_point( 37 | #' data = countdata1, aes(x = x), y = 0, shape = "+", 38 | #' col = "blue", cex = 4 39 | #' ) + 40 | #' xlab(expression(bold(s))) + 41 | #' ylab("count") 42 | #' } 43 | #' } 44 | NULL 45 | -------------------------------------------------------------------------------- /man/eval_spatial.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{eval_spatial} 4 | \alias{eval_spatial} 5 | \alias{eval_spatial.SpatialPolygonsDataFrame} 6 | \alias{eval_spatial.SpatialPixelsDataFrame} 7 | \alias{eval_spatial.SpatialGridDataFrame} 8 | \alias{eval_spatial.sf} 9 | \alias{eval_spatial.SpatRaster} 10 | \alias{eval_spatial.stars} 11 | \title{Evaluate spatial covariates} 12 | \usage{ 13 | eval_spatial(data, where, layer = NULL, selector = NULL) 14 | 15 | \method{eval_spatial}{SpatialPolygonsDataFrame}(data, where, layer = NULL, selector = NULL) 16 | 17 | \method{eval_spatial}{SpatialPixelsDataFrame}(data, where, layer = NULL, selector = NULL) 18 | 19 | \method{eval_spatial}{SpatialGridDataFrame}(data, where, layer = NULL, selector = NULL) 20 | 21 | \method{eval_spatial}{sf}(data, where, layer = NULL, selector = NULL) 22 | 23 | \method{eval_spatial}{SpatRaster}(data, where, layer = NULL, selector = NULL) 24 | 25 | \method{eval_spatial}{stars}(data, where, layer = NULL, selector = NULL) 26 | } 27 | \arguments{ 28 | \item{data}{Spatial data} 29 | 30 | \item{where}{Where to evaluate the data} 31 | 32 | \item{layer}{Which \code{data} layer to extract (as integer or character). 33 | May be a vector, specifying a separate layer for each \code{where} item.} 34 | 35 | \item{selector}{The name of a variable in \code{where} specifying the \code{layer} 36 | information.} 37 | } 38 | \description{ 39 | Evaluate spatial covariates 40 | } 41 | \section{Methods (by class)}{ 42 | \itemize{ 43 | \item \code{eval_spatial(SpatialPolygonsDataFrame)}: Compatibility wrapper for \code{eval_spatial.sf} 44 | 45 | \item \code{eval_spatial(sf)}: Supports point-in-polygon information lookup. 46 | Other combinations are untested. 47 | 48 | }} 49 | -------------------------------------------------------------------------------- /man/evaluate_effect.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/model.R 3 | \name{evaluate_effect_single_state} 4 | \alias{evaluate_effect_single_state} 5 | \alias{evaluate_effect_single_state.bru_mapper} 6 | \alias{evaluate_effect_single_state.bm_list} 7 | \alias{evaluate_effect_single_state.bru_comp_list} 8 | \title{Evaluate a component effect} 9 | \usage{ 10 | evaluate_effect_single_state(...) 11 | 12 | \method{evaluate_effect_single_state}{bru_mapper}(component, input, state, ..., label = NULL) 13 | 14 | \method{evaluate_effect_single_state}{bm_list}(components, input, state, ...) 15 | 16 | \method{evaluate_effect_single_state}{bru_comp_list}(components, input, state, ...) 17 | } 18 | \arguments{ 19 | \item{\dots}{Optional additional parameters, e.g. \code{inla_f}. Normally unused.} 20 | 21 | \item{component}{A \link{bru_mapper}, \link{bru_comp}, or 22 | \link{bm_list}.} 23 | 24 | \item{input}{Pre-evaluated component input} 25 | 26 | \item{state}{Specification of one latent variable state: 27 | \itemize{ 28 | \item \code{evaluate_effect_single_state.bru_mapper}: 29 | A vector of the latent component state. 30 | \item \verb{evaluate_effect_single_state.*_list}: list of named state vectors. 31 | }} 32 | 33 | \item{label}{Option label used for any warning messages, specifying the 34 | affected component.} 35 | } 36 | \value{ 37 | \itemize{ 38 | \item \code{evaluate_effect_single_state.bm_list}: A list of 39 | evaluated component effect values 40 | } 41 | } 42 | \description{ 43 | Calculate latent component effects given some data and the state of the 44 | component's internal random variables. 45 | } 46 | \author{ 47 | Fabian E. Bachl \email{bachlfab@gmail.com} and 48 | Finn Lindgren \email{finn.lindgren@gmail.com} 49 | } 50 | \keyword{internal} 51 | -------------------------------------------------------------------------------- /man/Poisson1_1D.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.Poisson1_1D.R 3 | \docType{data} 4 | \name{Poisson1_1D} 5 | \alias{Poisson1_1D} 6 | \alias{lambda1_1D} 7 | \alias{E_nc1} 8 | \alias{pts1} 9 | \alias{countdata1} 10 | \title{1-Dimensional Homogeneous Poisson example.} 11 | \format{ 12 | The data contain the following \code{R} objects: 13 | \describe{ 14 | \item{\code{lambda1_1D}}{ A function defining the intensity function of a 15 | nonhomogeneous Poisson process. Note that this function is only defined on 16 | the interval (0,55).} 17 | \item{\code{E_nc1}}{ The expected counts of the gridded data.} 18 | \item{\code{pts1}}{ The locations of the observed points (a data frame with 19 | one column, named \code{x}).} 20 | \item{\code{countdata1}}{ A data frame with three columns, containing the 21 | count data:} 22 | \describe{ 23 | \item{\code{x}}{ The grid cell midpoint.} 24 | \item{\code{count}}{ The number of detections in the cell.} 25 | \item{\code{exposure}}{ The width of the cell.} 26 | } 27 | } 28 | } 29 | \usage{ 30 | data(Poisson1_1D) 31 | } 32 | \description{ 33 | Point data and count data, together with intensity function and 34 | expected counts for a homogeneous 1-dimensional Poisson process example. 35 | } 36 | \examples{ 37 | \donttest{ 38 | if (require("ggplot2", quietly = TRUE)) { 39 | data(Poisson1_1D) 40 | ggplot(countdata1) + 41 | geom_point(data = countdata1, aes(x = x, y = count), col = "blue") + 42 | ylim(0, max(countdata1$count)) + 43 | geom_point(data = pts1, aes(x = x), y = 0.2, shape = "|", cex = 4) + 44 | geom_point( 45 | data = countdata1, aes(x = x), y = 0, shape = "+", 46 | col = "blue", cex = 4 47 | ) + 48 | xlab(expression(bold(s))) + 49 | ylab("count") 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /man/iinla.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bru.inference.R 3 | \name{iinla} 4 | \alias{iinla} 5 | \title{Iterated INLA} 6 | \usage{ 7 | iinla(model, lhoods, inputs = NULL, initial = NULL, options) 8 | } 9 | \arguments{ 10 | \item{model}{A \link{bru_model} object} 11 | 12 | \item{lhoods}{A list of likelihood objects from \code{\link[=bru_obs]{bru_obs()}}} 13 | 14 | \item{inputs}{Optional pre-computed list of per-likelihood component 15 | evaluations, from \code{\link[=bru_input.bru_obs_list]{bru_input.bru_obs_list()}}.} 16 | 17 | \item{initial}{A previous \code{bru} result or a list of named latent variable 18 | initial states (missing elements are set to zero), to be used as starting 19 | point, or \code{NULL}. If non-null, overrides \code{options$bru_initial}} 20 | 21 | \item{options}{A \code{bru_options} object.} 22 | } 23 | \value{ 24 | An \code{iinla} object that inherits from \code{INLA::inla}, with an 25 | added field \code{bru_iinla} with elements 26 | \describe{ 27 | \item{log}{The diagnostic log messages produced by the run} 28 | \item{states}{The list of linearisation points, one for each inla run} 29 | \item{inla_stack}{The \code{inla.stack} object from the final inla run} 30 | \item{track}{A list of convergence tracking vectors} 31 | } 32 | If an inla run is aborted by an error, the returned object also contains 33 | an element \code{error} with the error object. 34 | } 35 | \description{ 36 | This is an internal wrapper for iterated runs of \code{INLA::inla}. 37 | For nonlinear models, a linearisation is done with 38 | \code{bru_compute_linearisation}, with a line search method between each 39 | iteration. The \code{INLA::inla.stack} information is setup by \code{\link[=bru_make_stack]{bru_make_stack()}}. 40 | } 41 | \keyword{internal} 42 | -------------------------------------------------------------------------------- /tests/testthat/test-latent_rw2.R: -------------------------------------------------------------------------------- 1 | test_that("Latent models: RW2 mapping", { 2 | skip_on_cran() 3 | local_bru_safe_inla() 4 | 5 | withr::local_seed(123L) 6 | 7 | data1 <- data.frame( 8 | time = rep(c(1, 2, 4, 8, 16), times = 4), 9 | obs = rep(c(1, 2, 1, 4, 2), times = 4) + rnorm(20, sd = 0.5) 10 | ) 11 | 12 | cmp1 <- obs ~ time(time, 13 | model = "rw2", values = 2^(0:4), 14 | constr = FALSE, scale.model = TRUE 15 | ) - Intercept 16 | fit1 <- bru(cmp1, data = data1, family = "gaussian") 17 | 18 | expect_equal( 19 | fit1$summary.random$time$mean, 20 | c(1.631781, 1.895681, 1.025671, 3.959789, 1.841140), 21 | tolerance = midtol 22 | ) 23 | expect_equal( 24 | fit1$summary.random$time$sd, 25 | c(0.2350089, 0.2438991, 0.2749531, 0.2542052, 0.2473781), 26 | tolerance = hitol 27 | ) 28 | }) 29 | 30 | 31 | test_that("Latent models: RW2 mapping, data is list with different I/O sizes", { 32 | skip_on_cran() 33 | local_bru_safe_inla() 34 | 35 | withr::local_seed(123L) 36 | 37 | data1 <- list( 38 | time = c(1, 2, 4, 8, 16), 39 | obs = rep(c(1, 2, 1, 4, 2), times = 4) + rnorm(20, sd = 0.5) 40 | ) 41 | 42 | cmp1 <- obs ~ time(time, 43 | model = "rw2", values = 2^(0:4), 44 | constr = FALSE, scale.model = TRUE 45 | ) - Intercept 46 | formula <- obs ~ rep(time, times = 4) 47 | fit1 <- bru(cmp1, 48 | formula = formula, data = data1, family = "gaussian", 49 | is_rowwise = FALSE 50 | ) 51 | 52 | expect_equal( 53 | fit1$summary.random$time$mean, 54 | c(1.631781, 1.895681, 1.025671, 3.959789, 1.841140), 55 | tolerance = midtol 56 | ) 57 | expect_equal( 58 | fit1$summary.random$time$sd, 59 | c(0.2350011, 0.2438999, 0.2749631, 0.2542013, 0.2473662), 60 | tolerance = hitol 61 | ) 62 | }) 63 | -------------------------------------------------------------------------------- /man/bru_log_offset.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/environment.R 3 | \name{bru_log_offset} 4 | \alias{bru_log_offset} 5 | \alias{bru_log_index} 6 | \title{Position methods for \code{bru_log} objects} 7 | \usage{ 8 | bru_log_offset(x = NULL, bookmark = NULL, offset = NULL) 9 | 10 | bru_log_index(x = NULL, i, verbosity = NULL) 11 | } 12 | \arguments{ 13 | \item{x}{A \code{bru_log} object. If \code{NULL}, the global \code{inlabru} log is used.} 14 | 15 | \item{bookmark}{character; The label for a bookmark with a stored offset.} 16 | 17 | \item{offset}{integer; a position offset in the log, with \code{0L} pointing at 18 | the start of the log. If negative, denotes the point \code{abs(offset)} elements 19 | from tail of the log. When \code{bookmark} is non-NULL, the \code{offset} applies a 20 | shift (forwards or backwards) to the bookmark list.} 21 | 22 | \item{i}{indices specifying elements to extract. If \code{character}, denotes 23 | the sequence between bookmark \code{i} and the next bookmark (or the end of the 24 | log if \code{i} is the last bookmark)} 25 | 26 | \item{verbosity}{integer value for limiting the highest verbosity level being 27 | returned.} 28 | } 29 | \description{ 30 | Position methods for \code{bru_log} objects. 31 | } 32 | \section{Functions}{ 33 | \itemize{ 34 | \item \code{bru_log_offset()}: Utility function for computing log position offsets. 35 | 36 | \item \code{bru_log_index()}: Utility function for computing index vectors 37 | for \code{bru_log} objects. 38 | 39 | }} 40 | \seealso{ 41 | Other inlabru log methods: 42 | \code{\link{bru_log}()}, 43 | \code{\link{bru_log_bookmark}()}, 44 | \code{\link{bru_log_message}()}, 45 | \code{\link{bru_log_new}()}, 46 | \code{\link{bru_log_reset}()} 47 | } 48 | \concept{inlabru log methods} 49 | -------------------------------------------------------------------------------- /man/bru_log_bookmark.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/environment.R 3 | \name{bru_log_bookmark} 4 | \alias{bru_log_bookmark} 5 | \alias{bru_log_bookmarks} 6 | \title{Methods for \code{bru_log} bookmarks} 7 | \usage{ 8 | bru_log_bookmark(bookmark = "", offset = NULL, x = NULL) 9 | 10 | bru_log_bookmarks(x = NULL) 11 | } 12 | \arguments{ 13 | \item{bookmark}{character; The label for a bookmark with a stored offset.} 14 | 15 | \item{offset}{integer; a position offset in the log, with \code{0L} pointing at 16 | the start of the log. If negative, denotes the point \code{abs(offset)} elements 17 | from tail of the log. When \code{bookmark} is non-NULL, the \code{offset} applies a 18 | shift (forwards or backwards) to the bookmark list.} 19 | 20 | \item{x}{A \code{bru_log} object. If \code{NULL}, the global \code{inlabru} log is used.} 21 | } 22 | \value{ 23 | \code{bru_log_bookmark()}: Returns the modified \code{bru_log} object if \code{x} 24 | is non-NULL. 25 | 26 | \code{bru_log_bookmarks()}: Returns the bookmark vector associated with 27 | \code{x} 28 | } 29 | \description{ 30 | Methods for \code{bru_log} bookmarks. 31 | } 32 | \section{Functions}{ 33 | \itemize{ 34 | \item \code{bru_log_bookmark()}: Set a log bookmark. If \code{offset} is \code{NULL} (the default), 35 | the bookmark will point to the current end of the log. 36 | 37 | \item \code{bru_log_bookmarks()}: Return a integer vector with named elements 38 | being bookmarks into the global \code{inlabru} log with associated log position 39 | offsets. 40 | 41 | }} 42 | \seealso{ 43 | Other inlabru log methods: 44 | \code{\link{bru_log}()}, 45 | \code{\link{bru_log_message}()}, 46 | \code{\link{bru_log_new}()}, 47 | \code{\link{bru_log_offset}()}, 48 | \code{\link{bru_log_reset}()} 49 | } 50 | \concept{inlabru log methods} 51 | -------------------------------------------------------------------------------- /man/ibm_inla_subset.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mappers.R 3 | \name{ibm_inla_subset} 4 | \alias{ibm_inla_subset} 5 | \alias{ibm_inla_subset.default} 6 | \title{Find index subset of INLA visible states} 7 | \usage{ 8 | ibm_inla_subset(mapper, ...) 9 | 10 | \method{ibm_inla_subset}{default}(mapper, ...) 11 | } 12 | \arguments{ 13 | \item{mapper}{A mapper S3 object, inheriting from \code{bru_mapper}.} 14 | 15 | \item{...}{Arguments passed on to other methods} 16 | } 17 | \description{ 18 | Implementations must return a logical vector of \code{TRUE/FALSE} for 19 | the subset such that, given the full A matrix and values output, 20 | \code{A[, subset, drop = FALSE]} and \code{values[subset]} 21 | (or \code{values[subset, , drop = FALSE]} for data.frame values) are equal 22 | to the \code{inla_f = TRUE} version of A and values. The default method uses 23 | the \code{ibm_values} output to construct the subset indexing. 24 | } 25 | \section{Methods (by class)}{ 26 | \itemize{ 27 | \item \code{ibm_inla_subset(default)}: Uses the [ibm_values\verb{()] output to construct the inla subset indexing as the difference between }inla_f=FALSE\code{and}inla_f=TRUE\verb{. Extra arguments such as }multi\verb{are passed on to [ibm_values()]. This means it supports both regular vector values and}multi=1` data.frame values. 28 | 29 | }} 30 | \seealso{ 31 | Other mapper methods: 32 | \code{\link{bru_mapper_generics}}, 33 | \code{\link{ibm_eval}()}, 34 | \code{\link{ibm_eval2}()}, 35 | \code{\link{ibm_invalid_output}()}, 36 | \code{\link{ibm_is_linear}()}, 37 | \code{\link{ibm_is_rowwise}()}, 38 | \code{\link{ibm_jacobian}()}, 39 | \code{\link{ibm_linear}()}, 40 | \code{\link{ibm_n}()}, 41 | \code{\link{ibm_n_output}()}, 42 | \code{\link{ibm_names}()}, 43 | \code{\link{ibm_simplify}()}, 44 | \code{\link{ibm_values}()} 45 | } 46 | \concept{mapper methods} 47 | -------------------------------------------------------------------------------- /man/multiplot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ggplot.R 3 | \name{multiplot} 4 | \alias{multiplot} 5 | \title{Multiple ggplots on a page.} 6 | \source{ 7 | \url{http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/} 8 | } 9 | \usage{ 10 | multiplot(..., plotlist = NULL, cols = 1, layout = NULL) 11 | } 12 | \arguments{ 13 | \item{\dots}{Comma-separated \code{ggplot} objects.} 14 | 15 | \item{plotlist}{A list of \code{ggplot} objects - an alternative to the 16 | comma-separated argument above.} 17 | 18 | \item{cols}{Number of columns of plots on the page.} 19 | 20 | \item{layout}{A matrix specifying the layout. If present, \code{cols} is ignored. 21 | If the layout is something like \code{matrix(c(1,2,3,3), nrow=2, byrow=TRUE)}, 22 | then plot 1 will go in the upper left, 2 will go in the upper right, and 3 23 | will go all the way across the bottom.} 24 | } 25 | \description{ 26 | \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} in favour of the \code{patchwork} package; 27 | see the example below. 28 | 29 | Renders multiple ggplots on a single page. 30 | } 31 | \examples{ 32 | if (require("ggplot2", quietly = TRUE)) { 33 | df <- data.frame(x = 1:10, y = cos(1:10), z = sin(1:10)) 34 | pl1 <- ggplot(data = df) + 35 | geom_line(mapping = aes(x, y), color = "red") 36 | pl2 <- ggplot(data = df) + 37 | geom_line(mapping = aes(x, z), color = "blue") 38 | pl3 <- ggplot(data = df) + 39 | geom_path(mapping = aes(y, z), color = "magenta") 40 | multiplot( 41 | pl1, pl2, pl3, 42 | layout = rbind(c(1, 2), c(3, 3)) 43 | ) 44 | 45 | if (require("patchwork")) { 46 | (pl1 + pl2) / pl3 47 | } 48 | } 49 | } 50 | \author{ 51 | David L. Borchers \email{dlb@st-andrews.ac.uk} 52 | } 53 | -------------------------------------------------------------------------------- /man/bru_eval_in_data_context.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bru.inference.R 3 | \name{bru_eval_in_data_context} 4 | \alias{bru_eval_in_data_context} 5 | \title{Evaluate expressions in data contexts} 6 | \usage{ 7 | bru_eval_in_data_context( 8 | input, 9 | data = NULL, 10 | default = NULL, 11 | .envir = parent.frame() 12 | ) 13 | } 14 | \arguments{ 15 | \item{input}{An expression to be evaluated} 16 | 17 | \item{data}{list of data objects in priority order. Named elements will be 18 | available as whole objects \code{.name.} as well as pronouns \code{.name} in the 19 | evaluation.} 20 | 21 | \item{default}{Value used if the expression is evaluated as NULL. Default 22 | NULL} 23 | 24 | \item{.envir}{The evaluation environment} 25 | } 26 | \value{ 27 | The result of expression evaluation 28 | } 29 | \description{ 30 | Evaluate an expression in a series of data contexts, also making 31 | the objects directly available as names surrounded by ".", stopping when 32 | the expression evaluation completes with no error, as well as \code{tidy} 33 | evaluation pronouns, e.g. \code{.data}. 34 | 35 | This is an internal inlabru method, not intended for general use. 36 | } 37 | \examples{ 38 | # The A values come from the 'data' element, and the B values come from 39 | # the 'response_data' element, as that is listed first. 40 | bru_eval_in_data_context( 41 | list(A = .data$x, B = x), 42 | list( 43 | response_data = tibble::tibble(x = 1:5), 44 | data = tibble::tibble(x = 1:10) 45 | ) 46 | ) 47 | # Both A and B come from the 'data' element, as 'x' is found there, 48 | # and the data objects are listed in order of precedence. 49 | bru_eval_in_data_context( 50 | list(A = .data$x, B = x), 51 | list( 52 | data = tibble::tibble(x = 1:10), 53 | response_data = tibble::tibble(x = 1:5) 54 | ) 55 | ) 56 | 57 | } 58 | \keyword{internal} 59 | -------------------------------------------------------------------------------- /man/plot.bru.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ggplot.R, R/inla.R 3 | \name{plot.bru} 4 | \alias{plot.bru} 5 | \alias{plotmarginal.inla} 6 | \title{Plot method for posterior marginals estimated by bru} 7 | \usage{ 8 | \method{plot}{bru}(x, ...) 9 | 10 | plotmarginal.inla( 11 | result, 12 | varname = NULL, 13 | index = NULL, 14 | link = function(x) { 15 | x 16 | }, 17 | add = FALSE, 18 | ggp = TRUE, 19 | lwd = 3, 20 | ... 21 | ) 22 | } 23 | \arguments{ 24 | \item{x}{a fitted \code{\link[=bru]{bru()}} model.} 25 | 26 | \item{\dots}{Options passed on to other methods.} 27 | 28 | \item{result}{an \code{inla} or \code{bru} result object} 29 | 30 | \item{varname}{character; name of the variable to plot} 31 | 32 | \item{index}{integer; index of the random effect to plot} 33 | 34 | \item{link}{function; link function to apply to the variable} 35 | 36 | \item{add}{logical; if \code{TRUE}, add to an existing plot} 37 | 38 | \item{ggp}{logical; unused} 39 | 40 | \item{lwd}{numeric; line width} 41 | } 42 | \description{ 43 | From version \verb{2.11.0}, \code{plot.bru(x, ...)} calls \code{plot.inla(x, ...)} 44 | from the \code{INLA} package, unless the first argument after \code{x} is a 45 | \code{character}, in which case the pre-\verb{2.11.0} behaviour is used, calling 46 | \code{plotmarginal.inla(x, ...)} instead. 47 | 48 | Requires the \code{ggplot2} package. 49 | } 50 | \examples{ 51 | \dontrun{ 52 | if (require("ggplot2", quietly = TRUE)) { 53 | # Generate some data and fit a simple model 54 | input.df <- data.frame(x = cos(1:10)) 55 | input.df <- within( 56 | input.df, 57 | y <- 5 + 2 * x + rnorm(length(x), mean = 0, sd = 0.1) 58 | ) 59 | fit <- bru(y ~ x, family = "gaussian", data = input.df) 60 | summary(fit) 61 | 62 | # Plot the posterior density of the model's x-effect 63 | plot(fit, "x") 64 | } 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /man/bm_scale.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mappers.R 3 | \name{bm_scale} 4 | \alias{bm_scale} 5 | \alias{bru_mapper_scale} 6 | \title{Mapper for element-wise scaling} 7 | \usage{ 8 | bm_scale(mapper = NULL) 9 | 10 | bru_mapper_scale(...) 11 | } 12 | \arguments{ 13 | \item{mapper}{An optional \code{bru_mapper} to be scaled.} 14 | 15 | \item{\dots}{Arguments passed on to \code{\link[=bm_scale]{bm_scale()}}} 16 | } 17 | \description{ 18 | Create a standalone 19 | scaling mapper that can be used as part of a \code{bm_pipe}. 20 | If \code{mapper} is non-null, the \code{bm_scale()} constructor 21 | returns 22 | \code{bm_pipe(list(mapper = mapper, scale = bm_scale()))} 23 | } 24 | \examples{ 25 | m <- bm_scale() 26 | ibm_eval2(m, c(1, 2, 1, 2), 1:4) 27 | 28 | } 29 | \seealso{ 30 | \link{bru_mapper}, \link{bru_mapper_generics} 31 | 32 | Other mappers: 33 | \code{\link{bm_aggregate}()}, 34 | \code{\link{bm_collect}()}, 35 | \code{\link{bm_const}()}, 36 | \code{\link{bm_factor}()}, 37 | \code{\link{bm_fm_mesh_1d}}, 38 | \code{\link{bm_fmesher}()}, 39 | \code{\link{bm_harmonics}()}, 40 | \code{\link{bm_index}()}, 41 | \code{\link{bm_linear}()}, 42 | \code{\link{bm_logitaverage}()}, 43 | \code{\link{bm_logsumexp}()}, 44 | \code{\link{bm_marginal}()}, 45 | \code{\link{bm_matrix}()}, 46 | \code{\link{bm_multi}()}, 47 | \code{\link{bm_pipe}()}, 48 | \code{\link{bm_reparam}()}, 49 | \code{\link{bm_repeat}()}, 50 | \code{\link{bm_shift}()}, 51 | \code{\link{bm_sum}()}, 52 | \code{\link{bm_taylor}()}, 53 | \code{\link{bru_get_mapper}()}, 54 | \code{\link{bru_mapper}()} 55 | 56 | Other specific \link{bm_scale} method implementations: 57 | \code{\link{ibm_eval}()}, 58 | \code{\link{ibm_jacobian}()}, 59 | \code{\link{ibm_n}()}, 60 | \code{\link{ibm_n_output}()}, 61 | \code{\link{ibm_values}()} 62 | } 63 | \concept{mappers} 64 | \concept{specific \link{bm_scale} method implementations} 65 | -------------------------------------------------------------------------------- /man/bm_reparam.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mappers.R 3 | \name{bm_reparam} 4 | \alias{bm_reparam} 5 | \title{Mapper for reparameterising mapper states} 6 | \usage{ 7 | bm_reparam(mapper, B) 8 | } 9 | \arguments{ 10 | \item{mapper}{A \code{bru_mapper} object} 11 | 12 | \item{B}{a square or rectangular basis conversion matrix} 13 | } 14 | \description{ 15 | Creates a mapper for handling basis conversions. Functionally 16 | equivalent to \code{bm_pipe(list(bm_matrix(ncol(B)), mapper))}, but with an 17 | internally stored matrix input \code{B} for efficiency, and allowing the mapper 18 | \code{input} format to be identical to that of the original \code{mapper}. 19 | } 20 | \examples{ 21 | # 2->2 reparameterisation; (u1,u2) -> (u1, u1 + u2) 22 | (m <- bm_reparam(bm_index(2), B = matrix(c(1, 1, 0, 1), 2, 2))) 23 | 24 | # 2->3 reparameterisation; (u1,u2) -> (u1, u2, u1+u2) 25 | # This is an example of a low-rank representation of a higher-dimensional 26 | # state vector. 27 | (m <- bm_reparam(bm_index(3), B = cbind(c(1, 0, 1), c(0, 1, 1)))) 28 | 29 | } 30 | \seealso{ 31 | \link{bru_mapper}, \link{bru_mapper_generics} 32 | 33 | Other mappers: 34 | \code{\link{bm_aggregate}()}, 35 | \code{\link{bm_collect}()}, 36 | \code{\link{bm_const}()}, 37 | \code{\link{bm_factor}()}, 38 | \code{\link{bm_fm_mesh_1d}}, 39 | \code{\link{bm_fmesher}()}, 40 | \code{\link{bm_harmonics}()}, 41 | \code{\link{bm_index}()}, 42 | \code{\link{bm_linear}()}, 43 | \code{\link{bm_logitaverage}()}, 44 | \code{\link{bm_logsumexp}()}, 45 | \code{\link{bm_marginal}()}, 46 | \code{\link{bm_matrix}()}, 47 | \code{\link{bm_multi}()}, 48 | \code{\link{bm_pipe}()}, 49 | \code{\link{bm_repeat}()}, 50 | \code{\link{bm_scale}()}, 51 | \code{\link{bm_shift}()}, 52 | \code{\link{bm_sum}()}, 53 | \code{\link{bm_taylor}()}, 54 | \code{\link{bru_get_mapper}()}, 55 | \code{\link{bru_mapper}()} 56 | } 57 | \concept{mappers} 58 | -------------------------------------------------------------------------------- /man/bm_shift.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mappers.R 3 | \name{bm_shift} 4 | \alias{bm_shift} 5 | \alias{bru_mapper_shift} 6 | \title{Mapper for element-wise shifting} 7 | \usage{ 8 | bm_shift(mapper = NULL) 9 | 10 | bru_mapper_shift(...) 11 | } 12 | \arguments{ 13 | \item{mapper}{If non-NULL, a \code{bru_mapper} to be shifted.} 14 | 15 | \item{\dots}{Arguments passed on to \code{\link[=bm_shift]{bm_shift()}}} 16 | } 17 | \description{ 18 | Create a standalone 19 | shift mapper that can be used as part of a \code{bm_pipe}. 20 | If \code{mapper} is non-null, the \code{bm_shift()} constructor 21 | returns 22 | \code{bm_pipe(list(mapper = mapper, shift = bm_shift()))} 23 | } 24 | \examples{ 25 | m <- bm_shift() 26 | ibm_eval2(m, c(1, 2, 1, 2), 1:4) 27 | 28 | } 29 | \seealso{ 30 | \link{bru_mapper}, \link{bru_mapper_generics} 31 | 32 | Other mappers: 33 | \code{\link{bm_aggregate}()}, 34 | \code{\link{bm_collect}()}, 35 | \code{\link{bm_const}()}, 36 | \code{\link{bm_factor}()}, 37 | \code{\link{bm_fm_mesh_1d}}, 38 | \code{\link{bm_fmesher}()}, 39 | \code{\link{bm_harmonics}()}, 40 | \code{\link{bm_index}()}, 41 | \code{\link{bm_linear}()}, 42 | \code{\link{bm_logitaverage}()}, 43 | \code{\link{bm_logsumexp}()}, 44 | \code{\link{bm_marginal}()}, 45 | \code{\link{bm_matrix}()}, 46 | \code{\link{bm_multi}()}, 47 | \code{\link{bm_pipe}()}, 48 | \code{\link{bm_reparam}()}, 49 | \code{\link{bm_repeat}()}, 50 | \code{\link{bm_scale}()}, 51 | \code{\link{bm_sum}()}, 52 | \code{\link{bm_taylor}()}, 53 | \code{\link{bru_get_mapper}()}, 54 | \code{\link{bru_mapper}()} 55 | 56 | Other specific \link{bm_shift} method implementations: 57 | \code{\link{ibm_eval}()}, 58 | \code{\link{ibm_jacobian}()}, 59 | \code{\link{ibm_n}()}, 60 | \code{\link{ibm_n_output}()}, 61 | \code{\link{ibm_values}()} 62 | } 63 | \concept{mappers} 64 | \concept{specific \link{bm_shift} method implementations} 65 | -------------------------------------------------------------------------------- /R/inlabru-package.R: -------------------------------------------------------------------------------- 1 | #' inlabru 2 | #' 3 | #' Convenient model fitting using (iterated) INLA. 4 | #' 5 | #' @details 6 | #' 7 | #' `inlabru` facilitates Bayesian spatial modelling using integrated nested 8 | #' Laplace approximations. It is heavily based on R-inla 9 | #' () but adds additional modelling abilities and 10 | #' simplified syntax for (in particular) spatial models. 11 | #' Tutorials and more information can be found at 12 | #' and . 13 | #' The iterative method used for non-linear predictors is documented in the 14 | #' `method` vignette. 15 | #' 16 | #' The main function for inference using inlabru is [bru()]. 17 | #' The general model specification details is documented in [bru_comp()] 18 | #' and [bru_obs()]. 19 | #' Posterior quantities beyond the basic summaries can be calculated with 20 | #' a `predict()` method, documented in [predict.bru()]. 21 | #' For point process inference [lgcp()] can be used as a shortcut to 22 | #' `bru(..., bru_obs(model="cp", ...))`. 23 | #' 24 | #' The package comes with multiple real world data sets, namely [gorillas], 25 | #' [gorillas_sf], [mexdolphin_sf]. Plotting these data 26 | #' sets is straight forward using inlabru's extensions 27 | #' to `ggplot2`, e.g. the [gg()] function. For educational purposes some 28 | #' simulated data sets are available as well, e.g. [Poisson1_1D], 29 | #' [Poisson2_1D], [Poisson2_1D] and [toygroups]. 30 | #' 31 | #' @aliases inlabru 32 | #' @import stats 33 | #' @import methods 34 | #' @importFrom Matrix diag 35 | #' @import fmesher 36 | #' @importFrom glue glue 37 | #' @importFrom glue glue_data 38 | #' @importFrom glue glue_collapse 39 | #' @author Fabian E. Bachl \email{bachlfab@@gmail.com} 40 | #' and Finn Lindgren \email{finn.lindgren@@gmail.com} 41 | "_PACKAGE" 42 | 43 | ## usethis namespace: start 44 | #' @importFrom lifecycle deprecated 45 | ## usethis namespace: end 46 | NULL 47 | -------------------------------------------------------------------------------- /man/bru_used_vars.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/used.R 3 | \name{bru_used_vars} 4 | \alias{bru_used_vars} 5 | \alias{bru_used_vars.character} 6 | \alias{bru_used_vars.expression} 7 | \alias{bru_used_vars.quosure} 8 | \alias{bru_used_vars.formula} 9 | \title{Extract basic variable names from expression} 10 | \usage{ 11 | bru_used_vars(x, functions = FALSE) 12 | 13 | \method{bru_used_vars}{character}(x, functions = FALSE) 14 | 15 | \method{bru_used_vars}{expression}(x, functions = FALSE) 16 | 17 | \method{bru_used_vars}{quosure}(x, functions = FALSE) 18 | 19 | \method{bru_used_vars}{formula}(x, functions = FALSE) 20 | } 21 | \arguments{ 22 | \item{x}{A \code{formula}, \code{expression}, or \code{character}} 23 | 24 | \item{functions}{logical; if TRUE, include function names} 25 | } 26 | \value{ 27 | If successful, a character vector, otherwise \code{NULL} 28 | } 29 | \description{ 30 | Extracts the variable names from an R expression by pre- and post-processing 31 | around \code{\link[=all.vars]{all.vars()}}. 32 | First replaces \code{$} with \code{[[} indexing, so that internal column/variable names 33 | are ignored, then calls \code{all.vars()}. 34 | } 35 | \section{Methods (by class)}{ 36 | \itemize{ 37 | \item \code{bru_used_vars(formula)}: Only the right-hand side is used. 38 | 39 | }} 40 | \examples{ 41 | bru_used_vars(~.) 42 | bru_used_vars(~ a + b + c_latent + d_eval()) 43 | bru_used_vars(expression(a + b + c_latent + d_eval())) 44 | 45 | bru_used_vars(~., functions = TRUE) 46 | bru_used_vars(~ a + b + c_latent + d_eval(), functions = TRUE) 47 | bru_used_vars(expression(a + b + c_latent + d_eval()), functions = TRUE) 48 | 49 | bru_used_vars(a ~ b) 50 | bru_used_vars(expression(a ~ b)) 51 | 52 | } 53 | \seealso{ 54 | Other bru_used: 55 | \code{\link{bru_used}()}, 56 | \code{\link{bru_used_update}()}, 57 | \code{\link{new_bru_used}()} 58 | } 59 | \concept{bru_used} 60 | \keyword{internal} 61 | -------------------------------------------------------------------------------- /man/bm_matrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mappers.R 3 | \name{bm_matrix} 4 | \alias{bm_matrix} 5 | \alias{bru_mapper_matrix} 6 | \title{Mapper for matrix multiplication} 7 | \usage{ 8 | bm_matrix(labels) 9 | 10 | bru_mapper_matrix(...) 11 | } 12 | \arguments{ 13 | \item{labels}{Column labels for matrix mappings; Can be factor, character, or 14 | a single integer specifying the number of columns for integer column 15 | indexing.} 16 | 17 | \item{\dots}{Arguments passed on to \code{\link[=bm_matrix]{bm_matrix()}}} 18 | } 19 | \description{ 20 | Create a matrix mapper, for a given number of columns 21 | } 22 | \examples{ 23 | m <- bm_matrix(labels = c("a", "b")) 24 | ibm_values(m) 25 | ibm_eval2(m, input = matrix(1:6, 3, 2), state = 2:3) 26 | 27 | m <- bm_matrix(labels = 2L) 28 | ibm_values(m) 29 | ibm_eval2(m, input = matrix(1:6, 3, 2), state = 2:3) 30 | 31 | } 32 | \seealso{ 33 | \link{bru_mapper}, \link{bru_mapper_generics} 34 | 35 | Other mappers: 36 | \code{\link{bm_aggregate}()}, 37 | \code{\link{bm_collect}()}, 38 | \code{\link{bm_const}()}, 39 | \code{\link{bm_factor}()}, 40 | \code{\link{bm_fm_mesh_1d}}, 41 | \code{\link{bm_fmesher}()}, 42 | \code{\link{bm_harmonics}()}, 43 | \code{\link{bm_index}()}, 44 | \code{\link{bm_linear}()}, 45 | \code{\link{bm_logitaverage}()}, 46 | \code{\link{bm_logsumexp}()}, 47 | \code{\link{bm_marginal}()}, 48 | \code{\link{bm_multi}()}, 49 | \code{\link{bm_pipe}()}, 50 | \code{\link{bm_reparam}()}, 51 | \code{\link{bm_repeat}()}, 52 | \code{\link{bm_scale}()}, 53 | \code{\link{bm_shift}()}, 54 | \code{\link{bm_sum}()}, 55 | \code{\link{bm_taylor}()}, 56 | \code{\link{bru_get_mapper}()}, 57 | \code{\link{bru_mapper}()} 58 | 59 | Other specific \link{bm_matrix} method implementations: 60 | \code{\link{ibm_jacobian}()}, 61 | \code{\link{ibm_n}()}, 62 | \code{\link{ibm_values}()} 63 | } 64 | \concept{mappers} 65 | \concept{specific \link{bm_matrix} method implementations} 66 | -------------------------------------------------------------------------------- /vignettes/articles.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Articles list" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Articles list} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | ```{r, include = FALSE} 11 | knitr::opts_chunk$set( 12 | collapse = TRUE, 13 | comment = "#>" 14 | ) 15 | ``` 16 | 17 | ```{r setup, echo=FALSE,include=FALSE} 18 | ``` 19 | 20 | ## Package vignettes 21 | 22 | These package vignettes are available in the R package and on 23 | [`https://inlabru-org.github.io/inlabru/`](https://inlabru-org.github.io/inlabru/) 24 | 25 | ```{r, echo=FALSE,results="asis"} 26 | files <- list.files(".", "\\.Rmd$") 27 | for (file in files) { 28 | lines <- readLines(file, n = 10) 29 | title_idx <- grep("^title: ", lines) 30 | if (length(title_idx) > 0) { 31 | title <- sub("^title: ", "", lines[title_idx[1]]) 32 | title <- sub('^"', "", title) 33 | title <- sub('"$', "", title) 34 | cat("* [", 35 | title, 36 | "](https://inlabru-org.github.io/inlabru/articles/", 37 | sub("\\.Rmd", ".html", file), 38 | ")\n", 39 | sep = "" 40 | ) 41 | } 42 | } 43 | ``` 44 | 45 | ## Package examples 46 | 47 | These potentially long running examples/tutorials are available on 48 | [`https://inlabru-org.github.io/inlabru/`](https://inlabru-org.github.io/inlabru/) 49 | 50 | ```{r, echo=FALSE,results="asis"} 51 | files <- list.files("articles", "\\.Rmd$") 52 | for (file in file.path("articles", files)) { 53 | lines <- readLines(file, n = 10) 54 | title_idx <- grep("^title: ", lines) 55 | if (length(title_idx) > 0) { 56 | title <- sub("^title: ", "", lines[title_idx[1]]) 57 | title <- sub('^"', "", title) 58 | title <- sub('"$', "", title) 59 | cat("* [", 60 | title, 61 | "](https://inlabru-org.github.io/inlabru/articles/", 62 | sub("\\.Rmd", ".html", basename(file)), 63 | ")\n", 64 | sep = "" 65 | ) 66 | } 67 | } 68 | ``` 69 | 70 | -------------------------------------------------------------------------------- /man/as_bru_comp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bru_conversion.R 3 | \name{as_bru_comp} 4 | \alias{as_bru_comp} 5 | \alias{as_bru_comp_list} 6 | \alias{as_bru_comp.bru_comp} 7 | \alias{as_bru_comp_list.bru_comp_list} 8 | \alias{as_bru_comp_list.bru_comp} 9 | \alias{as_bru_comp_list.bru} 10 | \alias{as_bru_comp_list.bru_info} 11 | \alias{as_bru_comp_list.bru_model} 12 | \alias{as_bru_comp_list.list} 13 | \alias{as_bru_comp_list.formula} 14 | \title{Conversion methods for \code{bru_comp} and \code{bru_comp_list} objects} 15 | \usage{ 16 | as_bru_comp(x, ...) 17 | 18 | as_bru_comp_list(x, ...) 19 | 20 | \method{as_bru_comp}{bru_comp}(x, ...) 21 | 22 | \method{as_bru_comp_list}{bru_comp_list}(x, ...) 23 | 24 | \method{as_bru_comp_list}{bru_comp}(x, ...) 25 | 26 | \method{as_bru_comp_list}{bru}(x, ...) 27 | 28 | \method{as_bru_comp_list}{bru_info}(x, ...) 29 | 30 | \method{as_bru_comp_list}{bru_model}(x, ...) 31 | 32 | \method{as_bru_comp_list}{list}(x, ...) 33 | 34 | \method{as_bru_comp_list}{formula}(x, ...) 35 | } 36 | \arguments{ 37 | \item{x}{An object to convert to \link{bru_comp} or \link{bru_comp_list}} 38 | 39 | \item{\dots}{Additional arguments passed on to \code{\link[=bru_comp_list]{bru_comp_list()}}.} 40 | } 41 | \value{ 42 | An object of class \link{bru_comp_list}. 43 | } 44 | \description{ 45 | Methods for converting to \code{bru_comp} and \code{bru_comp_list} 46 | objects. 47 | } 48 | \section{Functions}{ 49 | \itemize{ 50 | \item \code{as_bru_comp_list(bru)}: Extract the component list from a \code{\link[=bru]{bru()}} object. 51 | 52 | \item \code{as_bru_comp_list(bru_info)}: Extract the component list from a \code{\link[=bru_info]{bru_info()}} 53 | object. 54 | 55 | \item \code{as_bru_comp_list(bru_model)}: Extract the component list from a \code{\link[=bru_model]{bru_model()}} 56 | object. 57 | 58 | }} 59 | \seealso{ 60 | \code{\link[=as_bru_obs]{as_bru_obs()}}, \code{\link[=as_bru_obs_list]{as_bru_obs_list()}} 61 | } 62 | -------------------------------------------------------------------------------- /man/spoly.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bru_sp.R 3 | \name{spoly} 4 | \alias{spoly} 5 | \title{Convert a data.frame of boundary points into a SpatialPolgonsDataFrame} 6 | \usage{ 7 | spoly( 8 | data, 9 | cols = colnames(data)[1:2], 10 | crs = fm_crs(), 11 | to.crs = NULL, 12 | format = c("sp", "sf") 13 | ) 14 | } 15 | \arguments{ 16 | \item{data}{A data.frame of points describing the boundary of the polygon 17 | (unique points, no holes)} 18 | 19 | \item{cols}{Column names of the x and y coordinates within the data} 20 | 21 | \item{crs}{Coordinate reference system of the points} 22 | 23 | \item{to.crs}{Coordinate reference system for the \code{SpatialLines}/\code{sf} ouput.} 24 | 25 | \item{format}{Format of the output object. Either "sp" (default) or "sf"} 26 | } 27 | \value{ 28 | \code{sp::SpatialPolygonsDataFrame} or \link[sf:sf]{sf::sf} 29 | } 30 | \description{ 31 | A polygon can be described as a sequence of points defining the polygon's 32 | boundary. When given such a sequence (anti clockwise!) this function creates 33 | a \code{SpatialPolygonsDataFrame} or \code{sf} holding the polygon decribed. By 34 | default, the first two columns of \code{data} are assumed to define the x and y 35 | coordinates of the points. This behaviour can be changed using the \code{cols} 36 | parameter, which points out the names of the columns holding the coordinates. 37 | The coordinate reference system of the resulting spatial polygon can be set 38 | via the \code{crs} parameter. Posterior conversion to a different CRS is supported 39 | using the \code{to.crs} parameter. 40 | } 41 | \examples{ 42 | \donttest{ 43 | # Create data frame of boundary points (anti clockwise!) 44 | pts <- data.frame( 45 | x = c(1, 2, 1.7, 1.3), 46 | y = c(1, 1, 2, 2) 47 | ) 48 | 49 | # Convert to sf 50 | pol <- spoly(pts, format = "sf") 51 | 52 | if (require(ggplot2, quietly = TRUE)) { 53 | # Plot it! 54 | ggplot() + 55 | gg(pol) 56 | } 57 | } 58 | 59 | } 60 | \keyword{internal} 61 | -------------------------------------------------------------------------------- /man/toygroups.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.toygroups.R 3 | \docType{data} 4 | \name{toygroups} 5 | \alias{toygroups} 6 | \title{Simulated 1D animal group locations and group sizes} 7 | \format{ 8 | The data are a list that contains these elements: 9 | \describe{ 10 | \item{\code{groups}:}{ A \code{data.frame} of group locations \code{x} and size \code{size}} 11 | \item{\code{df.size}:}{ IGNORE THIS } 12 | \item{\code{df.intensity}:}{ A \code{data.frame} with Poisson process 13 | intensity \code{d.lambda} at locations \code{x}} 14 | \item{\code{df.rate}:}{ A \code{data.frame} the locations \code{x} and associated \code{rate} 15 | which parameterized the exponential distribution from which the group 16 | sizes were drawn.} 17 | } 18 | } 19 | \usage{ 20 | data(toygroups) 21 | } 22 | \description{ 23 | This data set serves to teach the concept of modelling species that gather in 24 | groups and where the grouping behaviour depends on space. 25 | } 26 | \examples{ 27 | \donttest{ 28 | if (require(ggplot2, quietly = TRUE)) { 29 | # Load the data 30 | 31 | data("toygroups", package = "inlabru") 32 | 33 | # The data set is a simulation of animal groups residing in a 1D space. Their 34 | # locations in x-space are sampled from a Cox process with intensity 35 | 36 | ggplot(toygroups$df.intensity) + 37 | geom_line(aes(x = x, y = g.lambda)) 38 | 39 | # Adding the simulated group locations to this plot we obtain 40 | 41 | ggplot(toygroups$df.intensity) + 42 | geom_line(aes(x = x, y = g.lambda)) + 43 | geom_point(data = toygroups$groups, aes(x, y = 0), pch = "|") 44 | 45 | # Each group has a size mark attached to it. 46 | # These group sizes are sampled from an exponential distribution 47 | # for which the rate parameter depends on the x-coordinate 48 | 49 | ggplot(toygroups$groups) + 50 | geom_point(aes(x = x, y = size)) 51 | 52 | ggplot(toygroups$df.rate) + 53 | geom_line(aes(x, rate)) 54 | } 55 | } 56 | } 57 | \keyword{datasets} 58 | -------------------------------------------------------------------------------- /man/ibm_input.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bru_input.R 3 | \name{ibm_input} 4 | \alias{ibm_input} 5 | \alias{ibm_input_set} 6 | \alias{ibm_input_new} 7 | \alias{ibm_input_available} 8 | \alias{ibm_input_get} 9 | \alias{bm_autodetect} 10 | \title{Interface between \code{bru_input} and \code{bru_mapper}} 11 | \usage{ 12 | ibm_input_set(mapper, input) 13 | 14 | ibm_input_new(mapper, ...) 15 | 16 | ibm_input_available(mapper) 17 | 18 | ibm_input_get(mapper) 19 | 20 | bm_autodetect() 21 | } 22 | \arguments{ 23 | \item{mapper}{A \code{bru_mapper} object.} 24 | 25 | \item{input}{A \code{bru_input} object, or \code{NULL} to remove any existing input. 26 | Alternatively, an existing \code{bru_mapper} object with or without associated 27 | input can be provided, in which case the input from that mapper 28 | is copied.} 29 | 30 | \item{\dots}{Passed on to \code{\link[=new_bru_input]{new_bru_input()}}.} 31 | } 32 | \description{ 33 | Associate \link{bru_input} objects with \link{bru_mapper} objects. 34 | } 35 | \section{Functions}{ 36 | \itemize{ 37 | \item \code{ibm_input_set()}: Add an existing \code{bru_input} to a \code{bru_mapper}. 38 | 39 | \item \code{ibm_input_new()}: Create and add a \code{bru_input} to a \code{bru_mapper}. 40 | 41 | \item \code{ibm_input_available()}: Check if a \code{bru_input} is associated with a 42 | \code{bru_mapper}. 43 | 44 | \item \code{ibm_input_get()}: Get the \code{bru_input} associated with a \code{bru_mapper}. 45 | 46 | \item \code{bm_autodetect()}: Create a \code{bru_mapper} placeholder object of class 47 | \code{bm_autodetect}. The main purpose of this class is to attach \link{bru_input} 48 | information to it, which is later used to determine a suitable 'real' 49 | mapper type. 50 | 51 | }} 52 | \examples{ 53 | (m <- bm_autodetect()) 54 | ibm_input_available(m) 55 | (m <- ibm_input_new(m, cos(x))) 56 | ibm_input_available(m) 57 | ibm_input_set(bm_linear(), m) 58 | 59 | } 60 | \seealso{ 61 | \code{\link[=bru_input]{bru_input()}} 62 | } 63 | -------------------------------------------------------------------------------- /misc/apmaker.R: -------------------------------------------------------------------------------- 1 | # https://github.com/inlabru-org/inlabru/issues/125 2 | 3 | # TODO 20220126should not be a S3 but local function and function name should be clearer 4 | # bru_log_list function --------------------------------------------------------- 5 | # How does sf deal with secondary geometry columns? 6 | # TODO #### 7 | # TODO have to deal with the multidomain samplers 8 | # https://r-spatial.github.io/sf/articles/sf6.html 9 | # TODO #### extra domains we assign the sampler for them 10 | # TODO can use local helper function (with S3 Usemethod() maybe) 11 | 12 | # @param start_with The message starts with 13 | # @param end_with The message ends with 14 | # @verbosity Default: 2 15 | # @ verbose_store Default: T 16 | bru_log_list <- function(x, attr_names = "sf_column", start_with = NULL, end_with = NULL) { 17 | for (i in seq_along(x)) { 18 | bru_log_message( 19 | paste0( 20 | start_with, 21 | i, 22 | " is/are ", 23 | attr(x[[i]], attr_names), 24 | end_with, 25 | ".\n" 26 | ), 27 | verbosity = 2, verbose_store = T 28 | ) 29 | } 30 | } 31 | 32 | # devtools::load_all() 33 | # data(mrsea, package = "inlabru") 34 | # domain = list(coordinates = mrsea$mesh, 35 | # season = seq_len(4)) 36 | # samplers <- mrsea$samplers 37 | # samplers <- list(season = samplers$season, samplers) 38 | # debugonce(inlabru:::apmaker) 39 | # apmaker(samplers=samplers, domain=domain, response="coordinate") 40 | 41 | # TODO Extend S3 method with names_list??? 42 | # https://stackoverflow.com/questions/18513607/how-to-extend-s3-method-from-another-package-without-loading-the-package 43 | # to deal with samplers names in a dataframe 20230126 44 | # 1) do I need the names of the list or the names within the list(s)? 45 | # 2) Does column names mean sth here? 46 | # 3) What to do with NULL cases, aka unamed list? 47 | # @name names 48 | # @export names_list 49 | # @title Names within list(s) 50 | # 51 | names_list <- function(x) { 52 | lapply(x, function(y) { 53 | names(y) 54 | }) 55 | } 56 | -------------------------------------------------------------------------------- /man/gg.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ggplot.R 3 | \name{gg} 4 | \alias{gg} 5 | \title{ggplot2 geomes for inlabru related objects} 6 | \usage{ 7 | gg(data, ...) 8 | } 9 | \arguments{ 10 | \item{data}{an object for which to generate a geom.} 11 | 12 | \item{\dots}{Arguments passed on to the geom method.} 13 | } 14 | \value{ 15 | The form of the value returned by gg depends on the class of its 16 | argument. See the documentation of the particular methods for details of 17 | what is produced by that method. 18 | } 19 | \description{ 20 | gg is a generic function for generating geomes from various kinds of spatial 21 | objects, e.g. Spatial* data, meshes, Raster objects and inla/inlabru 22 | predictions. The function invokes particular methods which depend on the 23 | \link{class} of the first argument. 24 | } 25 | \examples{ 26 | if (require("ggplot2", quietly = TRUE)) { 27 | # Load Gorilla data 28 | 29 | gorillas <- inlabru::gorillas_sf 30 | 31 | # Invoke ggplot and add geomes for the Gorilla nests and the survey 32 | # boundary 33 | 34 | ggplot() + 35 | gg(gorillas$boundary) + 36 | gg(gorillas$nests) 37 | } 38 | } 39 | \seealso{ 40 | Other geomes for inla and inlabru predictions: 41 | \code{\link{gg.bru_prediction}()}, 42 | \code{\link{gg.data.frame}()}, 43 | \code{\link{gg.matrix}()} 44 | 45 | Other geomes for spatial data: 46 | \code{\link{gg.SpatRaster}()}, 47 | \code{\link{gg.SpatialGridDataFrame}()}, 48 | \code{\link{gg.SpatialLines}()}, 49 | \code{\link{gg.SpatialPixels}()}, 50 | \code{\link{gg.SpatialPixelsDataFrame}()}, 51 | \code{\link{gg.SpatialPoints}()}, 52 | \code{\link{gg.SpatialPolygons}()}, 53 | \code{\link{gg.sf}()} 54 | 55 | Other geomes for meshes: 56 | \code{\link{gg.fm_mesh_1d}()}, 57 | \code{\link{gg.fm_mesh_2d}()} 58 | 59 | Other geomes for Raster data: 60 | \code{\link{gg.RasterLayer}()} 61 | } 62 | \concept{geomes for Raster data} 63 | \concept{geomes for inla and inlabru predictions} 64 | \concept{geomes for meshes} 65 | \concept{geomes for spatial data} 66 | -------------------------------------------------------------------------------- /tests/testthat/test-utils.R: -------------------------------------------------------------------------------- 1 | test_that("Missing data infilling", { 2 | skip_on_cran() 3 | local_bru_safe_inla() 4 | skip_if_not(bru_safe_sp()) 5 | skip_if_not_installed("terra") 6 | 7 | points <- 8 | sp::SpatialPointsDataFrame( 9 | matrix(1:6, 3, 2), 10 | data = data.frame(val = c(NA, NA, NA)) 11 | ) 12 | input_coord <- expand.grid(x = 0:6, y = 0:7) 13 | input_data <- data.frame(val = as.vector(input_coord$y)) 14 | input <- 15 | sp::SpatialPixelsDataFrame( 16 | input_coord, 17 | data = input_data 18 | ) 19 | 20 | val0 <- bru_fill_missing(input, points, points$val) 21 | 22 | input <- 23 | sp::SpatialPointsDataFrame( 24 | input_coord, 25 | data = input_data 26 | ) 27 | val2 <- bru_fill_missing(input, points, points$val) 28 | 29 | expect_equal(val2, val0) 30 | 31 | input <- sp::SpatialGrid(sp::GridTopology(c(0, 0), c(1, 1), c(7, 8))) 32 | input_data <- data.frame(val = as.vector(sp::coordinates(input)[, 2])) 33 | input <- 34 | sp::SpatialGridDataFrame( 35 | input, 36 | data = input_data 37 | ) 38 | val2 <- bru_fill_missing(input, points, points$val) 39 | 40 | expect_equal(val2, val0) 41 | }) 42 | 43 | 44 | test_that("Laplace distribution", { 45 | q <- -5:5 46 | rate <- 2 47 | p <- plaplace(q, rate = rate) 48 | 49 | expect_equal(plaplace(q, rate = rate, lower.tail = TRUE), p) 50 | expect_equal(plaplace(-q, rate = rate, lower.tail = FALSE), p) 51 | expect_equal( 52 | plaplace(q, rate = rate, lower.tail = TRUE, log.p = TRUE), 53 | log(p) 54 | ) 55 | expect_equal( 56 | plaplace(-q, rate = rate, lower.tail = FALSE, log.p = TRUE), 57 | log(p) 58 | ) 59 | expect_equal(qlaplace(p, rate = rate, lower.tail = TRUE), q) 60 | expect_equal(qlaplace(p, rate = rate, lower.tail = FALSE), -q) 61 | expect_equal( 62 | qlaplace(log(p), rate = rate, lower.tail = TRUE, log.p = TRUE), 63 | q 64 | ) 65 | expect_equal( 66 | qlaplace(log(p), rate = rate, lower.tail = FALSE, log.p = TRUE), 67 | -q 68 | ) 69 | }) 70 | -------------------------------------------------------------------------------- /man/bru_convergence_plot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/track_plotting.R 3 | \name{bru_convergence_plot} 4 | \alias{bru_convergence_plot} 5 | \title{Plot inlabru convergence diagnostics} 6 | \usage{ 7 | bru_convergence_plot(x, from = 1, to = NULL, type = NULL) 8 | } 9 | \arguments{ 10 | \item{x}{a \link{bru} object, typically a result from \code{\link[=bru]{bru()}} for a nonlinear 11 | predictor model} 12 | 13 | \item{from, to}{integer values for the range of iterations to plot. 14 | Default \code{from = 1} (start from the first iteration) and \code{to = NULL} (end at 15 | the last iteration). 16 | Set \code{from = 0} to include the initial linearisation point in the track plot.} 17 | 18 | \item{type}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} character; "bru" (default) 19 | for iterative nonlinear inlabru convergence diagnostics plots, or "inla" 20 | for INLA optimiser trace plots.} 21 | } 22 | \value{ 23 | A ggplot object with four panels of convergence diagnostics: 24 | \itemize{ 25 | \item \code{Tracks}: Mode and linearisation values for each effect 26 | \item \code{Mode - Lin}: Difference between mode and linearisation values for each 27 | effect 28 | \item \verb{|Change| / sd}: Absolute change in mode and linearisation values 29 | divided by the standard deviation for each effect 30 | \item \code{Change & sd}: Absolute change in mode and linearisation values 31 | and standard deviation for each effect 32 | } 33 | 34 | For multidimensional components, only the overall average, maximum, and 35 | minimum values are shown. 36 | } 37 | \description{ 38 | Draws four panels of convergence diagnostics for an iterated INLA method 39 | estimation 40 | } 41 | \details{ 42 | Requires the "dplyr", "ggplot2", and "patchwork" 43 | packages to be installed. 44 | } 45 | \examples{ 46 | \dontrun{ 47 | fit <- bru(...) 48 | bru_convergence_plot(fit) 49 | } 50 | } 51 | \seealso{ 52 | \code{\link[=bru]{bru()}} 53 | } 54 | -------------------------------------------------------------------------------- /man/bru_model_mapper_methods.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/model.R 3 | \name{bru_model_mapper_methods} 4 | \alias{bru_model_mapper_methods} 5 | \alias{ibm_linear.bru_model} 6 | \alias{ibm_linear.bru_comp_list} 7 | \alias{ibm_simplify.bru_model} 8 | \alias{ibm_simplify.bru_comp} 9 | \alias{ibm_simplify.bru_comp_list} 10 | \alias{ibm_linear.bm_list} 11 | \alias{ibm_simplify.bm_list} 12 | \title{Mapper methods for model objects} 13 | \usage{ 14 | \method{ibm_linear}{bru_model}(mapper, input, state = NULL, ...) 15 | 16 | \method{ibm_linear}{bru_comp_list}(mapper, input, state = NULL, ...) 17 | 18 | \method{ibm_simplify}{bru_model}(mapper, input = NULL, state = NULL, ...) 19 | 20 | \method{ibm_simplify}{bru_comp}(mapper, input = NULL, state = NULL, ...) 21 | 22 | \method{ibm_simplify}{bru_comp_list}(mapper, input = NULL, state = NULL, ...) 23 | 24 | \method{ibm_linear}{bm_list}(mapper, input, state = NULL, ...) 25 | 26 | \method{ibm_simplify}{bm_list}(mapper, input = NULL, state = NULL, ...) 27 | } 28 | \arguments{ 29 | \item{mapper}{A mapper S3 object, inheriting from \code{bru_mapper}.} 30 | 31 | \item{input}{Data input for the mapper.} 32 | 33 | \item{state}{A vector of latent state values for the mapping, 34 | of length \code{ibm_n(mapper, inla_f = FALSE)}} 35 | 36 | \item{...}{Arguments passed on to other methods} 37 | } 38 | \description{ 39 | Methods for the \code{ibm_linear()} and \code{ibm_simplify()} methods for 40 | \link{bru} model objects and related classes. 41 | } 42 | \section{Functions}{ 43 | \itemize{ 44 | \item \code{ibm_linear(bru_model)}: Returns a list (one element per 45 | observation model) of \link{bm_list} objects, each with one \link{bm_taylor} 46 | entry for each included component. 47 | 48 | \item \code{ibm_simplify(bru_model)}: Returns a list (one element per 49 | observation model) of \link{bm_list} objects, each with one \link{bru_mapper} 50 | entry for each included component. 51 | 52 | }} 53 | \concept{specific \link{bm_list} mapper method implementations} 54 | \concept{specific \link{bru_comp_list} mapper method implementations} 55 | -------------------------------------------------------------------------------- /man/bm_pipe.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mappers.R 3 | \name{bm_pipe} 4 | \alias{bm_pipe} 5 | \alias{bru_mapper_pipe} 6 | \title{Mapper for linking several mappers in sequence} 7 | \usage{ 8 | bm_pipe(mappers) 9 | 10 | bru_mapper_pipe(...) 11 | } 12 | \arguments{ 13 | \item{mappers}{A list of \code{bru_mapper} objects} 14 | 15 | \item{\dots}{Arguments passed on to \code{\link[=bm_pipe]{bm_pipe()}}} 16 | } 17 | \description{ 18 | Create a pipe mapper, where \code{mappers} is a list of mappers, 19 | and the evaluated output of each mapper is handed as the state to the next 20 | mapper. 21 | The \code{input} format for the \code{ibm_eval} and \code{ibm_jacobian} methods is 22 | a list of inputs, one for each mapper. 23 | } 24 | \examples{ 25 | m <- bm_pipe(list( 26 | scale = bm_scale(), 27 | shift = bm_shift() 28 | )) 29 | ibm_eval2(m, input = list(scale = 2, shift = 1:4), state = 1:4) 30 | 31 | } 32 | \seealso{ 33 | \link{bru_mapper}, \link{bru_mapper_generics} 34 | 35 | Other mappers: 36 | \code{\link{bm_aggregate}()}, 37 | \code{\link{bm_collect}()}, 38 | \code{\link{bm_const}()}, 39 | \code{\link{bm_factor}()}, 40 | \code{\link{bm_fm_mesh_1d}}, 41 | \code{\link{bm_fmesher}()}, 42 | \code{\link{bm_harmonics}()}, 43 | \code{\link{bm_index}()}, 44 | \code{\link{bm_linear}()}, 45 | \code{\link{bm_logitaverage}()}, 46 | \code{\link{bm_logsumexp}()}, 47 | \code{\link{bm_marginal}()}, 48 | \code{\link{bm_matrix}()}, 49 | \code{\link{bm_multi}()}, 50 | \code{\link{bm_reparam}()}, 51 | \code{\link{bm_repeat}()}, 52 | \code{\link{bm_scale}()}, 53 | \code{\link{bm_shift}()}, 54 | \code{\link{bm_sum}()}, 55 | \code{\link{bm_taylor}()}, 56 | \code{\link{bru_get_mapper}()}, 57 | \code{\link{bru_mapper}()} 58 | 59 | Other specific \link{bm_pipe} method implementations: 60 | \code{\link{ibm_eval}()}, 61 | \code{\link{ibm_eval2}()}, 62 | \code{\link{ibm_jacobian}()}, 63 | \code{\link{ibm_n}()}, 64 | \code{\link{ibm_n_output}()}, 65 | \code{\link{ibm_simplify}()}, 66 | \code{\link{ibm_values}()} 67 | } 68 | \concept{mappers} 69 | \concept{specific \link{bm_pipe} method implementations} 70 | -------------------------------------------------------------------------------- /man/bm_repeat_indexing.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mapper_repeat.R 3 | \name{bm_repeat_indexing} 4 | \alias{bm_repeat_indexing} 5 | \alias{bm_repeat_indexing_matrix} 6 | \title{Re-indexing matrix for repeated mappers} 7 | \usage{ 8 | bm_repeat_indexing(n_map, n_rep, interleaved = FALSE) 9 | 10 | bm_repeat_indexing_matrix(n_map, n_rep) 11 | } 12 | \arguments{ 13 | \item{n_map}{The block mapper size} 14 | 15 | \item{n_rep}{The number of times the block is repeated} 16 | 17 | \item{interleaved}{logical; if \code{TRUE}, the state vector indexing is 18 | interleaved. Default is \code{FALSE}, for blockwise indexing.} 19 | } 20 | \value{ 21 | \code{bm_repeat_indexing}: Returns a list with a vector of offsets, 22 | \code{offsets}, and a vector of relative index values, \code{index}; block \code{k} 23 | indexing is given by \code{offsets[k] + index}. 24 | 25 | \code{bm_repeat_indexing_matrix}: A \code{sparseMatrix} object. 26 | } 27 | \description{ 28 | Helper methods for regular and interleaved state vector 29 | indexing, meant for use in \link{bm_repeat} mappers. 30 | } 31 | \section{Functions}{ 32 | \itemize{ 33 | \item \code{bm_repeat_indexing()}: Construct the offsets and within-block 34 | index vectors for a repeated mapper, with or without interleaving. 35 | 36 | \item \code{bm_repeat_indexing_matrix()}: Creates a sparse matrix \code{A} such that 37 | \code{z <- A \%*\% x} constructs a blockwise version \code{z = c(x1, x2, ..., xn)} of 38 | an interleaved state vector \code{x = c(x1[1], x2[1], ..., x1[2], x2[2], ...)}. 39 | Each block is of size \code{n_map}, and there are \code{n_rep} blocks. The reverse 40 | operation, taking a blockwise \code{z = c(x1, x2, ..., xn)} to an interleaved 41 | vector is \code{x <- Matrix::t(A) \%*\% z}. 42 | 43 | }} 44 | \examples{ 45 | (idx <- bm_repeat_indexing(3, 2, FALSE)) 46 | (idx <- bm_repeat_indexing(3, 2, TRUE)) 47 | (A <- bm_repeat_indexing_matrix(3, 2)) 48 | (x_interleaved <- 1:6) 49 | (x_blockwise <- as.vector(A \%*\% x_interleaved)) 50 | (x_recovered <- as.vector(Matrix::t(A) \%*\% x_blockwise)) 51 | 52 | } 53 | \keyword{internal} 54 | -------------------------------------------------------------------------------- /inst/examples/gg.sp.R: -------------------------------------------------------------------------------- 1 | \donttest{ 2 | if (require("ggplot2", quietly = TRUE) && 3 | requireNamespace("terra", quietly = TRUE) && 4 | bru_safe_sp() && 5 | require("sp")) { 6 | # Load Gorilla data 7 | 8 | gorillas <- inlabru::gorillas_sf 9 | 10 | gcov <- gorillas_sf_gcov() 11 | elev <- terra::as.data.frame(gcov$elevation, xy = TRUE) 12 | elev <- sf::as_Spatial(sf::st_as_sf(elev, coords = c("x", "y"))) 13 | 14 | # Turn elevation covariate into SpatialGridDataFrame 15 | elev <- sp::SpatialPixelsDataFrame(elev, data = as.data.frame(elev)) 16 | 17 | # Plot Gorilla elevation covariate provided as SpatialPixelsDataFrame. 18 | # The same syntax applies to SpatialGridDataFrame objects. 19 | 20 | ggplot() + 21 | gg(elev) 22 | 23 | # Add Gorilla survey boundary and nest sightings 24 | 25 | ggplot() + 26 | gg(elev) + 27 | gg(gorillas$boundary, alpha = 0.0, col = "red") + 28 | gg(gorillas$nests) 29 | 30 | # Load pantropical dolphin data 31 | 32 | mexdolphin <- inlabru::mexdolphin_sp() 33 | 34 | # Plot the pantropical survey boundary, ship transects and dolphin sightings 35 | 36 | ggplot() + 37 | gg(mexdolphin$ppoly) + # survey boundary as SpatialPolygon 38 | gg(mexdolphin$samplers) + # ship transects as SpatialLines 39 | gg(mexdolphin$points) # dolphin sightings as SpatialPoints 40 | 41 | # Change color 42 | 43 | ggplot() + 44 | gg(mexdolphin$ppoly, color = "green") + # survey boundary as SpatialPolygon 45 | gg(mexdolphin$samplers, color = "red") + # ship transects as SpatialLines 46 | gg(mexdolphin$points, color = "blue") # dolphin sightings as SpatialPoints 47 | 48 | 49 | # Visualize data annotations: line width by segment number 50 | 51 | names(mexdolphin$samplers) # 'seg' holds the segment number 52 | ggplot() + 53 | gg(mexdolphin$samplers, aes(color = seg)) 54 | 55 | # Visualize data annotations: point size by dolphin group size 56 | 57 | names(mexdolphin$points) # 'size' holds the group size 58 | ggplot() + 59 | gg(mexdolphin$points, aes(size = size)) 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /inst/examples/bru_obs.R: -------------------------------------------------------------------------------- 1 | \donttest{ 2 | if (bru_safe_inla() && 3 | require(ggplot2, quietly = TRUE)) { 4 | 5 | # The 'bru_obs()' (previously 'like()') function's main purpose is to set up 6 | # observation models, both for single- and multi-likelihood models. 7 | # The following example generates some random covariates which are observed 8 | # through two different random effect models with different likelihoods 9 | 10 | # Generate the data 11 | 12 | set.seed(123) 13 | 14 | n1 <- 200 15 | n2 <- 10 16 | 17 | x1 <- runif(n1) 18 | x2 <- runif(n2) 19 | z2 <- runif(n2) 20 | 21 | y1 <- rnorm(n1, mean = 2 * x1 + 3) 22 | y2 <- rpois(n2, lambda = exp(2 * x2 + z2 + 3)) 23 | 24 | df1 <- data.frame(y = y1, x = x1) 25 | df2 <- data.frame(y = y2, x = x2, z = z2) 26 | 27 | # Single likelihood models and inference using bru are done via 28 | 29 | cmp1 <- y ~ -1 + Intercept(1) + x 30 | fit1 <- bru(cmp1, family = "gaussian", data = df1) 31 | summary(fit1) 32 | 33 | cmp2 <- y ~ -1 + Intercept(1) + x + z 34 | fit2 <- bru(cmp2, family = "poisson", data = df2) 35 | summary(fit2) 36 | 37 | # A joint model has two likelihoods, which are set up using the bru_obs 38 | # function 39 | 40 | lik1 <- bru_obs( 41 | "gaussian", 42 | formula = y ~ x + Intercept, 43 | data = df1, 44 | tag = "norm" 45 | ) 46 | lik2 <- bru_obs( 47 | "poisson", 48 | formula = y ~ x + z + Intercept, 49 | data = df2, 50 | tag = "pois" 51 | ) 52 | 53 | # The union of effects of both models gives the components needed to run bru 54 | 55 | jcmp <- ~ x + z + Intercept(1) 56 | jfit <- bru(jcmp, lik1, lik2) 57 | 58 | bru_index(jfit, "norm") 59 | bru_index(jfit, "pois") 60 | 61 | # Compare the estimates 62 | 63 | p1 <- ggplot() + 64 | gg(fit1$summary.fixed, bar = TRUE) + 65 | ylim(0, 4) + 66 | ggtitle("Model 1") 67 | p2 <- ggplot() + 68 | gg(fit2$summary.fixed, bar = TRUE) + 69 | ylim(0, 4) + 70 | ggtitle("Model 2") 71 | pj <- ggplot() + 72 | gg(jfit$summary.fixed, bar = TRUE) + 73 | ylim(0, 4) + 74 | ggtitle("Joint model") 75 | 76 | multiplot(p1, p2, pj) 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /man/robins_subset.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.robins_subset.R 3 | \docType{data} 4 | \name{robins_subset} 5 | \alias{robins_subset} 6 | \title{robins_subset} 7 | \format{ 8 | The data are a data.frame with variables 9 | \describe{ 10 | \item{\code{circle}:}{ 11 | Four-letter code of the CBC circle. 12 | } 13 | \item{\code{bcr}:}{ 14 | Numeric code for the bird conservation region encompassing the 15 | count circle. 16 | } 17 | \item{\code{state}:}{ 18 | US state encompassing the count circle. 19 | } 20 | \item{\code{year}:}{ 21 | calendar year the count was conducted. 22 | } 23 | \item{\code{std_yr}:}{ 24 | transformed year, with 2016 = 0. 25 | } 26 | \item{\code{count}:}{ 27 | number of robins recorded. 28 | } 29 | \item{\code{log_hrs}:}{ 30 | the natural log of party hours. 31 | } 32 | \item{\code{lon}:}{ 33 | longitude of the count circle centroid. 34 | } 35 | \item{\code{lat}:}{ 36 | latitude of the count circle centroid. 37 | } 38 | \item{\code{obs}:}{ 39 | unique record identifier. 40 | } 41 | } 42 | } 43 | \source{ 44 | https://github.com/tmeeha/inlaSVCBC 45 | } 46 | \usage{ 47 | robins_subset 48 | } 49 | \description{ 50 | This is the \code{robins_subset} dataset, which is a subset of the 51 | full robins data set used to demonstrate a spatially varying trend 52 | coefficient model in Meehan et al. 2019. The dataset includes American 53 | Robin counts, along with time, location, and effort information, from 54 | Audubon Christimas Bird Counts (CBC) conducted in six US states between 55 | 1987 and 2016. 56 | } 57 | \examples{ 58 | if (require(ggplot2, quietly = TRUE)) { 59 | data(robins_subset, package = "inlabru") # get the data 60 | 61 | # plot the counts for one year of data 62 | ggplot(robins_subset[robins_subset$std_yr == 0, ]) + 63 | geom_point(aes(lon, lat, colour = count + 1)) + 64 | scale_colour_gradient(low = "blue", high = "red", trans = "log") 65 | } 66 | } 67 | \references{ 68 | Meehan, T.D., Michel, N.L., and Rue, H. 2019. Spatial modeling of Audubon 69 | Christmas Bird Counts reveals fine-scale patterns and drivers of relative 70 | abundance trends. Ecosphere, 10(4), p.e02707. 71 | } 72 | \keyword{datasets} 73 | -------------------------------------------------------------------------------- /R/data.robins_subset.R: -------------------------------------------------------------------------------- 1 | #' @name robins_subset 2 | #' @title robins_subset 3 | #' @docType data 4 | #' @description This is the `robins_subset` dataset, which is a subset of the 5 | #' full robins data set used to demonstrate a spatially varying trend 6 | #' coefficient model in Meehan et al. 2019. The dataset includes American 7 | #' Robin counts, along with time, location, and effort information, from 8 | #' Audubon Christimas Bird Counts (CBC) conducted in six US states between 9 | #' 1987 and 2016. 10 | #' 11 | #' @format The data are a data.frame with variables 12 | #' \describe{ 13 | #' \item{`circle`:}{ 14 | #' Four-letter code of the CBC circle. 15 | #' } 16 | #' \item{`bcr`:}{ 17 | #' Numeric code for the bird conservation region encompassing the 18 | #' count circle. 19 | #' } 20 | #' \item{`state`:}{ 21 | #' US state encompassing the count circle. 22 | #' } 23 | #' \item{`year`:}{ 24 | #' calendar year the count was conducted. 25 | #' } 26 | #' \item{`std_yr`:}{ 27 | #' transformed year, with 2016 = 0. 28 | #' } 29 | #' \item{`count`:}{ 30 | #' number of robins recorded. 31 | #' } 32 | #' \item{`log_hrs`:}{ 33 | #' the natural log of party hours. 34 | #' } 35 | #' \item{`lon`:}{ 36 | #' longitude of the count circle centroid. 37 | #' } 38 | #' \item{`lat`:}{ 39 | #' latitude of the count circle centroid. 40 | #' } 41 | #' \item{`obs`:}{ 42 | #' unique record identifier. 43 | #' } 44 | #' } 45 | #' @source 46 | #' https://github.com/tmeeha/inlaSVCBC 47 | #' 48 | #' 49 | #' @references 50 | #' Meehan, T.D., Michel, N.L., and Rue, H. 2019. Spatial modeling of Audubon 51 | #' Christmas Bird Counts reveals fine-scale patterns and drivers of relative 52 | #' abundance trends. Ecosphere, 10(4), p.e02707. 53 | #' 54 | #' @examples 55 | #' if (require(ggplot2, quietly = TRUE)) { 56 | #' data(robins_subset, package = "inlabru") # get the data 57 | #' 58 | #' # plot the counts for one year of data 59 | #' ggplot(robins_subset[robins_subset$std_yr == 0, ]) + 60 | #' geom_point(aes(lon, lat, colour = count + 1)) + 61 | #' scale_colour_gradient(low = "blue", high = "red", trans = "log") 62 | #' } 63 | "robins_subset" 64 | -------------------------------------------------------------------------------- /man/summary.bru_comp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bru_input.R, R/effect.R 3 | \name{print.summary_bru_input} 4 | \alias{print.summary_bru_input} 5 | \alias{summary.bru_comp} 6 | \alias{summary.bru_comp_list} 7 | \alias{print.bru_comp} 8 | \alias{print.bru_comp_list} 9 | \alias{format.bru_subcomp} 10 | \alias{summary.bru_subcomp} 11 | \alias{print.bru_subcomp} 12 | \alias{print.summary_component} 13 | \alias{print.summary_bru_comp_list} 14 | \alias{print.summary_bru_subcomp} 15 | \title{Summarise components} 16 | \usage{ 17 | \method{print}{summary_bru_input}(x, ...) 18 | 19 | \method{summary}{bru_comp}(object, ..., depth = Inf, verbose = TRUE) 20 | 21 | \method{summary}{bru_comp_list}(object, verbose = TRUE, ...) 22 | 23 | \method{print}{bru_comp}(x, ...) 24 | 25 | \method{print}{bru_comp_list}(x, ...) 26 | 27 | \method{format}{bru_subcomp}(x, verbose = TRUE, ..., label.override = NULL) 28 | 29 | \method{summary}{bru_subcomp}(object, verbose = TRUE, ..., label.override = NULL) 30 | 31 | \method{print}{bru_subcomp}(x, verbose = TRUE, ..., label.override = NULL) 32 | 33 | \method{print}{summary_component}(x, ...) 34 | 35 | \method{print}{summary_bru_comp_list}(x, ...) 36 | 37 | \method{print}{summary_bru_subcomp}(x, ...) 38 | } 39 | \arguments{ 40 | \item{x}{A summary object to be printed.} 41 | 42 | \item{\dots}{Passed on to other summary methods.} 43 | 44 | \item{object}{Object to be summarised.} 45 | 46 | \item{depth}{The depth of which to expand the component mapper. 47 | Default \code{Inf}, to traverse the entire mapper tree.} 48 | 49 | \item{verbose}{logical; If \code{TRUE}, includes more details of the 50 | component definitions. When \code{FALSE}, only show basic component 51 | definition information. Default \code{TRUE}.} 52 | 53 | \item{label.override}{character; If not \code{NULL}, use this label instead of 54 | the object's label.} 55 | } 56 | \description{ 57 | Summarise components 58 | } 59 | \seealso{ 60 | \code{\link[=bru_comp]{bru_comp()}}, \code{\link[=summary.bru_input]{summary.bru_input()}} 61 | } 62 | \author{ 63 | Fabian E. Bachl \email{bachlfab@gmail.com} 64 | 65 | Finn Lindgren \email{finn.lindgren@gmail.com} 66 | } 67 | \keyword{internal} 68 | -------------------------------------------------------------------------------- /man/inlabru-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/inlabru-package.R 3 | \docType{package} 4 | \name{inlabru-package} 5 | \alias{inlabru-package} 6 | \alias{inlabru} 7 | \title{inlabru} 8 | \description{ 9 | Convenient model fitting using (iterated) INLA. 10 | } 11 | \details{ 12 | \code{inlabru} facilitates Bayesian spatial modelling using integrated nested 13 | Laplace approximations. It is heavily based on R-inla 14 | (\url{https://www.r-inla.org}) but adds additional modelling abilities and 15 | simplified syntax for (in particular) spatial models. 16 | Tutorials and more information can be found at 17 | \url{https://inlabru-org.github.io/inlabru/} and \url{http://www.inlabru.org/}. 18 | The iterative method used for non-linear predictors is documented in the 19 | \code{method} vignette. 20 | 21 | The main function for inference using inlabru is \code{\link[=bru]{bru()}}. 22 | The general model specification details is documented in \code{\link[=bru_comp]{bru_comp()}} 23 | and \code{\link[=bru_obs]{bru_obs()}}. 24 | Posterior quantities beyond the basic summaries can be calculated with 25 | a \code{predict()} method, documented in \code{\link[=predict.bru]{predict.bru()}}. 26 | For point process inference \code{\link[=lgcp]{lgcp()}} can be used as a shortcut to 27 | \code{bru(..., bru_obs(model="cp", ...))}. 28 | 29 | The package comes with multiple real world data sets, namely \link{gorillas}, 30 | \link{gorillas_sf}, \link{mexdolphin_sf}. Plotting these data 31 | sets is straight forward using inlabru's extensions 32 | to \code{ggplot2}, e.g. the \code{\link[=gg]{gg()}} function. For educational purposes some 33 | simulated data sets are available as well, e.g. \link{Poisson1_1D}, 34 | \link{Poisson2_1D}, \link{Poisson2_1D} and \link{toygroups}. 35 | } 36 | \seealso{ 37 | Useful links: 38 | \itemize{ 39 | \item \url{http://www.inlabru.org} 40 | \item \url{https://inlabru-org.github.io/inlabru/} 41 | \item \url{https://github.com/inlabru-org/inlabru} 42 | \item Report bugs at \url{https://github.com/inlabru-org/inlabru/issues} 43 | } 44 | 45 | } 46 | \author{ 47 | Fabian E. Bachl \email{bachlfab@gmail.com} 48 | and Finn Lindgren \email{finn.lindgren@gmail.com} 49 | } 50 | -------------------------------------------------------------------------------- /man/plotsample.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plotsample.R 3 | \name{plotsample} 4 | \alias{plotsample} 5 | \title{Create a plot sample.} 6 | \usage{ 7 | plotsample(spdf, boundary, x.ppn = 0.25, y.ppn = 0.25, nx = 5, ny = 5) 8 | } 9 | \arguments{ 10 | \item{spdf}{A \code{SpatialPointsDataFrame} defining the points that are to be 11 | sampled by the plot sample.} 12 | 13 | \item{boundary}{A \code{SpatialPolygonsDataFrame} defining the survey boundary 14 | within which the points occur.} 15 | 16 | \item{x.ppn}{The proportion of the x=axis that is to be included in the 17 | plots.} 18 | 19 | \item{y.ppn}{The proportion of the y=axis that is to be included in the 20 | plots.} 21 | 22 | \item{nx}{The number of plots in the x-dimension.} 23 | 24 | \item{ny}{The number of plots in the y-dimension.} 25 | } 26 | \value{ 27 | A list with three components: 28 | \describe{ 29 | \item{\code{plots}}{A \code{SpatialPolygonsDataFrame} object containing the plots 30 | that were sampled.} 31 | \item{\code{dets}}{A \code{SpatialPointsDataFrame} object containing the locations 32 | of the points within the plots.} 33 | \item{\code{counts}}{A \code{dataframe} containing the following columns 34 | \describe{ 35 | \item{\code{x}}{The x-coordinates of the centres of the plots within the 36 | boundary.} 37 | \item{\code{y}}{The y-coordinates of the centres of the plots within the 38 | boundary.} 39 | \item{\code{n}}{The numbers of points in each plot.} 40 | \item{\code{area}}{The areas of the plots within the boundary} 41 | }} 42 | }. 43 | } 44 | \description{ 45 | Creates a plot sample on a regular grid with a random start location. 46 | } 47 | \examples{ 48 | \donttest{ 49 | # Some features require the raster package 50 | if (bru_safe_sp() && 51 | require("sp") && 52 | require("raster", quietly = TRUE) && 53 | require("ggplot2", quietly = TRUE) && 54 | require("terra", quietly = TRUE) && 55 | require("sf", quietly = TRUE)) { 56 | gorillas <- gorillas_sp() 57 | plotpts <- plotsample(gorillas$nests, gorillas$boundary, 58 | x.ppn = 0.4, y.ppn = 0.4, nx = 5, ny = 5 59 | ) 60 | ggplot() + 61 | gg(plotpts$plots) + 62 | gg(plotpts$dets, pch = "+", cex = 2) + 63 | gg(gorillas$boundary) 64 | } 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /man/bru_fill_missing.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{bru_fill_missing} 4 | \alias{bru_fill_missing} 5 | \title{Fill in missing values in Spatial grids} 6 | \usage{ 7 | bru_fill_missing( 8 | data, 9 | where, 10 | values, 11 | layer = NULL, 12 | selector = NULL, 13 | batch_size = deprecated() 14 | ) 15 | } 16 | \arguments{ 17 | \item{data}{A SpatialPointsDataFrame, SpatialPixelsDataFrame, 18 | SpatialGridDataFrame, SpatRaster, Raster, or sf object 19 | containing data to use for filling} 20 | 21 | \item{where}{A, matrix, data.frame, or SpatialPoints or 22 | SpatialPointsDataFrame, or sf object, containing the locations of the 23 | evaluated values} 24 | 25 | \item{values}{A vector of values to be filled in where \code{is.na(values)} is 26 | \code{TRUE}} 27 | 28 | \item{layer, selector}{Specifies what data column or columns from which to 29 | extract data, see \code{\link[=bru_comp]{bru_comp()}} for details.} 30 | 31 | \item{batch_size}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} due to improved 32 | algorithm. 33 | Size of nearest-neighbour calculation blocks, to limit the 34 | memory and computational complexity.} 35 | } 36 | \value{ 37 | An infilled vector of values 38 | } 39 | \description{ 40 | Computes nearest-available-value imputation for missing values in space 41 | } 42 | \examples{ 43 | \dontrun{ 44 | if (require("sf", quietly = TRUE)) { 45 | points <- 46 | sf::st_as_sf( 47 | data.frame( 48 | x = 1:3, 49 | y = 4:6, 50 | val = c(NA, NA, NA) 51 | ), 52 | coords = c("x", "y") 53 | ) 54 | input_coord <- expand.grid(x = 0:7, y = 0:7) 55 | input <- 56 | sf::st_as_sf( 57 | cbind(input_coord, val = as.vector(input_coord$y)), 58 | coords = c("x", "y") 59 | ) 60 | points$val <- bru_fill_missing(input, points, points$val) 61 | print(points) 62 | 63 | # To fill in missing values in a grid: 64 | print(input$val[c(3, 30)]) 65 | input$val[c(3, 30)] <- NA # Introduce missing values 66 | input$val <- bru_fill_missing(input, input, input$val) 67 | print(input$val[c(3, 30)]) 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /man/sline.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bru_sp.R 3 | \name{sline} 4 | \alias{sline} 5 | \title{Convert data frame to SpatialLinesDataFrame} 6 | \usage{ 7 | sline( 8 | data, 9 | start.cols, 10 | end.cols, 11 | crs = fm_crs(), 12 | to.crs = NULL, 13 | format = c("sp", "sf") 14 | ) 15 | } 16 | \arguments{ 17 | \item{data}{A data.frame} 18 | 19 | \item{start.cols}{Character array pointing out the columns of \code{data} that 20 | hold the start points of the lines} 21 | 22 | \item{end.cols}{Character array pointing out the columns of \code{data} that hold 23 | the end points of the lines} 24 | 25 | \item{crs}{Coordinate reference system of the original \code{data}} 26 | 27 | \item{to.crs}{Coordinate reference system for the output.} 28 | 29 | \item{format}{Format of the output object. Either \code{"sp"} (default) or \code{"sf"}} 30 | } 31 | \value{ 32 | \code{sp::SpatialLinesDataFrame} or \link[sf:sf]{sf::sf} 33 | } 34 | \description{ 35 | A line in 2D space is defined by a start and an end point, each associated 36 | with 2D coordinates. This function takes a \code{data.frame} as input and assumes 37 | that each row defines a line in space. In order to do so, the data frame must 38 | have at least four columns and the \code{start.cols} and \code{end.cols} parameters 39 | must be used to point out the names of the columns that define the start and 40 | end coordinates of the line. The data is then converted to a 41 | \code{SpatialLinesDataFrame} \code{DF}. If a coordinate reference system \code{crs} is 42 | provided it is attached to \code{DF}. If also \code{to.crs} is provided, the coordinate 43 | system of \code{DF} is transformed accordingly. Additional columns of the input 44 | data, e.g. covariates, are retained and attached to \code{DF}. 45 | } 46 | \examples{ 47 | \donttest{ 48 | # Create a data frame defining three lines 49 | lns <- data.frame( 50 | xs = c(1, 2, 3), ys = c(1, 1, 1), # start points 51 | xe = c(2, 3, 4), ye = c(2, 2, 2) 52 | ) # end points 53 | 54 | 55 | # Conversion to sf without CRS 56 | spl <- sline(lns, 57 | start.cols = c("xs", "ys"), 58 | end.cols = c("xe", "ye"), 59 | format = "sf" 60 | ) 61 | 62 | if (require(ggplot2, quietly = TRUE)) { 63 | # Plot the lines 64 | ggplot() + 65 | gg(spl) 66 | } 67 | } 68 | 69 | } 70 | \keyword{internal} 71 | -------------------------------------------------------------------------------- /man/materncov.bands.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/spde.R 3 | \name{materncov.bands} 4 | \alias{materncov.bands} 5 | \title{Matern correlation or covariance function approximate credible bands.} 6 | \usage{ 7 | materncov.bands( 8 | manifold, 9 | dist, 10 | log.range, 11 | log.variance = NULL, 12 | alpha = 2, 13 | quantile = 0.95, 14 | n = 64, 15 | S1.L = NULL 16 | ) 17 | } 18 | \arguments{ 19 | \item{manifold}{Either "R1", "S1", "R2", or "S2", from 20 | \code{fm_manifold(mesh)}, or an object supported by 21 | \code{\link[fmesher:fm_manifold]{fmesher::fm_manifold()}}.} 22 | 23 | \item{dist}{A vector of distances at which to calculate the 24 | covariances/correlations} 25 | 26 | \item{log.range}{A scalar or a list (mean, sd), such as produced by 27 | \code{inla.spde.result(...)$summary.log.range.nominal[[1]][c("mean","sd")]}} 28 | 29 | \item{log.variance}{Either \code{NULL}, a scalar, or vector of the 30 | same type as for log.range. When \code{NULL}, the correlations 31 | are calculated instead of the covariances.} 32 | 33 | \item{alpha}{The SPDE operator order. Default 2.} 34 | 35 | \item{quantile}{The target credible probability. Default 0.95.} 36 | 37 | \item{n}{The number of parameter combinations to use for the 38 | approximation. Default 64.} 39 | 40 | \item{S1.L}{For \code{manifold} \code{"S1"}, give the length of the 41 | cyclic interval} 42 | } 43 | \value{ 44 | A list with estimated covariance or correlation (when \code{log.variance} 45 | is \code{NULL}) functions: 46 | \item{lower}{An approximate lower bound for the \code{quantile} credible region} 47 | \item{median}{The function for for the approximate median parameters 48 | quantile} 49 | \item{upper}{An approximate upper bound for the \code{quantile} credible region} 50 | } 51 | \description{ 52 | Evaluate the covariance function for an inla.spde 53 | object. Calculates the posterior distribution of the range, 54 | log(range), variance, or log(variance) parameter of a model's 55 | SPDE component. Can also calculate Matern correlation or covariance 56 | function. 57 | } 58 | \details{ 59 | Uses a Gaussian assumption for the internal model parameters, and finds a 60 | region in parameter space with approximately \code{quantile} probability. 61 | } 62 | \author{ 63 | Finn Lindgren \email{Finn.Lindgren@ed.ac.uk} 64 | } 65 | \keyword{internal} 66 | -------------------------------------------------------------------------------- /misc/mdata_testing.R: -------------------------------------------------------------------------------- 1 | library(INLA) 2 | library(inlabru) 3 | library(tibble) 4 | 5 | dat1 <- tibble( 6 | time_to_event = 1:4, 7 | event_type = rep(c(1, 0), 2), 8 | cure_covar = matrix(1:8, 4, 2) 9 | ) 10 | dat2 <- tibble( 11 | time_to_event = 1:3 + 10, 12 | event_type = c(1, 0, 1), 13 | cure_covar = matrix(1:6, 3, 2) + 10 14 | ) 15 | 16 | dat1_ <- as_tibble(unclass(with( 17 | dat1, 18 | inla.surv(time = time_to_event, event = event_type, cure = cure_covar) 19 | ))[-7]) 20 | dat2_ <- as_tibble(unclass(with( 21 | dat2, 22 | inla.mdata(time_to_event, cure_covar) 23 | ))) 24 | 25 | stk1 <- inla.stack(dat1_, A = list(diag(4)), effects=list(Intercept=1)) 26 | stk2 <- inla.stack(dat2_, A = list(diag(3)), effects=list(Intercept=1)) 27 | inla.stack.LHS(stk1) 28 | inla.stack.RHS(stk1) 29 | inla.stack.LHS(stk2) 30 | inla.stack.RHS(stk2) 31 | 32 | stk <- inla.stack(stk1, stk2) 33 | inla.stack.LHS(stk) 34 | inla.stack.RHS(stk) 35 | 36 | 37 | fit <- inla(formula = list(inla.stack.LHS(stk), inla.stack.LHS(stk)) ~ 0 + Intercept, 38 | family = c("exponentialsurv", "agaussian"), 39 | data = inla.stack.RHS(stk), 40 | control.predictor = list(A = inla.stack.A(stk)), 41 | safe = FALSE) 42 | 43 | fit <- inla(formula = list(inla.stack.LHS(stk1), inla.stack.LHS(stk2)) ~ 0 + Intercept, 44 | family = c("exponentialsurv", "agaussian"), 45 | data = inla.stack.RHS(stk), 46 | control.predictor = list(A = inla.stack.A(stk)), 47 | safe = FALSE) 48 | 49 | 50 | fitb1 <- bru( 51 | components = ~ 0 + Intercept(1), 52 | bru_obs(formula = dat1_ ~ ., 53 | family = "exponentialsurv", 54 | response_data = list(dat1_ = dat1_)), 55 | options = list(safe = FALSE) 56 | ) 57 | fitb2 <- bru( 58 | components = ~ 0 + Intercept(1), 59 | bru_obs(formula = dat2_ ~ ., 60 | family = "agaussian", 61 | data = dat2), 62 | options = list(safe = FALSE) 63 | ) 64 | fitb <- bru( 65 | components = ~ 0 + Intercept(1), 66 | bru_obs(formula = as.data.frame(unclass(inla.surv(time = time_to_event, event = event_type, cure = cure_covar))[-7]) ~ ., 67 | family = "exponentialsurv", 68 | data = dat1), 69 | bru_obs(formula = inla.mdata(time_to_event, cure_covar) ~ ., 70 | family = "agaussian", 71 | data = dat2), 72 | options = list(safe = FALSE) 73 | ) 74 | -------------------------------------------------------------------------------- /tests/testthat/test-bru_sf.R: -------------------------------------------------------------------------------- 1 | test_that("sf gorillas lgcp vignette", { 2 | ## skip("Feature not yet implemented") 3 | 4 | skip_on_cran() 5 | local_bru_safe_inla() 6 | skip_if_not_installed("sf") 7 | 8 | # Code adapted from the lgcp vignette with an additional mesh construction 9 | # step instead of using the mesh provided in the gorillas data. 10 | 11 | # All sp objects in the example are replaced with sf equivalents. 12 | 13 | data(gorillas_sf, package = "inlabru", envir = environment()) 14 | 15 | # ## Not needed anymore for this test, but kept for future reference 16 | # # Bug in st_as_sf making check_ring_dir=TRUE have no effect, as 17 | # # st_as_sfc.SpatialPolygons ignores it. To get around it, need to convert to 18 | # # sfc_POLYGON first, and then do a separate st_sfc call, which does use 19 | # # check_ring_dir. 20 | # # No effect: 21 | # b1 <- sf::st_as_sf(gorillas$boundary, check_ring_dir = TRUE) 22 | # # st_sfc gives the proper effect: 23 | # b2 <- b1 24 | # b2$geometry <- sf::st_sfc(sf::st_geometry(b2$geometry), 25 | # check_ring_dir = TRUE) 26 | # 27 | # gorillas_sf$boundary <- b2 28 | 29 | ## Build boundary information: 30 | boundary <- list( 31 | gorillas_sf$boundary, 32 | NULL 33 | ) 34 | 35 | ## Build the mesh: 36 | mesh_sf <- fm_mesh_2d_inla( 37 | boundary = boundary, 38 | max.edge = c(0.54, 0.97), 39 | min.angle = c(30, 21), 40 | ## Safeguard against large meshes. 41 | max.n = c(48000, 16000), 42 | ## Don't build a huge mesh! 43 | max.n.strict = c(128000, 128000), 44 | ## Filter away adjacent points. 45 | cutoff = 0.01, 46 | ## Offset for extra boundaries, if needed. 47 | offset = c(0.73, 1.55), 48 | ## Build mesh in this crs: 49 | crs = fm_crs(gorillas_sf$nests) 50 | ) 51 | 52 | # library(ggplot2) 53 | # ggplot() + 54 | # gg(mesh_sf) + 55 | # geom_sf(data = gorillas_sf$boundary, alpha = 0.2, fill = "blue") 56 | 57 | matern <- INLA::inla.spde2.pcmatern(mesh_sf, 58 | prior.sigma = c(0.1, 0.01), 59 | prior.range = c(0.1, 0.01) 60 | ) 61 | 62 | cmp <- geometry ~ mySmooth(geometry, model = matern) + 63 | Intercept(1) 64 | 65 | expect_no_error( 66 | fit <- lgcp( 67 | cmp, 68 | data = gorillas_sf$nests, 69 | samplers = gorillas_sf$boundary, 70 | domain = list(geometry = mesh_sf) 71 | ) 72 | ) 73 | }) 74 | -------------------------------------------------------------------------------- /man/bru_comp_eval.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/model.R 3 | \name{bru_comp_eval} 4 | \alias{bru_comp_eval} 5 | \alias{bru_component_eval} 6 | \title{Evaluate component values in predictor expressions} 7 | \usage{ 8 | bru_comp_eval( 9 | main, 10 | group = NULL, 11 | replicate = NULL, 12 | weights = NULL, 13 | .state = NULL 14 | ) 15 | } 16 | \arguments{ 17 | \item{main, group, replicate, weights}{Specification of where to evaluate a 18 | component. The four inputs are passed on to the joint \code{bru_mapper} for the 19 | component, as 20 | 21 | \if{html}{\out{
}}\preformatted{list(mapper = list( 22 | main = main, 23 | group = group, 24 | replicate = replicate), 25 | scale = weights) 26 | }\if{html}{\out{
}} 27 | 28 | NOTE: If you have model component with the same name as a data variable you 29 | want to supply as input to \code{name_eval()}, you need to use 30 | \code{.data.[["myvar"]]} to access it. Otherwise, it will try to use the other 31 | component effect as input, which is ill-defined.} 32 | 33 | \item{.state}{The internal component state. Normally supplied automatically 34 | by the internal methods for evaluating inlabru predictor expressions.} 35 | } 36 | \value{ 37 | A vector of values for a component 38 | } 39 | \description{ 40 | In predictor expressions, \code{name_eval(...)} can be used to evaluate 41 | the effect of a component called "name". 42 | } 43 | \examples{ 44 | if (bru_safe_inla() && 45 | require("sf", quietly = TRUE) && 46 | requireNamespace("sn", quietly = TRUE)) { 47 | mesh <- fmesher::fm_mesh_2d_inla( 48 | cbind(0, 0), 49 | offset = 2, 50 | max.edge = 2.5 51 | ) 52 | spde <- INLA::inla.spde2.pcmatern( 53 | mesh, 54 | prior.range = c(1, NA), 55 | prior.sigma = c(0.2, NA) 56 | ) 57 | set.seed(12345L) 58 | data <- sf::st_as_sf( 59 | data.frame( 60 | x = runif(50), 61 | y = runif(50), 62 | z = rnorm(50) 63 | ), 64 | coords = c("x", "y") 65 | ) 66 | fit <- bru( 67 | z ~ -1 + field(geometry, model = spde), 68 | family = "gaussian", data = data, 69 | options = list(control.inla = list(int.strategy = "eb")) 70 | ) 71 | pred <- generate( 72 | fit, 73 | newdata = data.frame(A = 0.5, B = 0.5), 74 | formula = ~ field_eval(cbind(A, B)), 75 | n.samples = 1L 76 | ) 77 | } 78 | } 79 | --------------------------------------------------------------------------------