Heller Phar7383 Final title: “Covariate modeling and Qualification” date: “2025-12-03” output: html_document — #libraries

rm(list=ls())
library(ggplot2)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(PKNCA)
## Warning: package 'PKNCA' was built under R version 4.4.2
## 
## Attaching package: 'PKNCA'
## The following object is masked from 'package:stats':
## 
##     filter
library(knitr)
library(xpose4)
## Warning: package 'xpose4' was built under R version 4.4.2
## Loading required package: lattice
library(tidyr)
## Warning: package 'tidyr' was built under R version 4.4.2
library(knitr)

#theme

my_theme<-function(x){theme_bw()+
    theme(text = element_text(size=20))+
    theme(axis.line.y = element_line(size = 2.0))+
    theme(axis.line.x = element_line(size = 2.0))+
    theme(axis.ticks = element_line(size = 1.5,colour="black"))+
    theme(axis.ticks.length=  unit(0.45, "cm"))+
    theme(axis.title.y =element_text(vjust=1.2))+
    theme(axis.title.x =element_text(vjust=-0.2))+
    theme(axis.text=element_text(colour="black"))+
    theme(panel.background = element_rect(fill ="white"))}

#data import and analysis

unt325<-read.csv("C:\\Heller\\PHAR7383\\Final\\unt325a.csv",stringsAsFactors = F)
unt325sum<-unt325%>%filter(EVID==0)%>%group_by(DOSE,TIME)%>%summarise(cmean=mean(DV),stdev=sd(DV))
## `summarise()` has grouped output by 'DOSE'. You can override using the
## `.groups` argument.

#Exploratory plots

#Population Plot
ggplot(data=unt325,aes(TIME,DV,group=ID))+
geom_line(size=0.5)+
geom_point(size=1)+
scale_x_continuous(limits = c(0,24),breaks = c(0,1,2,4,6,8,12,24))+
theme_bw()+
my_theme()+
labs(x="Time after dose (hour)",y="Plasma concentration (ng/ml)")+
facet_wrap(vars(DOSE))
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## i Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0.
## i Please use the `linewidth` argument instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

#average plot with standard deviation (+/-1SD)
ggplot(data=unt325sum,aes(TIME,cmean,group=DOSE))+
geom_line(size=0.5)+
geom_point(size=2)+
scale_x_continuous(limits = c(0,24),breaks = c(0,1,2,4,6,8,12,24))+
geom_errorbar(aes(ymin=cmean-stdev, ymax=cmean+stdev), width=.2)+
theme_bw()+
my_theme()+
labs(x="Time after dose (hour)",y="Plasma concentration (ng/ml)")

#model building` #Run1- Base model- two compartment model with first order absorption

library(xpose4)
run1<-xpose.data(1,dir="C:\\Heller\\PHAR7383\\Final") 
## 
## Looking for NONMEM table files.
##     Reading C:\Heller\PHAR7383\Final/sdtab1 
##     Reading C:\Heller\PHAR7383\Final/patab1 
##     Reading C:\Heller\PHAR7383\Final/catab1 
##     Reading C:\Heller\PHAR7383\Final/cotab1 
## Table files read.
##     Reading C:\Heller\PHAR7383\Final/run1.phi 
## 
## Looking for NONMEM simulation table files.
## No simulated table files read.
#check the distribution of covariates (is there enough range in the covariates?) You don't need to check this every run.  
#change.xvardef line keeps all covariates needed ready for xpose to plot.  You need to run this line for xpose to recognize all our covarites in the dataset.
change.xvardef(run1, "covariates") <- c("WT","SEX","CRCL")
cov.hist(run1)

#Diagnostic plots
dv.vs.ipred(run1,type="p")

dv.vs.pred(run1,type="p")

cwres.vs.idv(run1,type="p")

cwres.vs.pred(run1,type="p")

ind.plots(run1)

ranpar.hist(run1)

#this code below gives plots of EBEs versus covariates.  You need to specify covariates properly in the tables of model file for this code to work properly.  ETA2 versus CRCL means clearance relationship versus CRCL and so on.  You need to use sensibility of covariates and select few to conduct forward addition and backward elimination.
ranpar.vs.cov(run1)

#Another approach for EBEs?
#individual parameters
run1_ebe<-read.table("C:\\Heller\\PHAR7383\\Final/patab1",header=T,skip=1)%>%
  select(ID,KA,CL,V2,V3,Q)%>%
  filter(!duplicated(ID))
