# Generate five datasets following DFOP-SFO kinetics
sampling_times = c(0, 1, 3, 7, 14, 28, 60, 90, 120)
dfop_sfo <- mkinmod(parent = mkinsub("DFOP", "m1"),
m1 = mkinsub("SFO"), quiet = TRUE)
set.seed(1234)
k1_in <- rlnorm(5, log(0.1), 0.3)
k2_in <- rlnorm(5, log(0.02), 0.3)
g_in <- plogis(rnorm(5, qlogis(0.5), 0.3))
f_parent_to_m1_in <- plogis(rnorm(5, qlogis(0.3), 0.3))
k_m1_in <- rlnorm(5, log(0.02), 0.3)
pred_dfop_sfo <- function(k1, k2, g, f_parent_to_m1, k_m1) {
mkinpredict(dfop_sfo,
c(k1 = k1, k2 = k2, g = g, f_parent_to_m1 = f_parent_to_m1, k_m1 = k_m1),
c(parent = 100, m1 = 0),
sampling_times)
}
ds_mean_dfop_sfo <- lapply(1:5, function(i) {
mkinpredict(dfop_sfo,
c(k1 = k1_in[i], k2 = k2_in[i], g = g_in[i],
f_parent_to_m1 = f_parent_to_m1_in[i], k_m1 = k_m1_in[i]),
c(parent = 100, m1 = 0),
sampling_times)
})
names(ds_mean_dfop_sfo) <- paste("ds", 1:5)
ds_syn_dfop_sfo <- lapply(ds_mean_dfop_sfo, function(ds) {
add_err(ds,
sdfunc = function(value) sqrt(1^2 + value^2 * 0.07^2),
n = 1)[[1]]
})
if (FALSE) {
# Evaluate using mmkin and saem
f_mmkin_dfop_sfo <- mmkin(list(dfop_sfo), ds_syn_dfop_sfo,
quiet = TRUE, error_model = "tc", cores = 5)
f_saem_dfop_sfo <- saem(f_mmkin_dfop_sfo)
print(f_saem_dfop_sfo)
illparms(f_saem_dfop_sfo)
f_saem_dfop_sfo_2 <- update(f_saem_dfop_sfo,
no_random_effect = c("parent_0", "log_k_m1"))
illparms(f_saem_dfop_sfo_2)
intervals(f_saem_dfop_sfo_2)
summary(f_saem_dfop_sfo_2, data = TRUE)
# Add a correlation between random effects of g and k2
cov_model_3 <- f_saem_dfop_sfo_2$so@model@covariance.model
cov_model_3["log_k2", "g_qlogis"] <- 1
cov_model_3["g_qlogis", "log_k2"] <- 1
f_saem_dfop_sfo_3 <- update(f_saem_dfop_sfo,
covariance.model = cov_model_3)
intervals(f_saem_dfop_sfo_3)
# The correlation does not improve the fit judged by AIC and BIC, although
# the likelihood is higher with the additional parameter
anova(f_saem_dfop_sfo, f_saem_dfop_sfo_2, f_saem_dfop_sfo_3)
}
Run the code above in your browser using DataLab