Skip to content

Commit 117ce5a

Browse files
authored
Merge pull request #344 from 4DModeller/devel
merge devel into joss
2 parents 7e8cafe + 77e3e30 commit 117ce5a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+262
-188
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Fixed
1111

12+
- Removed non-numeric/non-logical variable features from `shiny_modelbuilder` - [PR #341](https://github.com/4DModeller/fdmr/pull/341)
13+
- Updated documentation for all functions to reflect better the inputs and outputs - [PR #332](https://github.com/4DModeller/fdmr/pull/332)
14+
- Fixed an error in `model_viewer` description - [PR #331](https://github.com/4DModeller/fdmr/pull/331)
15+
- Added to `retrieve_tutorial_data` an option to save tutorial data at a user-specified location or in a temporary directory as default - [PR #330](https://github.com/4DModeller/fdmr/pull/330)
1216
- Fixed `model_viewer` app to work with random effect models - [PR #317](https://github.com/4DModeller/fdmr/pull/317)
1317
- Updated `plot_map_leaflet` to feature the same selection of basemap tiles as `mapview` and fix features not appearing - [PR #310](https://github.com/4DModeller/fdmr/pull/310)
1418

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ BugReports: https://github.com/4DModeller/fdmr/issues
1616
License: GPL (>= 3)
1717
Encoding: UTF-8
1818
Roxygen: list(markdown = TRUE)
19-
RoxygenNote: 7.2.3
19+
RoxygenNote: 7.3.2
2020
Additional_repositories: https://inla.r-inla-download.org/R/testing
2121
Imports:
2222
colorspace,

R/meshing.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# This function taken from https://groups.google.com/g/r-inla-discussion-group/c/z1n1exlZrKM/m/8vYNr2D8BwAJ
22
#' Convert an INLA mesh to a SpatialPolygonsDataFrame
33
#'
4-
#' @param mesh Mesh
5-
#' @param crs Coordinate Reference System as proj4string
4+
#' @param mesh Mesh object from INLA or fmesher (only R2 manifolds are valid)
5+
#' @param crs Coordinate Reference System as proj4string, does not support geocentric coordinates
66
#'
7-
#' @return SpatialPolygonsDataFrame
7+
#' @return SpatialPolygonsDataFrame with mesh triangles
88
#' @export
99
mesh_to_spatial <- function(mesh, crs) {
1010
if (!is.character(crs)) {

R/meshing_checks.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#' 2. A greater number of mesh triangles than observations
44
#' 3. Isolated triangles in mesh
55
#'
6-
#' @param mesh INLA mesh
7-
#' @param observations Observations data to be used woith model
6+
#' @param mesh INLA/fmesher mesh
7+
#' @param observations Observations data to be used with model (can be data.frame, SpatialPoints/SpatialPointsDataFrame, or simple feature collection)
88
#'
99
#' @return list: Named list containing errors
1010
#' @export

R/model_parse.R

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#' Parses inlabru::bru model output to create a list of model parameters
22
#'
33
#' @param model_output Output from running inlabru::bru
4-
#' @param measurement_data Measurement data
4+
#' @param measurement_data Measurement data (can be data.frame, SpatialPoints/SpatialPointsDataFrame, or simple feature collection)
55
#'
6-
#' @return list
6+
#' @return Creates a list of model outputs for the first timestep, including fitted mean and sd, mean of fixed effects, mean and sd of random effects, posterior hyperparameters, and DIC
77
#' @keywords internal
88
parse_model_output_bru <- function(model_output, measurement_data) {
99
fitted_mean_post <- model_output$summary.fitted.values$mean[seq_len(nrow(measurement_data))]
@@ -33,11 +33,11 @@ parse_model_output_bru <- function(model_output, measurement_data) {
3333

3434
#' Parse model output to create a list of model parameters
3535
#'
36-
#' @param model_output Data returned by model
37-
#' @param measurement_data Measurement data
38-
#' @param model_type Type of model, we currently support inlabru
36+
#' @param model_output Output returned by model (currently only from running inlabru::bru)
37+
#' @param measurement_data Measurement data (can be data.frame, SpatialPoints/SpatialPointsDataFrame, or simple feature collection)
38+
#' @param model_type Type of model, we currently only support inlabru
3939
#'
40-
#' @return list
40+
#' @return Creates a list of model outputs, including fitted mean and sd, mean of fixed effects, mean and sd of random effects, posterior hyperparameters, and DIC
4141
#' @export
4242
parse_model_output <- function(model_output, measurement_data, model_type = "inlabru") {
4343
if (model_type == "inlabru") {
@@ -48,13 +48,13 @@ parse_model_output <- function(model_output, measurement_data, model_type = "inl
4848

4949
#' Create a prediction field from the parsed model output and the mesh
5050
#'
51-
#' @param mesh INLA mesh
52-
#' @param plot_type Type of plot to create, "predicted_mean_fields" etc
53-
#' @param data_dist Type of data, "poisson" etc
54-
#' @param var_a Data for variable a, required for "predicted_mean_fields" and "random_effect_fields"
55-
#' @param var_b Data for variable b, required for "predicted_mean_fields"
51+
#' @param mesh INLA/fmesher mesh
52+
#' @param plot_type Type of plot to create, "predicted_mean_fields" or "random_mean_fields"
53+
#' @param data_dist Type of data, "poisson" or "gaussian"
54+
#' @param var_a Data for variable a (numeric), required for "predicted_mean_fields" and "random_effect_fields"; normally, random effect field from "summary.random$f"
55+
#' @param var_b Data for variable b (numeric), required for "predicted_mean_fields"; normally, fixed effect from "summary.fixed"
5656
#'
57-
#' @return data.frame
57+
#' @return data.frame with mesh node latlong coordinates (x, y) and the selected field values at the mesh nodes (z)
5858
#' @export
5959
create_prediction_field <- function(mesh,
6060
plot_type = "predicted_mean_fields",

R/plot_graph.R

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#' Plot a bar chart using ggplot2
22
#'
3-
#' @param data Data to plot
4-
#' @param x x-axis data
3+
#' @param data Data to plot (all data types recognised by ggplot2::geom_bar() like data.frame)
4+
#' @param x x-axis data, must be a Date object
55
#' @param y y-axis data
6-
#' @param breaks Break points
6+
#' @param breaks Break points, must be a sequence of dates
77
#' @param x_label x-axis label
88
#' @param y_label y-axis label
99
#' @param fill Fill colour
@@ -47,10 +47,10 @@ plot_barchart <- function(data, x, y, breaks, x_label, y_label, fill = "pink", c
4747

4848
#' Plot a boxplot using ggplot2
4949
#'
50-
#' @param data Data to plot
51-
#' @param x x-axis data
50+
#' @param data Data to plot (all data types recognised by ggplot2::geom_boxplot() like data.frame)
51+
#' @param x x-axis data, must be a Date object
5252
#' @param y y-axis data
53-
#' @param breaks Break points
53+
#' @param breaks Break points, must be a sequence of dates
5454
#' @param x_label x-axis label
5555
#' @param y_label y-axis label
5656
#'
@@ -82,19 +82,19 @@ plot_boxplot <- function(data, x, y, breaks, x_label, y_label) {
8282

8383
#' Plot timeseries data
8484
#'
85-
#' @param data Data to plot
86-
#' @param x Name of column to plot on x-axis, should be datetime, will be converted to Dates using as.Date
85+
#' @param data Data to plot (data.frame with x-axis column a character convertible to Date)
86+
#' @param x Name of column to plot on x-axis
8787
#' @param y Name of column to plot on y-axis
88-
#' @param breaks Date break points
88+
#' @param breaks Date break points, must be a sequence of dates
8989
#' @param x_label x-axis label
9090
#' @param y_label y-axis label
9191
#' @param title Figure title
9292
#' @param line_width Line width
9393
#' @param line_colour Line colour
9494
#' @param horizontal_y y-intercept for horizontal line
9595
#' @param vertical_x x-intercept for vertical line
96-
#' @param x_lim Limits for x-axis continous scale, vector passed to scale_x_continuous
97-
#' @param y_lim Limits for y-axis continuous scale, vector passed to scale_y_continous
96+
#' @param x_lim Limits for x-axis continuous scale, vector passed to scale_x_continuous
97+
#' @param y_lim Limits for y-axis continuous scale, vector passed to scale_y_continuous
9898
#'
9999
#' @return ggplot
100100
#' @export
@@ -172,12 +172,12 @@ plot_timeseries <- function(data,
172172

173173
#' Create a line plot with a confidence interval.
174174
#'
175-
#' @param data Data to plot
176-
#' @param x x-axis data
175+
#' @param data Data to plot (all data types recognised by ggplot2::geom_line() like data.frame)
176+
#' @param x x-axis data, must be a Date object
177177
#' @param y1 y1 line data - solid
178178
#' @param y2 y2 line data - dashed
179179
#' @param y3 y3 line data - dashed
180-
#' @param breaks Breaks vector
180+
#' @param breaks Breaks vector, must be a sequence of dates
181181
#' @param x_label x-axis label
182182
#' @param y_label y-axis label
183183
#' @param y1_colour Colour for y1

R/plot_mapping.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
#' The leaflet backend will work for most use cases and is recommended.
77
#' For plotting of maps with UTM coordinates, the mapview backend is recommended.
88
#'
9-
#' @param polygon_data Polygon data
10-
#' @param raster_data Raster datas
11-
#' @param domain Domain data to be passed to leaflet::colorNumeric and leaflet::addLegend
12-
#' @param markers Markers to display on map. A named list with latitude, longitude and label names must be given.
9+
#' @param polygon_data Polygon data (SpatialPolygon or SpatialPolygonDataFrame)
10+
#' @param raster_data Raster data (RasterLayer or SpatialRaster)
11+
#' @param domain Domain data (numeric or factor) to be passed to leaflet::colorNumeric and leaflet::addLegend
12+
#' @param markers Markers to display on map. A named list or data.frame with latitude, longitude and label names must be given.
1313
#' @param palette Palette to be used for colours, defaults to viridis
1414
#' @param legend_title Title for legend
1515
#' @param add_scale_bar Add scale bar if TRUE
@@ -71,10 +71,10 @@ plot_map <- function(polygon_data = NULL,
7171

7272
#' Create a simple Leaflet map from data
7373
#'
74-
#' @param polygon_data Polygon data
75-
#' @param raster_data Raster data
76-
#' @param domain Domain data to be passed to leaflet::colorNumeric and leaflet::addLegend
77-
#' @param markers Markers to display on map. A named list with latitude, longitude and label names must be given.
74+
#' @param polygon_data Polygon data (SpatialPolygon or SpatialPolygonDataFrame)
75+
#' @param raster_data Raster data (RasterLayer or SpatialRaster)
76+
#' @param domain Domain data (numeric or factor) to be passed to leaflet::colorNumeric and leaflet::addLegend
77+
#' @param markers Markers to display on map. A named list or data.frame with latitude, longitude and label names must be given.
7878
#' @param palette Palette to be used for colours, defaults to viridis
7979
#' @param legend_title Title for legend
8080
#' @param add_scale_bar Add scale bar if TRUE

R/plot_mesh.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#' Plot a mesh on a Leaflet map
22
#'
3-
#' @param mesh Mesh data
3+
#' @param mesh Mesh object from INLA or fmesher
44
#' @param spatial_data Spatial data, either a SpatialPolygonsDataFrame, SpatialPointsDataFrame or an object
55
#' that can be converted to a data.frame with longitude and latitude columns
6-
#' @param longitude_column Longitude column in spatial_data
7-
#' @param latitude_column Latitude column in spatial_data name
6+
#' @param longitude_column Longitude column name in spatial_data
7+
#' @param latitude_column Latitude column name in spatial_data
88
#' @param markers Markers to display on top of mesh. A named list with latitude, longitude and label names must be given.
99
#' Expects longitude name to be longitude, latitude name to be latitude, label name to be label.
1010
#'
11-
#' @return leaflet::leaflet
11+
#' @return leaflet::leaflet with mesh and markers
1212
#' @export
1313
plot_mesh <- function(mesh, spatial_data = NULL, longitude_column = "LONG", latitude_column = "LAT", markers = NULL) {
1414
expected_crs <- "+proj=longlat +datum=WGS84"

R/plot_priors.R

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#' Plot line comparison for stdev etc
22
#'
3-
#' @param data Parsed model output
3+
#' @param data List of parsed model outputs from "parse_model_output" (a list of lists)
44
#' @param to_plot Type of data to plot, "Range for f" etc
5+
#' @param title Title of the plot, defaults to the value of "to_plot"
56
#'
6-
#' @return ggplot2::ggplot
7-
plot_line_comparison <- function(data, to_plot, title) {
7+
#' @return ggplot2::ggplot of the selected hyperparameter posterior distribution
8+
plot_line_comparison <- function(data, to_plot, title = to_plot) {
89
parsed_data <- purrr::map(data, function(x) as.data.frame(x$pars[[to_plot]]))
910
single_df <- dplyr::bind_rows(parsed_data, .id = "Run")
1011
if (nrow(single_df) == 0) {
@@ -19,9 +20,9 @@ plot_line_comparison <- function(data, to_plot, title) {
1920

2021
#' Create boxplots from priors run data
2122
#'
22-
#' @param data
23+
#' @param data A list of parsed model output from "parse_model_output" (a list of lists)
2324
#'
24-
#' @return graphics::boxplot
25+
#' @return graphics::boxplot of fitted values
2526
plot_priors_boxplot <- function(data) {
2627
# TODO - I'm sure this can be done in a nicer functional way
2728
fitted_mean_post <- purrr::map(data, function(x) x$fitted_mean_post)
@@ -34,10 +35,10 @@ plot_priors_boxplot <- function(data) {
3435
#' Plot density function
3536
#'
3637
#'
37-
#' @param data Parsed model outputs
38-
#' @param measurement_data Measurement data
38+
#' @param data List of parsed model outputs from "parse_model_output" (a list of lists)
39+
#' @param measurement_data Measurement data (can be data.frame, SpatialPoints/SpatialPointsDataFrame, or simple feature collection)
3940
#'
40-
#' @return ggplot2::ggplot
41+
#' @return ggplot2::ggplot of measurement density by value
4142
plot_priors_density <- function(data, measurement_data) {
4243
# Can this be done in a cleaner way? Just create a dataframe from the lists?
4344
fitted_values <- unlist(purrr::map(data, function(x) x$fitted_mean_post))
@@ -56,9 +57,9 @@ plot_priors_density <- function(data, measurement_data) {
5657

5758
#' Plot Deviance Information Criterion (DIC) values
5859
#'
59-
#' @param data
60+
#' @param data List of parsed model outputs from "parse_model_output" (a list of lists)
6061
#'
61-
#' @return ggplot2::ggplot
62+
#' @return ggplot2::ggplot with DIC values shown as points
6263
plot_dic <- function(data) {
6364
infocri <- base::cbind.data.frame(
6465
priors = unlist(purrr::map(seq(1, length(data)), function(x) paste("Run", x))),

R/shiny_meshbuilder.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#' Mesh building shiny app
22
#'
3-
#' @param spatial_data Spatial data
3+
#' @param spatial_data Spatial data (must be a data.frame, SpatialPointsDataFrame or SpatialPolygonsDataFrame)
44
#' @param obs_data Measurement data
55
#' @param crs CRS as a proj4string
66
#' @param offset Specifies the size of the inner and outer extensions around data locations, passed to fmesher::fm_mesh_2d_inla
@@ -11,7 +11,7 @@
1111
#'
1212
#' @importFrom magrittr %>%
1313
#'
14-
#' @return shiny::app
14+
#' @return shiny::app with meshbuilder functionality
1515
#' @keywords internal
1616
meshbuilder_shiny <- function(
1717
spatial_data,
@@ -55,10 +55,10 @@ meshbuilder_shiny <- function(
5555
stop("Cannot read latitude and longitude data from spatial data. Please ensure given names are correct.")
5656
}
5757

58-
default_max_edge_min <- 0.01
59-
default_max_edge_max <- 0.3
58+
default_max_edge_min <- 0.9
59+
default_max_edge_max <- 1.8
6060
default_offset_min <- 0.02
61-
default_offset_max <- 0.2
61+
default_offset_max <- 2
6262
default_cutoff <- 0.02
6363
# TODO - these defaults need changing?
6464
if (!is.null(max_edge)) {
@@ -234,7 +234,7 @@ meshbuilder_shiny <- function(
234234
spatial_data
235235
}
236236
})
237-
237+
238238
output$map <- leaflet::renderLeaflet({
239239
map_tiles <- c("OpenStreetMap", "Esri.WorldImagery", "OpenTopoMap")
240240
m <- mapview::mapview(mesh_spatial(), layer.name = "Mesh", col.regions = "#548C2F", map.types = map_tiles) + mapview::mapview(spatial(), layer.name = "Spatial")
@@ -270,7 +270,7 @@ meshbuilder_shiny <- function(
270270

271271
#' Mesh building shiny app. Creates and visualises a mesh from some spatial data.
272272
#'
273-
#' @param spatial_data Spatial data
273+
#' @param spatial_data Spatial data (must be a data.frame, SpatialPointsDataFrame or SpatialPolygonsDataFrame)
274274
#' @param obs_data Measurement data
275275
#' @param crs CRS as a proj4string
276276
#' @param offset Specifies the size of the inner and outer extensions around data locations, passed to fmesher::fm_mesh_2d_inla
@@ -279,7 +279,7 @@ meshbuilder_shiny <- function(
279279
#' @param y_coord Name of the latitude column in the spatial data
280280
#' @param x_coord Name of the longitude column in the spatial data
281281
#'
282-
#' @return shiny::app
282+
#' @return shiny::app with meshbuilder functionality
283283
#' @export
284284
mesh_builder <- function(spatial_data, obs_data = NULL, crs = NULL, max_edge = NULL, offset = NULL, cutoff = NULL, y_coord = "LAT", x_coord = "LONG") {
285285
shiny::runApp(meshbuilder_shiny(

0 commit comments

Comments
 (0)