print (run1_ebe)
##      ID      KA      CL      V2      V3      Q
## 1     1 1.10960  41.787  625.73  280.50 179.69
## 2     2 1.49930  29.693  815.29  830.11 183.05
## 3     3 1.43760  25.991  562.00  654.75 171.27
## 4     4 1.42730  26.781  238.97  240.29 147.52
## 5     5 1.50050  28.681  628.59  461.91 181.31
## 6     6 1.47670  43.506  615.49  533.37 181.30
## 7     7 1.15840  23.692  638.01  535.85 157.43
## 8     8 1.55050  31.022  467.62  549.20 172.68
## 9     9 0.97272  35.822  505.96  224.25 178.06
## 10   10 1.30030  48.712  394.74  408.27 149.39
## 11   11 1.22680  26.931  734.46  386.50 175.39
## 12   12 1.63920  63.386  392.25  586.20 154.00
## 13   13 1.25930  26.113  468.60  287.16 174.31
## 14   14 1.54460  41.078  630.24  603.44 179.81
## 15   15 1.72680  34.534  370.90  762.49 178.27
## 16   16 1.79890  27.159  481.65  543.17 194.99
## 17   17 1.52670  17.618  660.56  584.60 179.71
## 18   18 1.57310  24.587  289.70  345.12 160.62
## 19   19 1.46260  19.587  375.00  388.08 165.33
## 20   20 1.16940  34.772 1108.80  544.88 173.38
## 21   21 1.68510  59.928  457.59  687.46 168.57
## 22   22 1.39100  30.502  512.49  512.28 163.11
## 23   23 1.57130  20.224  472.78  448.61 175.27
## 24   24 1.63920  45.796  673.67  783.40 193.61
## 25   25 1.40530  28.784  311.98  328.60 150.17
## 26   26 1.62550  58.506  381.08  378.97 175.65
## 27   27 1.41850  32.678  741.81  958.70 174.57
## 28   28 1.63240  36.898  372.00  515.44 166.57
## 29   29 1.46770  24.713  703.07  516.13 179.15
## 30   30 1.50590  34.864  344.45  261.53 176.96
## 31   31 1.31990  32.319  974.15  620.71 179.00
## 32   32 1.80760  21.555  496.88  561.47 192.61
## 33   33 1.51190  49.585  427.08  642.89 162.34
## 34   34 1.45780  31.743  280.34  399.96 143.94
## 35   35 1.59110  25.419  378.30  422.26 166.72
## 36   36 1.10680  52.618  357.88  181.69 178.92
## 37   37 1.63060  14.598  325.58  421.70 167.14
## 38   38 1.59490  20.367  352.07  492.09 162.57
## 39   39 1.49210  30.253  319.84  581.92 137.65
## 40   40 1.32150  27.764  742.13  513.41 173.21
## 41   41 1.45610  27.808  722.07  744.01 170.59
## 42   42 1.48570  30.815  478.10  440.25 172.03
## 43   43 1.45960  12.283  551.44  560.61 169.87
## 44   44 1.43590  49.018  523.80  805.52 178.95
## 45   45 1.32130  51.162  381.88  259.02 170.88
## 46   46 1.35070  32.901  400.66  386.52 161.67
## 47   47 0.96676  26.296  432.48  190.48 184.11
## 48   48 1.30090  26.006  392.61  278.62 168.68
## 49   49 1.55690  28.105  591.86  637.14 177.40
## 50   50 1.79930  29.200  483.09  533.75 189.59
## 51   51 1.52100  38.502  233.08  181.77 170.15
## 52   52 1.37730  18.637  585.04  687.56 163.05
## 53   53 1.43870  48.512  299.17  346.03 147.67
## 54   54 1.35270  32.007  405.18  317.53 167.45
## 55   55 1.50150  21.082  755.77  504.01 182.32
## 56   56 1.42100  40.657 1119.00  622.17 182.25
## 57   57 1.44410  24.880  757.92  643.24 179.68
## 58   58 1.27870  35.819  718.47  608.47 176.10
## 59   59 1.59610  25.409  597.95 1105.40 190.09
## 60   60 1.32300  22.405  548.30  343.80 175.97
## 61   61 1.83240  49.573  407.93  749.52 182.86
## 62   62 1.42370  41.518  509.29  861.57 167.65
## 63   63 1.33290  54.452  447.34  857.78 132.51
## 64   64 1.43560  26.159  446.11  540.00 156.85
## 65   65 1.31370  41.712  646.48  706.35 168.62
## 66   66 1.46940  46.304  742.11  879.61 176.97
## 67   67 1.60260  43.137  574.78  544.87 183.81
## 68   68 1.40880  32.646  561.71  494.53 171.02
## 69   69 1.57090  20.512  545.08 1010.80 184.39
## 70   70 1.52620  26.416  383.64 1112.90 162.56
## 71   71 1.68250  30.307  395.80  574.95 176.69
## 72   72 1.56970  17.383  361.69  521.02 163.66
## 73   73 1.53280  33.807  433.10  874.44 160.27
## 74   74 1.32500  41.668  800.28 1050.70 169.35
## 75   75 1.26110  33.226  632.32  719.42 164.94
## 76   76 1.60850  18.256  297.10  899.92 153.55
## 77   77 1.77390  21.945  230.06  645.53 149.52
## 78   78 1.47260  52.708  587.44  427.36 181.38
## 79   79 1.60540  35.341  449.22  782.45 177.60
## 80   80 1.58960  36.605  673.23  607.76 187.48
## 81   81 1.29600  33.461  749.28  468.45 172.26
## 82   82 1.45320  18.174  567.94  399.95 178.12
## 83   83 1.23590  42.405  643.09  264.56 188.51
## 84   84 1.46540  32.682  719.69  577.54 175.40
## 85   85 1.53650  19.781  682.54  814.44 179.84
## 86   86 1.59670  31.140  382.48  870.32 152.81
## 87   87 1.44330  25.473  772.20  903.42 183.21
## 88   88 1.72390  31.027  313.49  571.01 174.28
## 89   89 1.35450  19.793  340.75  921.08 131.69
## 90   90 1.65860  37.848  238.44  338.39 152.01
## 91   91 1.42230  25.295  668.51  473.46 175.85
## 92   92 1.43020  46.802  627.46  360.36 182.43
## 93   93 1.47900  25.554  620.63  424.26 182.04
## 94   94 1.57530  16.016  392.26  730.56 168.14
## 95   95 1.35230  34.770  452.99  686.69 146.97
## 96   96 1.43090  20.024  850.85  519.35 178.78
## 97   97 1.38100  18.566  478.73  477.85 161.32
## 98   98 1.53100  34.568  691.49  739.98 174.51
## 99   99 1.24200  21.462  820.67  601.97 166.25
## 100 100 1.46970  16.639  670.52  473.92 180.30
## 101 101 1.31320  40.240  823.59  665.67 174.70
## 102 102 1.39970  23.704  391.60  692.20 147.66
## 103 103 1.48640  29.506  784.78  433.45 184.76
## 104 104 1.40680  19.711  522.35  450.96 170.84
## 105 105 1.11950  33.989  483.64  242.22 178.13
## 106 106 1.32000  38.598  463.52  943.40 146.13
## 107 107 1.39750  25.810  696.44  474.17 176.71
## 108 108 1.51540  22.868  376.73  638.32 160.25
## 109 109 1.34190  26.069  867.33  457.84 179.42
## 110 110 1.22900  18.544  702.34  492.87 166.36
## 111 111 1.61140  22.687  608.03  990.64 192.80
## 112 112 1.57430  29.853  479.65  745.72 177.73
## 113 113 1.37770  31.095  329.64  412.30 150.83
## 114 114 1.29700  34.258  552.76  537.68 158.22
## 115 115 1.52350  11.977  499.83  558.50 170.45
## 116 116 1.37410  30.899  595.93  475.01 170.76
## 117 117 1.34310  41.799  472.60  382.70 166.81
## 118 118 1.30540  37.799  471.65  445.47 155.43
## 119 119 1.07110  42.316  687.78  368.48 169.33
## 120 120 1.29900  30.437  827.47  683.05 168.73
## 121 121 1.50490  48.577  551.28  771.00 177.40
## 122 122 1.32810  23.304  481.81  351.22 169.54
## 123 123 1.67740  28.491  569.10  527.47 190.93
## 124 124 1.53700  24.634  448.22  424.51 173.72
## 125 125 1.28430  33.124 1209.80  736.09 176.20
## 126 126 1.64400  37.938  563.63  708.18 179.68
## 127 127 1.52610  45.860  247.16  566.74 136.07
## 128 128 1.16120  29.345  772.69  428.52 170.97
## 129 129 1.74210  22.682  283.46  668.50 159.74
## 130 130 1.13160  33.871  751.73  344.00 177.04
## 131 131 1.29540  34.635  589.57  548.23 169.22
## 132 132 1.40820  52.258  686.17  870.27 179.09
## 133 133 1.57740  23.515  376.08  376.31 170.40
## 134 134 1.31330  31.331  476.55  648.48 150.91
## 135 135 1.46590  24.653  262.00  270.55 153.61
## 136 136 1.43550  37.738  338.01  343.55 158.37
## 137 137 1.00040  36.545 1036.60  368.20 176.97
## 138 138 1.47960  43.818  217.09  364.99 126.62
## 139 139 1.55650  30.337  804.65  829.77 187.23
## 140 140 1.39780  24.316  678.55  722.64 168.74
## 141 141 1.30550  43.006  854.65  414.20 178.02
## 142 142 1.60610  30.364  638.69  852.61 179.80
## 143 143 1.43520  47.373  662.00  649.83 172.67
## 144 144 1.55550  21.209  482.82  430.82 178.09
## 145 145 1.48920  39.364  500.07  845.87 156.07
## 146 146 1.43640  25.383  463.11  607.06 165.68
## 147 147 1.46000  20.299  891.07  546.06 180.96
## 148 148 1.61580  31.120  500.42  762.82 185.75
## 149 149 1.25880  23.729  533.90  454.36 160.88
## 150 150 1.38610  25.848  707.91  582.69 169.30
## 151 151 1.61530  27.243  645.61  749.17 186.74
## 152 152 1.46960  17.137  433.72  345.40 173.10
## 153 153 1.67040  27.472  534.81 1206.90 193.85
## 154 154 1.43010  30.687  512.73  795.16 164.98
## 155 155 1.41680  34.957  700.77  471.37 175.70
## 156 156 1.12180  48.874  793.05  345.44 177.96
## 157 157 1.47490  52.273  601.56  511.90 171.41
## 158 158 1.49350  45.435  300.15  509.23 142.87
## 159 159 1.48420  20.430  351.45  611.10 145.12
## 160 160 1.63560  34.412  372.80  391.52 174.70
## 161 161 1.22710  29.292  470.93  292.23 170.81
## 162 162 1.78640  31.699  289.58  636.61 173.73
## 163 163 1.51670  32.889  613.97  607.46 173.92
## 164 164 1.47980 139.550  499.86  685.67 176.46
## 165 165 1.31660  39.782  437.07  334.54 167.26
## 166 166 1.25660  24.691  600.83  308.55 179.59
## 167 167 1.36650  31.347  798.27  705.51 169.05
## 168 168 1.35270  31.105  667.11  413.87 175.65
## 169 169 1.48170  31.524  572.66  947.73 175.69
## 170 170 1.59670  35.866  572.52 1026.80 179.81

