\input{settings.sty}
\usepackage{Sweave}

 
\begin{document}
\vspace*{2cm}
\begin{center}
{\Large Parameter Table}\\
~\\
\today\\
~\\
Tim Bergsma\\
\end{center}
\newpage

\section{Purpose}
This script picks up after model.Rnw to process bootstrap results and make a parameter table.
\subsection{Package}
\begin{Schunk}
\begin{Sinput}
> getwd()
\end{Sinput}
\begin{Soutput}
[1] "/home/timb/metrumrg/inst/sample/script"
\end{Soutput}
\begin{Sinput}
> require(metrumrg)
\end{Sinput}
\begin{Soutput}
metrumrg 5.0 
\end{Soutput}
\end{Schunk}
\section{Parameter Table}
\begin{Schunk}
\begin{Sinput}
> tab <- wikitab(1005,'../nonmem')
> tab
\end{Sinput}
\begin{Soutput}
   parameter                                   description
1     THETA1                       apparent oral clearance
2     THETA2                central volume of distribution
3     THETA3                      absorption rate constant
4     THETA4                  intercompartmental clearance
5     THETA5             peripheral volume of distribution
6     THETA6                      male effect on clearance
7     THETA7                    weight effect on clearance
8   OMEGA1.1      interindividual variability of clearance
9   OMEGA2.2 interindividual variability of central volume
10  OMEGA3.3             interindividual variability of Ka
11  SIGMA1.1                            proportional error
                                                                model tool  run
1  CL/F (L/h) ~ theta_1 *  theta_6 ^MALE * (WT/70)^theta_7  * e^eta_1  nm7 1005
2                          V_c /F (L) ~ theta_2 * (WT/70)^1 * e^eta_2  nm7 1005
3                                     K_a (h^-1 ) ~ theta_3 * e^eta_3  nm7 1005
4                                                 Q/F (L/h) ~ theta_4  nm7 1005
5                                                V_p /F (L) ~ theta_5  nm7 1005
6                                                 MALE_CL/F ~ theta_6  nm7 1005
7                                                   WT_CL/F ~ theta_7  nm7 1005
8                                                IIV_CL/F ~ Omega_1.1  nm7 1005
9                                              IIV_V_c /F ~ Omega_2.2  nm7 1005
10                                               IIV_K_a  ~ Omega_3.3  nm7 1005
11                                               err_prop ~ Sigma_1.1  nm7 1005
    estimate prse         se
1    8.57997 9.53   0.817948
2    21.6409 9.34    2.02094
3  0.0684281 8.04 0.00550178
4    3.78411 13.5   0.511271
5    107.376 15.7    16.8344
6   0.998986 14.8   0.148279
7    1.67117 21.7   0.363297
8   0.195776   23  0.0450967
9   0.128574 30.4  0.0391104
10  0.106527 25.3  0.0268981
11  0.067111 11.4 0.00766169
\end{Soutput}
\begin{Sinput}
> tab$estimate <- as.character(signif(as.numeric(tab$estimate),3))
> tab$estimate <- with(tab, paste(estimate,'$',justUnits(model),'$'))
> tab$name <- with(tab, wiki2label(model))
> tab$root <- signif(sqrt(exp(text2decimal(tab$estimate))-1),3)*100
> needcv <- contains('OMEGA|SIGMA',tab$parameter)
> tab <- within(tab, estimate[needcv] <- paste(estimate[needcv],parens(glue('\\%CV=',root[needcv]))))
> tab$root <- NULL
> #offdiag <- contains('2.1',tab$parameter)
> #tab$estimate[offdiag] <- text2decimal(tab$estimate[offdiag])
> #omegablock <- text2decimal(tab$estimate[contains('Omega..(1|2)',tab$parameter)])
> #cor <- signif(half(cov2cor(as.matrix(as.halfmatrix(omegablock))))[[2]],3)
> #tab$estimate[offdiag] <- paste(sep='',tab$estimate[offdiag],' (COR=',cor,')')
> tab$model[is.na(tab$model)] <- ''
> boot <- read.csv('../nonmem/1005.boot/log.csv',as.is=TRUE)
> boot <- boot[boot$moment=='estimate',]
> boot <- data.frame(cast(boot,...~moment))
> boot[] <- lapply(boot,as.character)
> boot <- boot[contains('THETA|OMEGA|SIGMA',boot$parameter),c('parameter','estimate')]
> boot$estimate <- as.numeric(boot$estimate)
> boot <-data.frame(
+   cast(
+     boot,
+     parameter~.,
+     value='estimate',
+     fun=function(x)list(
+       lo=as.character(
+         signif(
+           quantile(
+             x,
+             probs=0.05,
+             na.rm=TRUE
+           ),
+           3
+         )
+       ),
+       hi=as.character(
+         signif(
+           quantile(
+             x,
+             probs=0.95,
+             na.rm=TRUE
+           ),
+           3
+         )
+       )
+     )
+   )
+ )
> boot$CI <- with(boot, parens(glue(lo,',',hi)))
> tab <- stableMerge(tab,boot[,c('parameter','CI')])
> tab <- within(tab, se <- name <- run <- tool <- parameter <- NULL)
> tab$model <- wiki2latex(noUnits(tab$model))
> tab
\end{Sinput}
\begin{Soutput}
                                     description
