Title: | Create Simple Predictive Models on Bayesian Belief Networks |
---|---|
Description: | A system to build, visualise and evaluate Bayesian belief networks. The methods are described in Stafford et al. (2015) <doi:10.12688/f1000research.5981.1>. |
Authors: | Victoria Dominguez Almela [cre, aut]
|
Maintainer: | Victoria Dominguez Almela <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.1.0 |
Built: | 2025-02-22 05:56:40 UTC |
Source: | https://github.com/vda1r22/bbnet |
bbn.network.diagram()
generates a network diagram from a specified Bayesian Belief Network (BBN
),
allowing for the visualization of the relationships and interactions between nodes
.
bbn.network.diagram( bbn.network, font.size = 0.7, arrow.size = 4, arrange = layout_on_sphere )
bbn.network.diagram( bbn.network, font.size = 0.7, arrow.size = 4, arrange = layout_on_sphere )
bbn.network |
A dataframe, with a first column called |
font.size |
Changes the font in the figure produced. Default = 0.7.
The value here is a multiplier of the default font size used in the |
arrow.size |
Changes the size of the arrows. Default = 4. Note, sizes do vary based on interaction strength, so this is a multiplier for visualisation purposes. Negative interactions are shown by red arrows, and positive interactions by black arrows. |
arrange |
this describes how the final diagram looks.
Default is |
The diagram is created using edge
and node
data derived from the BBN
, with edges
representing
interactions (positive or negative) between nodes
.
bbn.network.diagram()
visualises all nodes
and interactions in a network, in a similar manner to bbn.visualise
, other than this is the full network.
A plot of the network diagram, illustrating the interactions (both positive and negative) between nodes
.
data(my_network) bbn.network.diagram(bbn.network = my_network, font.size=0.7, arrow.size=4, arrange = layout_on_sphere)
data(my_network) bbn.network.diagram(bbn.network = my_network, font.size=0.7, arrow.size=4, arrange = layout_on_sphere)
bbn.predict
performs predictions using a Bayesian Belief Network (BBN)
model,
accommodating multiple priors
scenarios and allowing for bootstrapping
to assess variability.
bbn.predict( bbn.model, ..., boot_max = 1, values = 1, figure = 1, font.size = 5 )
bbn.predict( bbn.model, ..., boot_max = 1, values = 1, figure = 1, font.size = 5 )
bbn.model |
A matrix or dataframe of interactions between different model |
... |
An X by 2 array of initial changes to the system under investigation.
It requires at least 1 prior scenario (up to 12 priors).
The first column should be a -4 to 4 (including 0) integer value for each |
boot_max |
The number of bootstraps to perform. Suggested range for exploratory analysis 1-1000.
For final analysis recommended size = 1000 - 10000 - note, this can take a long time to run.
Default value is 1, running with no |
values |
This provides a numeric output of |
figure |
Sets the figure options. Default value 1. 0 = no figures produced. 1 = figure is saved in working directory as a PDF file (note, this is overwritten if the name is not changed, and no figure is produced if the existing PDF is open when the new one is generated). 2 = figure is produced in a graphics window. All figures are combined on a single plot where scenario 2 is below scenario 1 (i.e. scenarios work in columns then rows) |
font.size |
Font size for the plot labels. Defaults to 5. |
Supports input of multiple priors
through ellipsis()
.
Allows bootstrapping
with a specified number of maximum iterations to assess prediction variability.
Generates plots
for visual representation of the predictions.
Plots of the (BBN)
predictions and optionally prints the predicted values.
data(my_BBN, combined) bbn.predict(bbn.model = my_BBN, priors1 = combined, boot_max=100, values=1, figure=1, font.size=5)
data(my_BBN, combined) bbn.predict(bbn.model = my_BBN, priors1 = combined, boot_max=100, values=1, figure=1, font.size=5)
bbn.sensitivity()
conducts a sensitivity analysis on a Bayesian Belief Network (BBN
) model.
It evaluates the impact of varying key node
on the network's outcomes using bootstrapping
.
The analysis helps identify which node
significantly influence the network, providing insights into the robustness and dependency of the network's structure.
bbn.sensitivity(bbn.model, boot_max = 1000, ...)
bbn.sensitivity(bbn.model, boot_max = 1000, ...)
bbn.model |
a matrix or dataframe of interactions between different model |
boot_max |
The number of bootstraps to perform. Suggested range for exploratory analysis 100-1000. For final analysis recommended size = 1000 - 10000 - note, this can take a long time to run. Default value is 1000. |
... |
Key |
The function outputs a plot showing the nodes
most influential to the network's outcomes, alongside a table ranking these variables by their impact.
The analysis highlights how changes in the key nodes
can affect the network, offering valuable insights for model refinement and decision-making.
data(my_BBN) bbn.sensitivity(bbn.model = my_BBN, boot_max = 100, 'Limpet', 'Green Algae')
data(my_BBN) bbn.sensitivity(bbn.model = my_BBN, boot_max = 100, 'Limpet', 'Green Algae')
bbn.timeseries()
performs time series predictions using a Bayesian Belief Network (BBN
) model based on a single prior
scenario.
It generates figures illustrating how parameters change over time for all or selected nodes
.
bbn.timeseries(bbn.model, priors1, timesteps = 5, disturbance = 1)
bbn.timeseries(bbn.model, priors1, timesteps = 5, disturbance = 1)
bbn.model |
A matrix or dataframe of interactions between different model |
priors1 |
An X by 2 array of initial changes to the system under investigation.
The first column should be a -4 to 4 (including 0) integer value for each |
timesteps |
This is the number of |
disturbance |
Default = 1.
1 creates a prolonged or press |
Plots for each node
showing the predicted change over time.
data(my_BBN, combined) bbn.timeseries(bbn.model = my_BBN, priors1 = combined, timesteps=6, disturbance=1)
data(my_BBN, combined) bbn.timeseries(bbn.model = my_BBN, priors1 = combined, timesteps=6, disturbance=1)
bbn.visualise()
visualises the outcomes of a Bayesian Belief Network (BBN
) model over time,
given a single prior
scenario. It highlights the changes in network parameters across specified timesteps
and visualises the strength and direction of interactions among nodes
based on the specified disturbance
and threshold
parameters.
bbn.visualise( bbn.model, priors1, timesteps = 5, disturbance = 1, threshold = 0.2, font.size = 0.7, arrow.size = 4 )
bbn.visualise( bbn.model, priors1, timesteps = 5, disturbance = 1, threshold = 0.2, font.size = 0.7, arrow.size = 4 )
bbn.model |
A matrix or dataframe of interactions between different model |
priors1 |
An X by 2 array of initial changes to the system under investigation.
The first column should be a -4 to 4 (including 0) integer value for each |
timesteps |
This is the number of |
disturbance |
Default = 1.
1 creates a prolonged or press |
threshold |
|
font.size |
Changes the font in the figure produced. Default = 0.7.
The value here is a multiplier of the default font size used in the |
arrow.size |
Changes the size of the arrows. Default = 4. Note, sizes do vary based on interaction strength, so this is a multiplier for visualisation purposes. |
A plot of the BBN
, illustrating the dynamic interactions between nodes
over the specified timesteps
.
data(my_BBN, combined) bbn.visualise(bbn.model = my_BBN, priors1 = combined, timesteps=6, disturbance=1, threshold=0.2, font.size=0.7, arrow.size=4)
data(my_BBN, combined) bbn.visualise(bbn.model = my_BBN, priors1 = combined, timesteps=6, disturbance=1, threshold=0.2, font.size=0.7, arrow.size=4)
This dataset represents the numerical changes in species populations on a rocky shore ecosystem due to the combined treatment of removing dogwhelks and adding periwinkles. It reflects the complex interactions and potential synergistic effects of multiple ecological interventions.
A data frame with 9 rows and 2 columns:
integer
Variable names
<https://doi.org/10.1016/j.ocecoaman.2015.04.013>
This dataset represents the numerical changes in species populations on a rocky shore ecosystem due to the removal of dogwhelks. It provides insights into the potential ecological impacts of removing a predatory species.
A data frame with 9 rows and 2 columns:
integer
Variable names
<https://doi.org/10.1016/j.ocecoaman.2015.04.013>
This function determines whether the provided object is empty.
isEmpty(x)
isEmpty(x)
x |
The object to check for emptiness. |
isEmpty()
checks if the given object, x
, has a length of 0,
indicating that it is empty. It can be used with various types of objects
in R, including vectors, lists, and data frames.
A logical value: TRUE
if the object is empty, FALSE
otherwise.
# Check an empty vector isEmpty(c()) # Check a non-empty vector isEmpty(c(1, 2, 3)) # Check an empty list isEmpty(list()) # Check a non-empty list isEmpty(list(a = 1, b = 2)) # Check an empty data frame isEmpty(data.frame()) # Check a non-empty data frame isEmpty(mtcars)
# Check an empty vector isEmpty(c()) # Check a non-empty vector isEmpty(c(1, 2, 3)) # Check an empty list isEmpty(list()) # Check a non-empty list isEmpty(list(a = 1, b = 2)) # Check an empty data frame isEmpty(data.frame()) # Check a non-empty data frame isEmpty(mtcars)
This dataset represents an interaction model of marine protected area and ecological components This is an example dataset loosely based on Lundy Island MCZ.
A data frame with 11 rows and 12 columns:
Variable names
integer
integer
integer
integer
integer
integer
integer
integer
integer
integer
integer
<unpublished work by Rick Stafford>
This function allows for the arrangement and display of multiple ggplot2
plots on a single graphics page.
multiplot(..., plotlist = NULL, file, cols = 1, layout = NULL)
multiplot(..., plotlist = NULL, file, cols = 1, layout = NULL)
... |
One or more |
plotlist |
An optional list of |
file |
A path to save the output file. |
cols |
Specifies the number of columns in the grid layout if |
layout |
An optional matrix specifying the layout of plots. Overrides |
multiplot()
can take any number of plot objects as arguments, or if it can take a list of plot objects passed to plotlist.
multiplot()
is built under CC0 licence from:
http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/
ggplot2
objects can be passed in ..., or to plotlist (as a list of ggplot2
objects)
Details:
cols: Number of columns in layout.
layout: A matrix specifying the layout.If present, cols
is ignored.
If the layout is something like matrix(c(1,2,3,3), nrow=2, byrow=TRUE)
, then plot 1 will go in the upper left, 2 will go in the upper right, and 3 will go all the way across the bottom.
plot
# Load necessary library library(ggplot2) # Create example ggplot objects plot1 <- ggplot(mtcars, aes(x=mpg, y=wt)) + geom_point() plot2 <- ggplot(mtcars, aes(x=mpg, y=cyl)) + geom_point() plot3 <- ggplot(mtcars, aes(x=gear, y=wt)) + geom_point() # Plot all three plots in a single row multiplot(plot1, plot2, plot3, cols=3) # Plot using a custom layout layout_matrix <- matrix(c(1,2,3,3), nrow=2, byrow=TRUE) multiplot(plotlist=list(plot1, plot2, plot3), layout=layout_matrix)
# Load necessary library library(ggplot2) # Create example ggplot objects plot1 <- ggplot(mtcars, aes(x=mpg, y=wt)) + geom_point() plot2 <- ggplot(mtcars, aes(x=mpg, y=cyl)) + geom_point() plot3 <- ggplot(mtcars, aes(x=gear, y=wt)) + geom_point() # Plot all three plots in a single row multiplot(plot1, plot2, plot3, cols=3) # Plot using a custom layout layout_matrix <- matrix(c(1,2,3,3), nrow=2, byrow=TRUE) multiplot(plotlist=list(plot1, plot2, plot3), layout=layout_matrix)
This dataset represents a simplified food web of a rocky shore ecosystem, focusing on the interactions between various species. The data was used to study the effects of various ecological interventions and their effects, as described in the associated paper.
A data frame with 9 rows and 10 columns:
Row names, representing various species
integer
integer
integer
integer
integer
integer
integer
integer
integer
<https://doi.org/10.1016/j.ocecoaman.2015.04.013>
In this file, the first column is called id and consists of an s and a 2 digit number relating to the node number. The second column is called node.type and is an integer value from 1-4. This sets the colour of the node in the network (sticking to a maximum of four colours). Here, predators, grazers, filter feeders and algae are colour coded separately it would be fine to change the colours, for example to ensure algae were green. The third column is the same as the first column in the standard BBN interaction csv, other than it is titled node.name. It is important to use these column names (including capitals and dot notation). The remainder of the columns are exactly as the standard my_BBN data file.
A data frame with 9 rows and 12 columns:
Variable names
integer
Variable names
integer
integer
integer
integer
integer
integer
integer
integer
integer
<https://doi.org/10.1016/j.ocecoaman.2015.04.013>
Dataset represents banning potting (for crabs / lobsters etc) in a Marine Protected Area Data presents insights into how management measures may affect ecological communities in MPAs
A data frame with 11 rows and 2 columns:
integer
Variable names
<unpublished work by Rick Stafford>
Data presents insights into how management measures may affect ecological communities in MPAs
A data frame with 11 rows and 2 columns:
integer
Variable names
<unpublished work by Rick Stafford>
This dataset represents the numerical changes in species populations on a rocky shore ecosystem due to the addition of periwinkles. It captures the direct interventions and expected ecological shifts as modeled in the study.
A data frame with 9 rows and 2 columns:
integer
Variable names
<https://doi.org/10.1016/j.ocecoaman.2015.04.013>