# Wambaugh et al. (2018): Estimating TK Parameters from In Vivo Data

#### John Wambaugh and Caroline Ring

#### 2025-03-24

To use the code in this vignette, you’ll first need to load a few packages (if you haven’t already).

    library(invivoPKfit)

# Initialized the Random Number Generator:

    TeachingDemos::char2seed("Caroline Ring")

# Do the noncompartment model fit

    system.time(PK.fit.table.noncomp <- invivoPKfit::fit_all(data.set=pkdataset_nheerlcleaned, model="noncompartment"))

    saveRDS(PK.fit.table.noncomp , paste("output/PK_fit_table_noncomp-",Sys.Date(),".rda",sep=""))

# Do the 2-compartment model fit

    system.time(PK.fit.table.2comp  <- invivoPKfit::fit_all(pkdataset_nheerlcleaned, model="2compartment", modelfun="analytic"))

    saveRDS(PK.fit.table.2comp, paste("output/PK_fit_table_2comp-",Sys.Date(),".rda",sep=""))

# Plot the 2-compartment concentration vs. time

    junk <- plot_conctime(PK.fit.table=PK.fit.table.2comp,
                          data.set=pkdataset_nheerlcleaned,
                          model="2compartment")

# Do the 1-compartment model fit

    system.time(PK.fit.table.1comp <- invivoPKfit::fit_all(data.set=pkdataset_nheerlcleaned, model="1compartment", modelfun="analytic"))

    saveRDS(PK.fit.table.1comp, paste("output/PK_fit_table_1comp-",Sys.Date(),".rda",sep=""))

# Plot one compartment concentration vs. time

    junk <- plot_conctime(PK.fit.table=PK.fit.table.1comp,
                          data.set=pkdataset_nheerlcleaned,
                          model="1compartment")

# Output the dataset analyzed:

    write.csv(pkdataset_nheerlcleaned[order(pkdataset_nheerlcleaned$Compound),],"SupTable1.txt",row.names=F)
    write.csv(pkdataset_nheerlcleaned[order(pkdataset_nheerlcleaned$Compound),],file=paste("InVivoData-",Sys.Date(),".txt",sep=""),row.names=F)
    save(pkdataset_nheerlcleaned,file=paste("PKdata-",Sys.Date(),".RData",sep=""))