knitr::opts_chunk$set(comment='.',fig.path="inst/img/README-")
devtools:::install_github("kylebaron/klava")
requireNamespace("nlme")
library(dplyr) library(mrgsolve) library(nloptr) library(ggplot2) library(rlang) library(klava)
Load an mrgsolve model
mod <- modlib("pk2")
data <- readRDS("inst/dat/2cmtA.RDS") ggplot(data, aes(time,DV)) + geom_point() + theme_bw()
The data is more or less in NONMEM-type format
data
theta <- all_log(CL = 0.5, V2 = 50, Q = 1.1, V3 = 30, KA = 1.1, sigma=1.1)
This is a self-transforming vector
theta
trans(theta)
That also supports fixed values
foo <- quick_par(CL = log(1), KA = fixed(1.1), F1 = logit(0.8)) foo trans(foo) untrans(trans(foo))
fit <- fit_nl(theta, data, mod = mod, pred_name= "CP", cov_step=TRUE, pred_initial=TRUE)
Result
fit$tab
plot(fit)
ggplot(fit$data, aes(time,RES)) + geom_point() + geom_hline(yintercept=0) + theme_bw()
ggplot(fit$data, aes(PRED,DV)) + geom_point() + geom_abline(intercept = 0, slope = 1) + theme_bw()
Extended Least Squares - ELS
fit <- fit_nl(theta, data, mod, pred_name= "CP", ofv=els)
Normal likelihood
fit <- fit_nl(theta, data, mod, pred_name= "CP", ofv=ml)
Ordinary Least Squares - OLS
fit <- fit_nl(theta, data, mod, pred_name= "CP", ofv=ols)
Weighted Least Squares - WLS
fit <- fit_nl(theta, data, mod, pred_name= "CP", ofv=wls)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.