#Read this instructions carefully #The model files for runs 2-4 are provided. These will form the step 1 of forward addition. You want to make sure all the table files are properly numbered and create job files for each modelfile to run the models. # You need to create model files for step 2 onwards for adding more than one covarites into the models. #For backward elimination, take your full model and remove one covarite and see how much increase in OBJFUN occured and is that significant at alfa 0.01. #It is time for you to understand how the model files are being changed to fit different models of covariates. You will need to do this for the project! # Good luck! #you may see some errors and just continue with the process. Your covariate model may solve those problems. But, always mention what errors occured in your presentation. Run2- Base model+WTonV2

#Diagnostic plots
run2<-xpose.data(2,dir="C:\\Heller\\PHAR7383\\Final") 
## 
## Looking for NONMEM table files.
##     Reading C:\Heller\PHAR7383\Final/sdtab2 
##     Reading C:\Heller\PHAR7383\Final/patab2 
##     Reading C:\Heller\PHAR7383\Final/catab2 
##     Reading C:\Heller\PHAR7383\Final/cotab2 
## Table files read.
##     Reading C:\Heller\PHAR7383\Final/run2.phi 
## 
## Looking for NONMEM simulation table files.
## No simulated table files read.
dv.vs.ipred(run2,type="p")

dv.vs.pred(run2,type="p")

