Skip to content

Commit

Permalink
Fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
gareth-j committed Oct 31, 2023
2 parents fd25b23 + 09da24f commit bb5306b
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 143 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Allowed reversal of colour palette and added raster plot legend in map plotter - [PR #229](https://github.com/4DModeller/fdmr/pull/229)
- Added markers option to mesh plotter - [PR #230](https://github.com/4DModeller/fdmr/pull/230)

### Removed

## [0.1.0] - 2023-10-17
Expand All @@ -31,7 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Clearer documentation on types expected by the `mesh_builder` tool - [PR #101](https://github.com/4DModeller/fdmr/pull/101)
- Checks on the data types being passed into the `mesh_builder` tool - [PR #101](https://github.com/4DModeller/fdmr/pull/101)
- Ability to plot either polygon or point data on Leaflet map of `mesh_builder` tool - [PR #101](https://github.com/4DModeller/fdmr/pull/101)
- The ability to plot model predictions on a `leaflet` map in the our [Interactive priors Shiny app](https://4dmodeller.github.io/fdmr/articles/priors_app.html) - [PR #147](https://github.com/4DModeller/fdmr/pull/147)
- The ability to plot model predictions on a `leaflet` map in the our [Model builder Shiny app](https://4dmodeller.github.io/fdmr/articles/modelbuilder.html) - [PR #147](https://github.com/4DModeller/fdmr/pull/147)
- A new Shiny app to parse and plot INLA model output, letting users easily view model parameters and predictions on a map - [PR #158](https://github.com/4DModeller/fdmr/pull/158)

### Fixed
Expand Down
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ Imports:
promises,
fmesher,
purrr,
shinyjs
shinyjs,
bslib
Suggests:
bookdown,
knitr,
Expand Down
16 changes: 13 additions & 3 deletions R/plot_mapping.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#' @param polygon_fill_colour Polygon fill colour
#' @param polygon_line_colour Polygon surrounding line colour
#' @param polygon_line_weight Polygon surrounding line weight
#' @param reverse Reverse the colour palette if TRUE
#'
#' @return leaflet::leaflet
#' @export
Expand All @@ -24,7 +25,8 @@ plot_map <- function(polygon_data = NULL,
polygon_fill_colour = "#E4572E",
polygon_line_colour = "grey",
polygon_line_weight = 1,
polygon_fill_opacity = 0.6) {
polygon_fill_opacity = 0.6,
reverse = FALSE) {
if (is.null(polygon_data) && is.null(raster_data)) {
stop("Polygon or raster data must be given.")
}
Expand All @@ -39,7 +41,7 @@ plot_map <- function(polygon_data = NULL,

if (!is.null(polygon_data)) {
if (!is.null(domain)) {
colours <- leaflet::colorNumeric(palette = palette, domain = domain, reverse = FALSE)
colours <- leaflet::colorNumeric(palette = palette, domain = domain, reverse = reverse)
polygon_fill_colour <- ~ colours(domain)
m <- leaflet::addLegend(m,
pal = colours,
Expand All @@ -61,12 +63,20 @@ plot_map <- function(polygon_data = NULL,
}

if (!is.null(raster_data)) {
colours <- leaflet::colorNumeric(palette = palette, domain = raster::values(raster_data), na.color=rgb(0,0,0,0), reverse = reverse)
m <- leaflet::addRasterImage(m,
x = raster_data,
opacity = 0.75,
group = "Raster",
layerId = "raster",
colors = palette,
colors = colours,
)
m <- leaflet::addLegend(m,
pal = colours,
values = raster::values(raster_data),
opacity = 0.75,
title = legend_title,
na.label = ""
)
layers <- append(layers, "Raster")
}
Expand Down
10 changes: 8 additions & 2 deletions R/plot_mesh.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
#' that can be converted to a data.frame with longitude and latitude columns
#' @param longitude_column Longitude column in spatial_data
#' @param latitude_column Latitude column in spatial_data name
#' @param markers Markers to display on top of mesh. A named list with latitude, longitude and label names must be given.
#' Expects longitude name to be longitude, latitude name to be latitude, label name to be label.
#'
#' @return leaflet::leaflet
#' @export
plot_mesh <- function(mesh, spatial_data = NULL, longitude_column = "LONG", latitude_column = "LAT") {
plot_mesh <- function(mesh, spatial_data = NULL, longitude_column = "LONG", latitude_column = "LAT", markers = NULL) {
expected_crs <- "+proj=longlat +datum=WGS84"
crs_string <- fmesher::fm_proj4string(mesh)

Expand All @@ -24,7 +26,6 @@ plot_mesh <- function(mesh, spatial_data = NULL, longitude_column = "LONG", lati

spatial_mesh <- fdmr::mesh_to_spatial(mesh = mesh, crs = expected_crs)


plot_polygons <- FALSE
plot_points <- FALSE
if (!is.null(spatial_data)) {
Expand Down Expand Up @@ -68,6 +69,11 @@ plot_mesh <- function(mesh, spatial_data = NULL, longitude_column = "LONG", lati
overlay_groups <- append(overlay_groups, "Spatial")
}

if (!is.null(markers)) {
m <- leaflet::addMarkers(m, lng = markers$longitude, lat = markers$latitude, label = markers$label, group = "Markers")
overlay_groups <- append(overlay_groups, "Markers")
}

m <- leaflet::addLayersControl(m,
position = "topright",
baseGroups = c("OSM"),
Expand Down
31 changes: 21 additions & 10 deletions R/shiny_priors.R → R/shiny_modelbuilder.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ model_builder_shiny <- function(spatial_data,
# structure we can remove this
busy_spinner <- get_busy_spinner()

range0_tooltip <- "range0 and Prange jointly specify the complexity priors for the spatial range parameter ρ, in the relation that P(ρ < range0 ) = Prange.
range0_tooltip <- "range0 and Prange jointly specify the complexity priors for the spatial range parameter ρ, in the relation that P(ρ < range0 ) = Prange.
The spatial range parameter ρ is defined as the distance at which the spatial correlation between two locations is approximately 0"
Prange_tooltip <- "Large values of Prange lead to a greater prior belief on small values of ρ."

Prange_tooltip <- "Large values of Prange lead to a greater prior belief on small values of ρ."
sigma0_tooltip <- "sigma0 and Psigma jointly specify the complexity priors for the marginal standard deviation of the field σ, in the relation of P(σ > sigma0) = Psigma."
Psigma_tooltip <- "Large values of Psigma lead to a greater prior belief on large values of σ."

prior_alpha_tooltip <- "prior_alpha and pg_alpha jointly specify the complexity priors for the temporal autocorrelation parameter α, in the relation that P(α > prior_alpha) = pg_alpha."
pg_alpha_tooltip <- "Large values of pg_alpha lead to a greater prior belief on large values of α"

Expand Down Expand Up @@ -214,6 +214,7 @@ model_builder_shiny <- function(spatial_data,
),
shiny::tabPanel(
"Features",
class = "p-3 border",
shiny::fluidRow(
shiny::column(
6,
Expand All @@ -225,17 +226,23 @@ model_builder_shiny <- function(spatial_data,
shiny::selectInput(inputId = "data_dist", label = "Data distribution", choices = c("Poisson", "Gaussian"), selected = data_distribution),
)
),
shiny::checkboxGroupInput(inputId = "features", label = "Features", choices = features),
shiny::checkboxInput(inputId = "f_func", label = "Add f()", value = FALSE),
shiny::actionButton(inputId = "clear", label = "Clear"),
shiny::fluidRow(
shiny::h2("Formula"),
shiny::textOutput(outputId = "final_equation"),
style = "height:20vh;"
shiny::column(
6,
shiny::checkboxGroupInput(inputId = "features", label = "Features", choices = features),
shiny::checkboxInput(inputId = "f_func", label = "Add f()", value = FALSE),
shiny::actionButton(inputId = "clear", label = "Clear"),
),
shiny::column(
6,
shiny::h2("Formula"),
shiny::textOutput(outputId = "final_equation"),
)
)
),
shiny::tabPanel(
"Model",
class = "p-3 border",
shiny::fluidRow(
shiny::h2("Model output"),
# shiny::conditionalPanel("output.gotoutput", shiny::h3("Hyperparameter summary")),
Expand All @@ -248,12 +255,14 @@ model_builder_shiny <- function(spatial_data,
),
shiny::tabPanel(
"Plot",
class = "p-3 border",
shiny::h2("Plot output"),
shiny::selectInput(inputId = "plot_type", label = "Plot type:", choices = plot_choices, selected = plot_choices[1]),
shiny::plotOutput(outputId = "plot_model_out")
),
shiny::tabPanel(
"Map",
class = "p-3 border",
shiny::fluidRow(
shiny::column(
4,
Expand Down Expand Up @@ -286,11 +295,13 @@ model_builder_shiny <- function(spatial_data,
),
shiny::tabPanel(
"Code",
class = "p-3 border",
shiny::selectInput(inputId = "select_run_code", label = "Select run:", choices = c()),
shiny::verbatimTextOutput(outputId = "code_out")
),
shiny::tabPanel(
"Help",
class = "p-3 border",
shiny::h3("Help"),
shiny::h4("Spatial priors"),
shiny::p(prior_range_text),
Expand Down
4 changes: 1 addition & 3 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ navbar:
href: articles/simulation_poisson_data.html
- text: ---
- text: Shiny apps
- text: "Map plotting"
href: articles/mapping.html
- text: "Mesh building"
href: articles/meshbuilder.html
- text: "Model builder"
href: articles/priors_app.html
href: articles/modelbuilder.html
- text: ---
- text: In depth tutorials
- text: "COVID-19"
Expand Down
2 changes: 1 addition & 1 deletion man/model_builder.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/model_builder_shiny.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions vignettes/inla_FAQ.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,33 @@ fit.mod <- inlabru::bru(formula,
)
)
```


## INLA error - Linux - Failed to get good enough initial values

If you're running Linux and encounter an error similar to the one below:

```
.../INLA/INLA/bin/linux/64bit/inla.mkl: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by .../INLA/INLA/bin/linux/64bit/libmvec.so.1)
*** inla.core.safe: inla.program has crashed: rerun to get better initial values. try=1/1
Loading required package: INLA
Warning: package 'INLA' was built under R version 4.3.1
Loading required package: Matrix
Loading required package: sp
This is INLA_23.10.19-1 built 2023-10-19 08:26:30 UTC.
- See www.r-inla.org/contact-us for how to get help.
- List available models/likelihoods/etc with inla.list.models()
- Use inla.doc(<NAME>) to access documentation
Warning in iinla(model = info[["model"]], lhoods = info[["lhoods"]], options = info[["options"]]) :
iinla: Problem in inla: Error in inla.core.safe(formula = formula, family = family, contrasts = contrasts, :
*** Failed to get good enough initial values. Maybe it is due to something else.
```

You may need to run a binary install of INLA. This can be done by running the following:

```{r eval=FALSE}
INLA::inla.binary.install()
```

For more installation instructions see [the INLA documentation](https://www.r-inla.org/download-install).
2 changes: 1 addition & 1 deletion vignettes/priors.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -551,5 +551,5 @@ mesh <- fmesher::fm_mesh_2d_inla(
```

```{r eval=FALSE}
fdmr::model_builder(spatial_data=sp_data, measurement_data = covid19_data, mesh=mesh, time_variable="week")
fdmr::model_builder(spatial_data = sp_data, measurement_data = covid19_data, mesh = mesh, time_variable = "week")
```
110 changes: 0 additions & 110 deletions vignettes/priors_app.Rmd

This file was deleted.

Loading

0 comments on commit bb5306b

Please sign in to comment.