knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>", 
  fig.width = 8, 
  fig.height = 5
)
library(MEMC)
library(ggplot2)
theme_set(theme_bw(base_size = 14))

This example will show how to update the model parameter values for any MEMC model configuration.

# Assumes MEMC has already been installed. 
library(MEMC) 

The MEMC package includes default parameter and initial pool values that are included as package data that are based on Wang et al. 2015^[Wang, G., Jagadamma, S., Mayes, M. et al. Microbial dormancy improves development and experimental validation of ecosystem model. ISME J 9, 226–237 (2015). https://doi.org/10.1038/ismej.2014.120]. This example will use these values and show users how to update these values. We will also be running the MEMC MEND model configuration. \

Default Parameters

Start by taking a look at the default model parameter values.

print(memc_initial_state)
# Alternatively can use the :: to access the MEMC package data. 
# print(MEMC::memc_initial_state)
print(memc_params)
# Alternatively can use the :: to access the MEMC package data. 
# print(MEMC::memc_params)

Run deafult MEMC MEND

Run the pre-configured MEMC MEND model with the default parameter values.

time <- 0:600 
mod1 <- MEND_config
out1 <- memc_solve(mod = mod1, time = time)
out1$name <- "Km = 250 (default)"

Update parameter value

Users can update the parameters directly via memc_solve. Any parameter(s) value(s) fed into the memc_solve params argument will overwrite the parameter values defined the model configuration.

out2 <- memc_solve(mod = MEND_config, time = time, params = c("K_m" = 10))
out2$name <- "Km = 10 (lower)"
ggplot(data = rbind(out1, out2)) + 
  geom_line(aes(time, value, color = name, linetype = name), linewidth = 0.75) + 
  facet_wrap("variable", scales = "free") + 
  labs(y = "mg C/g soil", 
       title = "Change Km Values") +
  theme(legend.title = element_blank())

Update parameter table using memc_update_params

memc_update_params is a helper function that can change the parameter values in the parameter table. You will need to set up a new model configuration with the new parameter table.

new_km <- memc_update_params(new_params = c("K_m" = 100), param_table = memc_params)

# Set up the new model configuration with the 
mod_km <- memc_configure(params = new_km, 
                        state = memc_initial_state,
                        name = "Km = 100", 
                        DOMuptake = "MM",
                        POMdecomp = "MM",
                        MBdecay = "LM")

out3 <- memc_solve(mod = mod_km, time = time)
ggplot(data = rbind(out1, out2, out3)) + 
  geom_line(aes(time, value, color = name, linetype = name), linewidth = 0.75) + 
  facet_wrap("variable", scales = "free") + 
  labs(y = "mg C/g soil", 
       title = "Change Km Values") +
  theme(legend.title = element_blank())


Microbial-Explicit-Model/MEMC documentation built on April 12, 2025, 12:50 p.m.