cwres.vs.idv(run2,type="p")

cwres.vs.pred(run2,type="p")

ind.plots(run2)

ranpar.hist(run2)

ranpar.vs.cov(run2)

Run3- Base model+WTonV3

run3<-xpose.data(3,dir="C:\\Heller\\PHAR7383\\Final") 
## 
## Looking for NONMEM table files.
##     Reading C:\Heller\PHAR7383\Final/sdtab3 
##     Reading C:\Heller\PHAR7383\Final/patab3 
##     Reading C:\Heller\PHAR7383\Final/catab3 
##     Reading C:\Heller\PHAR7383\Final/cotab3 
## Table files read.
##     Reading C:\Heller\PHAR7383\Final/run3.phi 
## 
## Looking for NONMEM simulation table files.
## No simulated table files read.
dv.vs.ipred(run3,type="p")

dv.vs.pred(run3,type="p")

cwres.vs.idv(run3,type="p")

cwres.vs.pred(run3,type="p")

ind.plots(run3)

ranpar.hist(run3)

ranpar.vs.cov(run3)

Run4- Base model+CRCL on CL (is it justified to test this relationship either by plots or biological rationale? Comment on this in your presentation of results)

run4corr<-xpose.data(4,dir="C:\\Heller\\PHAR7383\\Final") 
## 
## Looking for NONMEM table files.
##     Reading C:\Heller\PHAR7383\Final/sdtab4 
##     Reading C:\Heller\PHAR7383\Final/patab4 
##     Reading C:\Heller\PHAR7383\Final/catab4 
##     Reading C:\Heller\PHAR7383\Final/cotab4 
## Table files read.
##     Reading C:\Heller\PHAR7383\Final/run4.phi 
## 
## Looking for NONMEM simulation table files.
## No simulated table files read.
dv.vs.ipred(run4corr,type="p")

