/
xpose.VPC.both.R
257 lines (232 loc) · 8.74 KB
/
xpose.VPC.both.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# Xpose 4
# An R-based population pharmacokinetic/
# pharmacodynamic model building aid for NONMEM.
# Copyright (C) 1998-2004 E. Niclas Jonsson and Mats Karlsson.
# Copyright (C) 2005-2008 Andrew C. Hooker, Justin J. Wilkins,
# Mats O. Karlsson and E. Niclas Jonsson.
# Copyright (C) 2009-2010 Andrew C. Hooker, Mats O. Karlsson and
# E. Niclas Jonsson.
# This file is a part of Xpose 4.
# Xpose 4 is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation, either version 3
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public License
# along with this program. A copy can be cound in the R installation
# directory under \share\licenses. If not, see http://www.gnu.org/licenses/.
#' Xpose Visual Predictive Check (VPC) for both continuous and Limit of
#' Quantification data.
#'
#' Xpose Visual Predictive Check (VPC) for both continuous and Below or Above
#' Limit of Quantification (BLQ or ALQ) data.
#'
#'
#' @param vpc.info Name of PSN file to use. File will come from \code{VPC}
#' command in PsN.
#' @param vpctab Name of vpctab file produced from PsN.
#' @param object Xpose data object.
#' @param subset Subset of data to look at.
#' @param main Title for plot.
#' @param main.sub Used for names above each plot when using multiple plots.
#' Should be a vector, e.g. \code{c("title 1","title 2")}.
#' @param inclZeroWRES Include WRES=0 rows in the computations for these plots?
#' @param cont.logy Should the continuous plot y-axis be on the log scale?
#' @param hline Horizontal line marking the limits of quantification. If they
#' are defined, they must be a vector of values.
#' @param add.args.cont Additional arguments to the continuous plot.
#' \code{\link{xpose.VPC}}.
#' @param add.args.cat Additional arguments to the categorical plot.
#' \code{\link{xpose.VPC.categorical}}.
#' @param \dots Additional arguments to both plots.
#' @author Andrew C. Hooker
#' @seealso \code{\link{xpose.VPC}}, \code{\link{xpose.VPC.categorical}}.
#' @keywords methods
#' @examples
#'
#' \dontrun{
#' library(xpose4)
#'
#' ## move to the directory where results from PsN
#' ## are found
#' cur.dir <- getwd()
#' setwd(paste(cur.dir,"/vpc_cont_LLOQ/",sep=""))
#'
#' xpose.VPC()
#' xpose.VPC.categorical(censored=T)
#'
#' xpose.VPC.both()
#'
#' xpose.VPC.both(subset="DV>1.75")
#'
#' xpose.VPC.both(add.args.cont=list(ylim=c(0,80)))
#'
#' xpose.VPC.both(add.args.cont = list(ylim = c(0.01, 80)), xlim = c(0,
#' 40), add.args.cat = list(ylim = c(0, 0.4)), cont.logy = T)
#'
#' xpose.VPC.both(cont.logy=T)
#' }
#'
#' @export xpose.VPC.both
#' @family PsN functions
#' @family specific functions
"xpose.VPC.both" <-
function(vpc.info="vpc_results.csv", #name of PSN file to use
vpctab = dir(pattern="^vpctab")[1],
object = NULL,
#ids=NULL,
#type="p",
#by=NULL,
#PI="area",
subset=NULL,
main="Default",
main.sub=NULL, #used for names above each plot
#when using multiple plots
#Should be a vector c("","")
##main.sub.cex=0.85, # size of main.sub
inclZeroWRES=FALSE,
##plot.cont.table=TRUE,
#plot.cat.table=TRUE,
#force.x.continuous=FALSE,
#real.col=4,
#median.line=FALSE,
#median.col="darkgrey",
#ci.lines=FALSE,
#ci.col="blue",
#ci.lines.col="darkblue",
#xlb="Default",
#ylb="Proportion of Total",
#force.x.continuous=FALSE,
#level.to.plot=NULL,
#max.plots.per.page=1,
#strip="Default",
#rug=TRUE,
#rug.col="orange",
cont.logy=F,
hline="default",
add.args.cont=list(),
add.args.cat=list(),
...) {
## Make sure we have the necessary variables defined
if(is.null(object) & is.null(vpctab)){
cat(paste("Both the arguments object and vpctab are NULL\n"))
cat(paste("At least one of these must be defined\n"))
return(NULL)
}
if(!is.null(vpctab)){
tmp <- FALSE
if(is.null(object)) tmp <- TRUE
object.2 <- read.vpctab(vpctab=vpctab,
object=object,
inclZeroWRES=inclZeroWRES,
...)
if(tmp==TRUE) inclZeroWRES=TRUE
}
file.info <- read.npc.vpc.results(vpc.results=vpc.info,...)
num.tables <- file.info$num.tables
dv.var <- file.info$dv.var
idv.var <- file.info$idv.var
arg.list.1 <- list(vpc.info=vpc.info,
vpctab = vpctab,
object = object,
subset=subset,
main=NULL,
main.sub=main.sub,
#aspect="fill",
#xlb=NULL,
censored=T,
...)
arg.list <- c(arg.list.1,add.args.cat)
cat.plots.tmp <- do.call(xpose.VPC.categorical,arg.list,quote=F)
## cat.plots.tmp <-
## xpose.VPC.categorical(vpc.info=vpc.info,
## vpctab = vpctab,
## object = object,
## subset=subset,
## main=NULL,
## main.sub=NULL,
## #xlb=NULL,
## censored=T,
## ...)
cat.plots <- cat.plots.tmp@plotList
if(!is.na(match(hline,"default"))) {
hline=c(file.info$lloq,file.info$uloq)
if(cont.logy) hline=log10(hline)
}
if(num.tables==1) {
cont.plots <- vector("list",1)
arg.list.1 <- list(vpc.info=vpc.info,
vpctab = vpctab,
object = object,
subset=subset,
main=NULL,
aspect="fill",
xlb=NULL,
hline=hline,
logy=cont.logy,
...)
arg.list <- c(arg.list.1,add.args.cont)
cont.plots[[1]] <- do.call(xpose.VPC,arg.list,quote=F)
## cont.plots[[1]] <-
## xpose.VPC(vpc.info=vpc.info,
## vpctab = vpctab,
## object = object,
## subset=subset,
## main=NULL,
## aspect="fill",
## xlb=NULL,
## hline=c(file.info$lloq,file.info$uloq),
## add.args.cont,
## ...)
} else {
arg.list.1 <- list(vpc.info=vpc.info,
vpctab = vpctab,
object = object,
subset=subset,
##main=NULL,
aspect="fill",
xlb=NULL,
hline=hline,
logy=cont.logy,
...)
arg.list <- c(arg.list.1,add.args.cont)
cont.plots.tmp <- do.call(xpose.VPC,arg.list,quote=F)
## cont.plots.tmp <-
## xpose.VPC(vpc.info=vpc.info,
## vpctab = vpctab,
## object = object,
## subset=subset,
## aspect="fill",
## xlb=NULL,
## hline=c(file.info$lloq,file.info$uloq),
## ...)
cont.plots <- cont.plots.tmp@plotList
}
plotList <- vector("list",num.tables*2)
j=0
for(i in 1:num.tables){
plotList[[i+j]] <- cont.plots[[i]]
plotList[[i+j+1]] <- cat.plots[[i]]
j=j+1
}
if(main=="Default"){
no.runno <- FALSE
text2 <- NULL
if(object.2@Runno=="0"){
no.runno <- TRUE
text2 <- paste("\n(",file.info$model.file,")",sep="")
}
main <- xpose.create.title.text(NULL,dv.var,
"VPC for",
text2=text2,
no.runno=no.runno,
object.2,subset=subset,...)
}
#print(cont.plots[[i]],position=c(0,0.2,1,1),more=TRUE)
# print(cat.plots[[i]],position=c(0,0,1,0.33),more=TRUE)
obj <- xpose.multiple.plot(plotList,plotTitle=main,bql.layout=T,...)
return(obj)
}