1                        apparent oral clearance
2                 central volume of distribution
3                       absorption rate constant
4                   intercompartmental clearance
5              peripheral volume of distribution
6                       male effect on clearance
7                     weight effect on clearance
8       interindividual variability of clearance
9  interindividual variability of central volume
10             interindividual variability of Ka
11                            proportional error
                                                                                                           model
1  $\\mathrm{CL/F  \\sim \\theta_{1}\\cdot  \\theta_{6}^{MALE}\\cdot (WT/70)^{\\theta_{7}}\\cdot e^{\\eta_{1}}}$
2                                   $\\mathrm{V_{c}/F  \\sim \\theta_{2}\\cdot (WT/70)^{1}\\cdot e^{\\eta_{2}}}$
3                                                        $\\mathrm{K_{a} \\sim \\theta_{3}\\cdot e^{\\eta_{3}}}$
4                                                                             $\\mathrm{Q/F  \\sim \\theta_{4}}$
5                                                                         $\\mathrm{V_{p}/F  \\sim \\theta_{5}}$
6                                                                       $\\mathrm{MALE_{CL/F}\\sim \\theta_{6}}$
7                                                                         $\\mathrm{WT_{CL/F}\\sim \\theta_{7}}$
8                                                                      $\\mathrm{IIV_{CL/F}\\sim \\Omega_{1.1}}$
9                                                                   $\\mathrm{IIV_{V_{c}/F}\\sim \\Omega_{2.2}}$
10                                                                    $\\mathrm{IIV_{K_{a}}\\sim \\Omega_{3.3}}$
11                                                                     $\\mathrm{err_{prop}\\sim \\Sigma_{1.1}}$
                   estimate prse             CI
1              8.58 $ L/h $ 9.53    (7.17,9.98)
2                21.6 $ L $ 9.34    (18.2,25.2)
3          0.0684 $ h^-1  $ 8.04 (0.0593,0.078)
4              3.78 $ L/h $ 13.5    (3.03,4.77)
5                 107 $ L $ 15.7     (84.8,164)
6                0.999 $  $ 14.8   (0.773,1.31)
7                 1.67 $  $ 21.7     (1.02,2.3)
8   0.196 $  $ (\\%CV=46.5)   23  (0.124,0.266)
9   0.129 $  $ (\\%CV=37.1) 30.4  (0.064,0.187)
10  0.107 $  $ (\\%CV=33.6) 25.3  (0.064,0.152)
11 0.0671 $  $ (\\%CV=26.3) 11.4  (0.0551,0.08)
\end{Soutput}
\end{Schunk}
\begin{table}[!htpb]
 \caption[Model 1005 Parameters]{Parameter Estimates from Population Pharmacokinetic Model Run 1005 \label{p1005}}
 \begin{center}
  \begin{tabular}{lllll}
    \hline \hline
   description & model & estimate & prse & CI \\ \hline
   apparent oral clearance                       & $\mathrm{CL/F  \sim \theta_{1}\cdot  \theta_{6}^{MALE}\cdot (WT/70)^{\theta_{7}}\cdot e^{\eta_{1}}}$ & 8.58 $ L/h $             & 9.53 & (7.17,9.98)    \\
   central volume of distribution                & $\mathrm{V_{c}/F  \sim \theta_{2}\cdot (WT/70)^{1}\cdot e^{\eta_{2}}}$                                  & 21.6 $ L $               & 9.34 & (18.2,25.2)    \\
   absorption rate constant                      & $\mathrm{K_{a} \sim \theta_{3}\cdot e^{\eta_{3}}}$                                                       & 0.0684 $ h^-1  $         & 8.04 & (0.0593,0.078) \\
   intercompartmental clearance                  & $\mathrm{Q/F  \sim \theta_{4}}$                                                                            & 3.78 $ L/h $             & 13.5 & (3.03,4.77)    \\
   peripheral volume of distribution             & $\mathrm{V_{p}/F  \sim \theta_{5}}$                                                                        & 107 $ L $                & 15.7 & (84.8,164)     \\
   male effect on clearance                      & $\mathrm{MALE_{CL/F}\sim \theta_{6}}$                                                                      & 0.999 $  $               & 14.8 & (0.773,1.31)   \\
   weight effect on clearance                    & $\mathrm{WT_{CL/F}\sim \theta_{7}}$                                                                        & 1.67 $  $                & 21.7 & (1.02,2.3)     \\
   interindividual variability of clearance      & $\mathrm{IIV_{CL/F}\sim \Omega_{1.1}}$                                                                     & 0.196 $  $ (\%CV=46.5)  & 23   & (0.124,0.266)  \\
   interindividual variability of central volume & $\mathrm{IIV_{V_{c}/F}\sim \Omega_{2.2}}$                                                                  & 0.129 $  $ (\%CV=37.1)  & 30.4 & (0.064,0.187)  \\
   interindividual variability of Ka             & $\mathrm{IIV_{K_{a}}\sim \Omega_{3.3}}$                                                                    & 0.107 $  $ (\%CV=33.6)  & 25.3 & (0.064,0.152)  \\
   proportional error                            & $\mathrm{err_{prop}\sim \Sigma_{1.1}}$                                                                     & 0.0671 $  $ (\%CV=26.3) & 11.4 & (0.0551,0.08)  \\ \hline
  \end{tabular}
 \end{center}
\end{table}\end{document}