dv.vs.pred(run4corr,type="p")

cwres.vs.idv(run4corr,type="p")

cwres.vs.pred(run4corr,type="p")

ind.plots(run4corr)

ranpar.hist(run4corr)

ranpar.vs.cov(run4corr)

#Base model+WTonV2 and WTonV3

run5<-xpose.data(5,dir="C:\\Heller\\PHAR7383\\Final") 
## 
## Looking for NONMEM table files.
##     Reading C:\Heller\PHAR7383\Final/sdtab5 
##     Reading C:\Heller\PHAR7383\Final/patab5 
##     Reading C:\Heller\PHAR7383\Final/catab5 
##     Reading C:\Heller\PHAR7383\Final/cotab5 
## Table files read.
##     Reading C:\Heller\PHAR7383\Final/run5.phi 
## 
## Looking for NONMEM simulation table files.
## No simulated table files read.
dv.vs.ipred(run5,type="p")

dv.vs.pred(run5,type="p")

cwres.vs.idv(run5,type="p")

cwres.vs.pred(run5,type="p")

ind.plots(run5)

ranpar.hist(run5)

ranpar.vs.cov(run5)

#Another approach for EBEs?
#individual parameters
run5_ebe<-read.table("C:\\Heller\\PHAR7383\\Final/patab5",header=T,skip=1)%>%
  select(ID,KA,CL,V2,V3,Q)%>%
  filter(!duplicated(ID))
