combine_sources: Combine the dietary proportions from two food sources after...

View source: R/combine_sources.R

combine_sourcesR Documentation

Combine the dietary proportions from two food sources after running simmr

Description

This function takes in an object of class simmr_output and combines two of the food sources. It works for single and multiple group data.

Usage

combine_sources(
  simmr_out,
  to_combine = NULL,
  new_source_name = "combined_source"
)

Arguments

simmr_out

An object of class simmr_output created from simmr_mcmc or simmr_ffvb

to_combine

The names of exactly two sources. These should match the names given to simmr_load.

new_source_name

A name to give to the new combined source.

Details

Often two sources either (1) lie in similar location on the iso-space plot, or (2) are very similar in phylogenetic terms. In case (1) it is common to experience high (negative) posterior correlations between the sources. Combining them can reduce this correlation and improve precision of the estimates. In case (2) we might wish to determine the joint amount eaten of the two sources when combined. This function thus combines two sources after a run of simmr_mcmc or simmr_ffvb (known as a posteriori combination). The new object can then be called with plot.simmr_input or plot.simmr_output to produce iso-space plots of summaries of the output after combination.

Value

A new simmr_output object

Author(s)

Andrew Parnell <andrew.parnell@mu.ie>, Emma Govan

See Also

See simmr_mcmc and simmr_ffvb and the associated vignette for examples.

Examples


# The data
data(geese_data)

# Load into simmr
simmr_1 <- with(
  geese_data_day1,
  simmr_load(
    mixtures = mixtures,
    source_names = source_names,
    source_means = source_means,
    source_sds = source_sds,
    correction_means = correction_means,
    correction_sds = correction_sds,
    concentration_means = concentration_means
  )
)

# Plot
plot(simmr_1)

# Print
simmr_1

# MCMC run
simmr_1_out <- simmr_mcmc(simmr_1)

# Print it
print(simmr_1_out)

# Summary
summary(simmr_1_out)
summary(simmr_1_out, type = "diagnostics")
summary(simmr_1_out, type = "correlations")
summary(simmr_1_out, type = "statistics")
ans <- summary(simmr_1_out, type = c("quantiles", "statistics"))

# Plot
plot(simmr_1_out)
plot(simmr_1_out, type = "boxplot")
plot(simmr_1_out, type = "histogram")
plot(simmr_1_out, type = "density")
plot(simmr_1_out, type = "matrix")

simmr_out_combine <- combine_sources(simmr_1_out,
  to_combine = c("U.lactuca", "Enteromorpha"),
  new_source_name = "U.lac+Ent"
)
plot(simmr_out_combine$input)
plot(simmr_out_combine, type = "boxplot", title = "simmr output: combined sources")


simmr documentation built on Nov. 2, 2023, 6:08 p.m.