print (run5_ebe)
##      ID      KA      CL      V2      V3      Q
## 1     1 0.75095  41.550  448.53  389.37 233.19
## 2     2 1.23510  29.658  684.51  882.48 228.33
## 3     3 1.25490  26.060  556.67  878.93 194.52
## 4     4 1.19170  26.376  187.82  247.01 170.35
## 5     5 1.25220  28.738  549.83  656.06 232.26
## 6     6 1.23810  43.678  537.33  684.64 225.24
## 7     7 0.85564  23.677  507.50  574.71 180.76
## 8     8 1.33510  30.992  403.35  581.51 206.53
## 9     9 0.70628  35.926  387.98  350.95 217.15
## 10   10 1.06350  48.681  339.30  452.24 164.46
## 11   11 0.85387  26.907  548.31  512.54 224.16
## 12   12 1.43840  62.943  342.73  588.52 176.44
## 13   13 0.95295  26.123  370.80  388.36 215.09
## 14   14 1.28670  41.096  539.02  696.14 223.76
## 15   15 1.70210  34.703  392.81  853.33 190.71
## 16   16 1.66380  27.225  421.05  642.20 249.67
## 17   17 1.24870  17.607  507.88  616.43 228.08
## 18   18 1.39990  24.625  261.54  391.00 178.90
## 19   19 1.24000  19.591  323.67  442.34 190.52
## 20   20 0.87528  34.961 1024.70 1089.90 205.33
## 21   21 1.54490  60.059  428.53  717.99 191.19
## 22   22 1.13250  30.472  434.54  562.64 193.31
## 23   23 1.34480  20.230  402.89  530.73 217.94
## 24   24 1.43330  45.863  590.94  868.93 242.71
## 25   25 1.16560  28.906  280.85  391.14 156.34
## 26   26 1.36090  58.058  307.69  421.49 215.08
## 27   27 1.18800  32.624  663.20  963.12 206.56
## 28   28 1.44460  36.772  323.86  519.07 193.70
## 29   29 1.17530  24.720  575.12  654.47 229.77
## 30   30 1.24930  34.944  280.79  332.90 219.79
## 31   31 1.04250  32.399  827.47  905.24 230.04
## 32   32 1.66690  21.578  407.45  614.13 252.97
## 33   33 1.31830  49.404  379.71  637.31 182.37
## 34   34 1.31120  31.882  269.33  449.28 148.08
## 35   35 1.34390  25.227  293.52  402.45 209.54
## 36   36 0.86235  52.743  270.96  258.63 224.83
## 37   37 1.37420  14.495  222.00  310.38 201.12
## 38   38 1.39670  20.292  289.87  447.03 191.45
## 39   39 1.36020  30.305  313.70  610.52 139.23
## 40   40 0.98482  27.716  572.25  594.10 218.70
## 41   41 1.23450  27.889  702.15 1008.50 194.51
## 42   42 1.20790  30.714  383.35  475.17 213.80
## 43   43 1.18720  12.277  415.69  523.57 207.99
## 44   44 1.24840  48.893  465.55  786.95 204.49
## 45   45 1.03590  51.252  302.38  332.58 207.38
## 46   46 1.11640  32.879  339.01  435.43 185.64
## 47   47 0.67699  26.305  315.20  285.46 240.61
## 48   48 1.01180  25.975  309.47  341.98 203.18
## 49   49 1.30670  28.039  486.35  644.62 222.40
## 50   50 1.63890  29.208  404.84  589.84 247.70
## 51   51 1.28690  38.388  185.84  221.22 203.38
## 52   52 1.09910  18.587  473.98  622.92 192.00
## 53   53 1.23650  48.537  264.10  377.31 160.01
## 54   54 1.07850  32.001  330.31  385.69 199.62
## 55   55 1.20720  21.081  586.02  635.96 242.69
## 56   56 1.07910  40.634  879.81  841.46 245.94
## 57   57 1.23800  24.955  732.87  991.93 220.67
## 58   58 0.98777  35.643  561.47  623.01 215.75
## 59   59 1.49220  25.447  622.85 1213.00 220.37
## 60   60 0.97040  22.362  400.77  404.44 225.80
## 61   61 1.79910  49.849  406.94  794.61 203.60
## 62   62 1.34420  41.875  551.43 1160.50 175.67
## 63   63 1.17710  54.331  421.28  826.40 137.35
## 64   64 1.19820  26.119  386.23  552.69 179.61
## 65   65 1.07030  41.671  558.41  753.40 197.71
## 66   66 1.27640  46.549  714.91 1099.80 201.80
## 67   67 1.30510  42.802  450.30  562.98 237.66
## 68   68 1.19180  32.792  552.06  763.88 190.40
## 69   69 1.46070  20.522  575.18 1119.00 213.04
## 70   70 1.45520  26.358  393.77  987.57 171.94
## 71   71 1.55880  30.377  374.70  638.08 202.77
## 72   72 1.41120  17.381  339.16  564.37 183.47
## 73   73 1.38300  33.674  401.57  777.65 176.42
## 74   74 1.07810  41.566  713.10 1032.10 195.51
## 75   75 1.08920  33.427  648.84 1067.00 178.25
## 76   76 1.55340  18.215  307.94  793.95 160.09
## 77   77 1.70510  21.822  212.88  526.45 157.45
## 78   78 1.16190  52.575  466.88  520.66 235.71
## 79   79 1.48330  35.387  430.87  806.72 199.54
## 80   80 1.31990  36.560  546.77  682.22 243.11
## 81   81 0.94349  33.438  590.88  600.99 215.79
## 82   82 1.17450  18.174  480.16  552.15 225.78
## 83   83 0.78612  42.045  435.95  379.23 261.63
## 84   84 1.16080  32.636  585.26  665.09 224.51
## 85   85 1.33860  19.797  637.98  949.41 217.56
## 86   86 1.54150  31.210  399.71  913.91 157.25
## 87   87 1.21150  25.467  674.55  955.94 223.19
## 88   88 1.63770  31.080  302.89  592.00 190.87
## 89   89 1.23630  19.742  335.62  789.68 133.91
## 90   90 1.51880  37.878  218.67  358.34 163.29
## 91   91 1.11400  25.301  550.12  613.23 222.38
## 92   92 1.09140  46.975  505.05  525.02 243.31
## 93   93 1.28510  25.550  635.36  801.30 225.80
## 94   94 1.48840  16.002  440.70  914.49 185.76
## 95   95 1.14940  34.667  405.18  658.20 161.16
## 96   96 1.11630  20.027  689.09  719.87 232.16
## 97   97 1.09600  18.523  368.83  451.65 196.13
## 98   98 1.30750  34.633  638.13  890.52 206.63
## 99   99 0.92921  21.522  731.22  880.10 189.27
## 100 100 1.27870  16.611  758.94  986.28 219.66
## 101 101 1.02220  40.266  689.77  806.98 214.28
## 102 102 1.23210  23.667  363.04  653.04 158.58
## 103 103 1.15770  29.505  618.25  616.20 253.75
## 104 104 1.13180  19.714  433.78  532.93 205.72
## 105 105 0.81529  34.009  367.52  351.20 224.01
## 106 106 1.16930  38.533  441.65  885.12 153.76
## 107 107 1.04310  25.722  509.93  516.86 230.70
## 108 108 1.39030  22.891  376.11  707.40 172.66
## 109 109 1.00290  26.075  696.95  677.55 235.26
## 110 110 0.89907  18.563  574.88  634.07 193.82
## 111 111 1.42070  22.606  526.58  857.91 231.37
## 112 112 1.37850  29.742  415.81  681.81 207.52
## 113 113 1.18700  31.056  290.79  432.81 163.99
## 114 114 1.05320  34.455  527.16  751.01 163.69
## 115 115 1.31450  11.972  462.01  666.25 201.93
## 116 116 1.11580  31.003  555.81  706.39 194.43
## 117 117 1.05070  41.571  375.31  432.62 203.16
## 118 118 1.04200  38.009  426.03  573.34 163.09
## 119 119 0.78259  42.567  578.48  592.67 193.33
## 120 120 0.97608  30.375  665.12  740.83 205.65
## 121 121 1.29590  48.472  487.18  772.03 206.52
## 122 122 1.02340  23.301  386.50  434.26 205.84
## 123 123 1.57370  28.587  589.15  889.49 240.45
## 124 124 1.34830  24.669  447.70  641.79 197.69
## 125 125 0.98036  33.254 1034.90 1132.40 221.40
## 126 126 1.45130  37.937  502.99  752.86 218.12
## 127 127 1.45600  45.909  246.38  565.14 137.02
## 128 128 0.76922  29.064  520.68  424.24 220.88
## 129 129 1.67960  22.650  275.83  621.05 171.57
## 130 130 0.79098  33.923  600.85  557.06 222.09
## 131 131 1.08660  34.795  554.17  766.35 193.43
## 132 132 1.18460  52.176  602.34  890.99 212.87
## 133 133 1.34190  23.477  308.17  410.29 209.34
## 134 134 1.13400  31.456  468.86  788.12 155.61
## 135 135 1.24840  24.582  219.64  294.38 172.28
## 136 136 1.22360  37.972  304.16  412.02 173.92
## 137 137 0.60488  36.478  725.49  542.31 229.90
## 138 138 1.31970  43.319  191.69  359.24 129.36
## 139 139 1.34000  30.386  709.91  979.53 237.09
## 140 140 1.09890  24.204  535.93  657.27 206.18
## 141 141 0.89412  42.872  638.68  568.32 237.04
## 142 142 1.46040  30.446  632.36 1034.00 209.38
## 143 143 1.18220  47.515  589.51  783.93 203.72
## 144 144 1.33730  21.226  428.59  564.01 219.72
## 145 145 1.33460  39.401  483.02  873.48 167.61
## 146 146 1.26500  25.427  448.45  730.96 184.17
## 147 147 1.21460  20.331  840.09  957.85 231.59
## 148 148 1.47160  31.165  468.85  813.90 216.97
## 149 149 0.99889  23.799  505.85  682.56 170.12
## 150 150 1.07720  25.871  611.36  742.02 200.10
## 151 151 1.38270  27.173  525.58  729.95 236.83
## 152 152 1.21740  17.107  420.39  541.14 198.90
## 153 153 1.62170  27.511  573.53 1262.60 220.55
## 154 154 1.20220  30.455  429.14  664.84 192.35
## 155 155 1.08140  34.982  577.16  628.30 220.94
## 156 156 0.80011  49.161  659.39  627.38 220.32
## 157 157 1.16850  52.237  500.45  599.21 212.27
## 158 158 1.34100  45.306  276.22  508.26 150.28
## 159 159 1.31260  20.377  315.39  551.22 159.13
## 160 160 1.44560  34.529  329.85  462.29 208.42
## 161 161 0.91052  29.307  370.40  390.74 204.34
## 162 162 1.74910  31.761  291.68  645.99 185.70
## 163 163 1.24480  32.810  508.15  641.99 217.75
## 164 164 1.28180 139.790  446.98  724.63 195.68
## 165 165 1.06810  40.112  385.42  462.56 190.16
## 166 166 0.92755  24.686  539.37  558.24 216.59
## 167 167 1.10450  31.486  761.30 1043.90 191.50
## 168 168 1.01760  31.126  541.72  568.62 222.43
## 169 169 1.28030  31.362  501.47  822.59 205.63
## 170 170 1.49810  35.961  580.38 1121.40 202.02

#Base model+WTonV2 and WTonV3 and CRCL on CL

run6<-xpose.data(6,dir="C:\\Heller\\PHAR7383\\Final") 
## 
## Looking for NONMEM table files.
##     Reading C:\Heller\PHAR7383\Final/sdtab6 
##     Reading C:\Heller\PHAR7383\Final/patab6 
##     Reading C:\Heller\PHAR7383\Final/catab6 
##     Reading C:\Heller\PHAR7383\Final/cotab6 
## Table files read.
##     Reading C:\Heller\PHAR7383\Final/run6.phi 
## 
## Looking for NONMEM simulation table files.
## No simulated table files read.
dv.vs.ipred(run6,type="p")

dv.vs.pred(run6,type="p")

cwres.vs.idv(run6,type="p")

cwres.vs.pred(run6,type="p")

ind.plots(run6)

ranpar.hist(run6)

ranpar.vs.cov(run6)

#Model qualification #VPC plot

#VPC
vpc.file <- "C:/Heller/PHAR7383/Final/vpc/vpc_results.csv"
vpctab <- "C:/Heller/PHAR7383/Final/vpc/vpctab5"
xpose.VPC(vpc.info=vpc.file,vpctab=vpctab,PI.ci.area.smooth="TRUE",logy="TRUE")

#pcVPC
vpc.file <- "C:/Heller/PHAR7383/Final/pcvpc/vpc_results.csv"
vpctab <- "C:/Heller/PHAR7383/FInal/pcvpc/vpctab5"
xpose.VPC(vpc.info=vpc.file,vpctab=vpctab,PI.ci="area",PI.ci.area.smooth="FALSE",logy="TRUE")

#Bootstrap #run in terminal: bootstrap run5.mod -samples=200 -seed=12345

bsres<-read.csv("C:/Heller/PHAR7383/Final/bootstrap_dir1/raw_results_run5.csv",stringsAsFactors = F)

options(digits=2)
bsres%>%gather(parameter,value,21:31)%>%
select(parameter, value)%>%
group_by(parameter)%>%
summarise(MEDIAN=median(value),LL=quantile(value,prob=0.025),UL=quantile(value,prob=0.975))%>%slice(7,6,10,11,8,2,1,4,5,3,9)%>%kable()
parameter MEDIAN LL UL
Q 209.12 134.86 283.79
KA 1.20 0.84 1.67
WTonV2 0.92 0.70 1.23
WTonV3 1.04 0.81 1.37
V2 483.03 322.74 619.81
BSVKA 0.11 0.03 0.25
BSVCL 0.11 0.09 0.16
BSVV3 0.08 0.04 0.15
CL 30.56 29.05 32.30
BSVV2 0.09 0.05 0.14
V3 672.76 571.24 830.52