├── NAMESPACE ├── .Rbuildignore ├── .gitignore ├── rspeaksnonmem.pptx ├── man └── hello.Rd ├── tests ├── originals │ ├── control3.con │ ├── Test.ctl │ ├── 1105.ctl │ ├── phenobarb.con │ ├── TestData1notab.ctl │ ├── 1001.ctl │ ├── simexampl.ctl │ ├── 1.ctl │ ├── 2.ctl │ ├── 4.ctl │ ├── 3.ctl │ ├── 5.ctl │ ├── 6.ctl │ ├── 7.ctl │ ├── 8.ctl │ ├── 9.ctl │ ├── 10.ctl │ ├── TestData1SIM_missingtab.con │ ├── Theophylline.mod │ ├── 1002.ctl │ ├── control4.con │ ├── 1003.ctl │ ├── 1004.ctl │ ├── TestData1.ctl │ ├── TestData1_missingtab.ctl │ ├── multiprob1.mod │ ├── sde6.ctl │ ├── TestData1SIM.con │ ├── subprob1.mod │ ├── sde7.ctl │ ├── sde8.ctl │ ├── warfarin.ctl │ ├── warfarin_boot.ctl │ ├── sde10.ctl │ ├── sde9b.ctl │ ├── sde9.ctl │ ├── moxonidine.mod │ ├── 1006.ctl │ └── 1005.ctl ├── written │ ├── control3.con │ ├── Test.ctl │ ├── 1105.ctl │ ├── TestData1notab.ctl │ ├── phenobarb.con │ ├── 1001.ctl │ ├── TestData1SIM_missingtab.con │ ├── 1.ctl │ ├── 4.ctl │ ├── 2.ctl │ ├── 3.ctl │ ├── 5.ctl │ ├── 6.ctl │ ├── 7.ctl │ ├── 8.ctl │ ├── 9.ctl │ ├── 10.ctl │ ├── simexampl.ctl │ ├── Theophylline.mod │ ├── 1002.ctl │ ├── sde6.ctl │ ├── TestData1.ctl │ ├── TestData1_missingtab.ctl │ ├── 1003.ctl │ ├── control4.con │ ├── 1004.ctl │ ├── TestData1SIM.con │ ├── warfarin.ctl │ ├── warfarin_boot.ctl │ ├── sde7.ctl │ ├── sde8.ctl │ ├── subprob1.mod │ ├── sde10.ctl │ ├── moxonidine.mod │ ├── sde9b.ctl │ └── sde9.ctl ├── compare_importNmMod.R └── Read_and_write_from_NM_examples.R ├── R ├── getNMObjects.R ├── PsNHeader.R ├── basicGOF_Xpose.R ├── sumo_PsN.R ├── bootstrap_PsN.R ├── updateModel.R ├── execute_PsN.R ├── SSE_PsN.R ├── estimate_NM.R ├── VPC_PsN.R ├── callPsN.R ├── bs_summary.R ├── runRecord_PsN.R ├── validate_PsN_options.R ├── runModel.R ├── utils.R ├── extractNMObjects.R └── defineExecutable.R ├── inst └── exdata │ ├── Theophylline.mod │ ├── warfarin.ctl │ ├── moxonidine.mod │ ├── THEO.DAT │ └── warfarin_conc_pca.csv ├── DESCRIPTION ├── vignettes ├── using_pharmpy.Rmd ├── rspeaksnonmem_with_PsN_rplots.Rmd ├── Introduction_to_rspeaksnonmem.Rmd ├── using_rspeaksnonmem_to_run_NONMEM_and_PsN.Rmd ├── using_rspeaksnonmem_to_modify_NONMEM_control_streams.Rmd └── Setting up workflow using rspeaksnonmem.Rmd └── README.md /NAMESPACE: -------------------------------------------------------------------------------- 1 | exportPattern("^[[:alpha:]]+") 2 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | rspeaksnonmem.Rproj 5 | inst/doc 6 | -------------------------------------------------------------------------------- /rspeaksnonmem.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MikeKSmith/-no_entry-DEPRECATED-rspeaksnonmem/HEAD/rspeaksnonmem.pptx -------------------------------------------------------------------------------- /man/hello.Rd: -------------------------------------------------------------------------------- 1 | \name{hello} 2 | \alias{hello} 3 | \title{Hello, World!} 4 | \usage{ 5 | hello() 6 | } 7 | \description{ 8 | Prints 'Hello, world!'. 9 | } 10 | \examples{ 11 | hello() 12 | } 13 | -------------------------------------------------------------------------------- /tests/originals/control3.con: -------------------------------------------------------------------------------- 1 | ; control3 example from NONMEM guide part VIII 2 | $PROBLEM THEOPHYLLINE SINGLE SUBJECT DATA 3 | $INPUT DOSE=AMT TIME CP=DV 4 | $DATA DATA3 5 | $SUBROUTINES ADVAN2 6 | $PK 7 | CALLFL=1 8 | KA=THETA(1) 9 | K=THETA(2) 10 | SC=THETA(3) 11 | $ERROR 12 | Y=F+ERR(1) 13 | $THETA (0,1.7) (0,.102) (0,29) 14 | $ESTIMATION MAXEVAL=240 PRINT=2 15 | $COVR 16 | $TABLE TIME FILE=table3 17 | -------------------------------------------------------------------------------- /tests/written/control3.con: -------------------------------------------------------------------------------- 1 | $PROBLEM THEOPHYLLINE SINGLE SUBJECT DATA 2 | $INPUT DOSE=AMT TIME CP=DV 3 | $DATA 'DATA3' 4 | $SUBROUTINES ADVAN2 5 | $PK 6 | CALLFL=1 7 | KA=THETA(1) 8 | K=THETA(2) 9 | SC=THETA(3) 10 | $ERROR 11 | Y=F+ERR(1) 12 | $THETA (0, 1.7, ) 13 | (0, 0.102, ) 14 | (0, 29, ) 15 | $ESTIMATION MAXEVAL=240 PRINT=2 16 | $COV 17 | 18 | $TABLE TIME APPEND ONEHEADER NOPRINT FILE=table3 19 | -------------------------------------------------------------------------------- /tests/written/Test.ctl: -------------------------------------------------------------------------------- 1 | $PROB System Test 1 2 | $INPUT SID SEX AGE RACE HT SMOK HCTZ PROP CON DOSE=AMT WT TIME SECR DV DROP=RATE EVID SS II ID OCC 3 | $DATA input.tab IGNORE=@ 4 | $PRED 5 | KA = THETA(1) 6 | KE = THETA(2) 7 | CL = THETA(3) 8 | F = (DOSE*KE*KA) /(CL * (KE-KA)) * (EXP(-KE*TIME) - EXP(-KA*TIME)) 9 | Y = F + ERR(1) 10 | IPRED = F 11 | IWRES = F - DV 12 | $THETA 18.7 FIX 13 | 87.3 FIX 14 | 2.13 FIX 15 | $OMEGA 0.0231 FIX 16 | $EST METHOD=0 MAXEVAL=0 17 | -------------------------------------------------------------------------------- /tests/originals/Test.ctl: -------------------------------------------------------------------------------- 1 | $PROB System Test 1 2 | $INPUT SID SEX AGE RACE HT SMOK HCTZ PROP CON DOSE=AMT WT TIME SECR 3 | DV DROP=RATE EVID SS II ID OCC 4 | $DATA input.tab IGNORE=@ 5 | $PRED 6 | KA = THETA(1) 7 | KE = THETA(2) 8 | CL = THETA(3) 9 | F = (DOSE*KE*KA) /(CL * (KE-KA)) * (EXP(-KE*TIME) - EXP(-KA*TIME)) 10 | Y = F + ERR(1) 11 | IPRED = F 12 | IWRES = F - DV 13 | 14 | $THETA 18.7 FIX 15 | 87.3 FIX 16 | 2.13 FIX 17 | $OMEGA 0.0231 FIX 18 | $EST METHOD=0 MAXEVAL=0 19 | -------------------------------------------------------------------------------- /R/getNMObjects.R: -------------------------------------------------------------------------------- 1 | #' Retrieves Data, Parameters, Task Properties from a NONMEM control file. 2 | #' 3 | #' @param RNMImportObject RNMImport object. 4 | #' @param what 'Data', 'Parameters', 'Model', 'TaskProperties', 'All'. 5 | #' @return Object from the NONMEM control stream corresponding to . 6 | #' @examples 7 | #' 8 | #' getNMObjects(foo, what='Data') 9 | #' getNMObjects(foo, what='All') 10 | getNMObjects <- function(RNMImportObject, 11 | what = c("Data", "Parameters", "TaskProperties", "All")) { 12 | ## TO BE WRITTEN 13 | } 14 | -------------------------------------------------------------------------------- /tests/written/1105.ctl: -------------------------------------------------------------------------------- 1 | $PROB 1105 phase1 2 CMT like 1004 but diff. initial on V3 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV SUBJ HOUR HEIGHT WT SEX AGE DOSE FED 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) * THETA(6)**SEX * (WT/70)**THETA(7) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4) 10 | V3=THETA(5) 11 | S2=V2 12 | $ERROR 13 | Y=F*(1+ERR(1)) + ERR(2) 14 | IPRE=F 15 | 16 | $SIMULATION (1968) SUBPROBLEMS= 500 ONLYSIMULATION 17 | $TABLE DV NOAPPEND NOHEADER NOPRINT FILE=./1105.tab 18 | -------------------------------------------------------------------------------- /tests/originals/1105.ctl: -------------------------------------------------------------------------------- 1 | $PROB 1105 phase1 2 CMT like 1004 but diff. initial on V3 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV SUBJ HOUR HEIGHT WT SEX AGE DOSE FED 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) * THETA(6)**SEX * (WT/70)**THETA(7) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4) 10 | V3=THETA(5) 11 | S2=V2 12 | 13 | $ERROR 14 | Y=F*(1+ERR(1)) + ERR(2) 15 | IPRE=F 16 | 17 | $MSFI =../1005/1005.msf 18 | $SIMULATION ONLYSIM (1968) SUBPROBLEMS=500 19 | $TABLE DV NOHEADER NOPRINT FILE=./1105.tab FORWARD NOAPPEND 20 | -------------------------------------------------------------------------------- /tests/originals/phenobarb.con: -------------------------------------------------------------------------------- 1 | $PROBLEM PHENOBARB SIMPLE MODEL 2 | $INPUT ID TIME AMT WGT APGR DV 3 | $DATA PHENO 4 | $SUBR ADVAN1 TRANS2 5 | $PK 6 | TVCL=THETA(1) 7 | TVV=THETA(2) 8 | CL=TVCL*EXP(ETA(1)) 9 | V=TVV*EXP(ETA(2)) 10 | S1=V 11 | $THETA (0,.0105) (0,1.05) 12 | $OMEGA .25 .25 13 | $ERROR 14 | W=F 15 | Y=F+W*EPS(1) 16 | IPRED=F ; individual-specific prediction 17 | IRES=DV-IPRED ; individual-specific residual 18 | IWRES=IRES/W ; individual-specific weighted residual 19 | $SIGMA .04 20 | $ESTIMATION SIGDIGITS=4 POSTHOC 21 | $COVARIANCE 22 | $TABLE ID WGT APGR TIME AMT CL V ETA1 ETA2 IPRED IWRES 23 | NOPRINT ONEHEADER FILE=TABLE1 24 | -------------------------------------------------------------------------------- /tests/written/TestData1notab.ctl: -------------------------------------------------------------------------------- 1 | 2 | $PROB System Test 1 3 | $INPUT SID SEX AGE RACE HT SMOK HCTZ PROP CON AMT WT TIME SECR DV DROP=RATE EVID SS II ID OCC 4 | $DATA Data1 IGNORE=@ 5 | $SUBROUTINE ADVAN2 TRANS2 6 | $PK 7 | TVCL=THETA(1) 8 | TVV=THETA(2) 9 | TVKA=THETA(3) 10 | CL=TVCL*EXP(ETA(1)) 11 | V =TVV *EXP(ETA(2)) 12 | KA=TVKA*EXP(ETA(3)) 13 | S2=V 14 | $THETA 15 | 18.7 16 | 87.3 17 | 2.13 18 | $OMEGA 19 | 0.128 20 | 0.142 $OMEGA 21 | 1.82 22 | $ERROR 23 | IPRED = F 24 | IRES = DV - F 25 | W = F 26 | IF(W.EQ.0) W = 1 27 | IWRES = IRES/W 28 | Y = IPRED + W*EPS(1) 29 | $COV 30 | 31 | $SIGMA 32 | 0.0231 33 | $EST NOABORT POSTHOC -------------------------------------------------------------------------------- /tests/originals/TestData1notab.ctl: -------------------------------------------------------------------------------- 1 | $PROB System Test 1 2 | $INPUT SID SEX AGE RACE HT SMOK HCTZ PROP CON AMT WT TIME SECR 3 | DV DROP=RATE EVID SS II ID OCC 4 | $DATA Data1 IGNORE=@ 5 | $SUBROUTINE ADVAN2 TRANS2 6 | $PK 7 | TVCL=THETA(1) 8 | TVV=THETA(2) 9 | TVKA=THETA(3) 10 | CL=TVCL*EXP(ETA(1)) 11 | V =TVV *EXP(ETA(2)) 12 | KA=TVKA*EXP(ETA(3)) 13 | S2=V 14 | $THETA 18.7 87.3 2.13 15 | $OMEGA .128 .142 16 | $OMEGA 1.82 17 | $ERROR 18 | IPRED = F 19 | IRES = DV - F 20 | W = F 21 | IF(W.EQ.0) W = 1 22 | IWRES = IRES/W 23 | Y = IPRED + W*EPS(1) 24 | $COV 25 | $SIGMA 0.0231 26 | $EST NOABORT POSTHOC 27 | -------------------------------------------------------------------------------- /tests/written/phenobarb.con: -------------------------------------------------------------------------------- 1 | $PROBLEM PHENOBARB SIMPLE MODEL 2 | $INPUT ID TIME AMT WGT APGR DV 3 | $DATA 'PHENO' 4 | $SUBR ADVAN1 TRANS2 5 | $PK 6 | TVCL=THETA(1) 7 | TVV=THETA(2) 8 | CL=TVCL*EXP(ETA(1)) 9 | V=TVV*EXP(ETA(2)) 10 | S1=V 11 | $THETA (0, 0.0105, ) 12 | (0, 1.05, ) 13 | $OMEGA 0.25 14 | 0.25 15 | $ERROR 16 | W=F 17 | Y=F+W*EPS(1) 18 | IPRED=F ; individual-specific prediction 19 | IRES=DV-IPRED ; individual-specific residual 20 | IWRES=IRES/W ; individual-specific weighted residual 21 | $SIGMA 0.04 22 | $ESTIMATION SIGDIGITS=4 POSTHOC 23 | $COV 24 | 25 | $TABLE ID WGT APGR TIME AMT CL V ETA1 ETA2 IPRED IWRES APPEND ONEHEADER NOPRINT FILE=TABLE1 26 | -------------------------------------------------------------------------------- /tests/originals/1001.ctl: -------------------------------------------------------------------------------- 1 | $PROB 1001 phase1 1CMT 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN2 TRANS2 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) 7 | V =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | S2=V 10 | 11 | $ERROR 12 | Y=F*EXP(ERR(1)) + ERR(2) 13 | IPRE=F 14 | 15 | $THETA 16 | (10) ;CL 17 | (10) ;V 18 | (0.2) ;KA 19 | 20 | $OMEGA 0.09 0.09 0.09 21 | $SIGMA 0.09 0.1 22 | $ESTIMATION MAXEVAL=9999 PRINT=5 NOABORT METHOD=1 INTER MSFO=./1001.msf 23 | $COV PRINT=E 24 | $TABLE NOPRINT FILE=./1001.tab ONEHEADER ID AMT TIME EVID PRED IPRE CWRES 25 | $TABLE NOPRINT FILE=./1001par.tab ONEHEADER ID TIME CL V KA ETA1 ETA2 ETA3 26 | -------------------------------------------------------------------------------- /tests/originals/simexampl.ctl: -------------------------------------------------------------------------------- 1 | $PROBLEM Simulation of population data w/ covariates 2 | $INPUT ID TIME WT AMT DV 3 | $DATA SIMORIG IGNORE=# 4 | $SUBROUTINE ADVAN1 5 | $PK 6 | IF (ICALL.EQ.4) THEN 7 | WT=70+70*ETA(3) 8 | ENDIF 9 | CL=THETA(1)*WT*EXP(ETA(1)) 10 | IF (ICALL.EQ.4) THEN 11 | V=THETA(2)*EXP(ETA(2)) ; Simulated V 12 | ELSE 13 | V=THETA(3)+ETA(4) ; Non-simulated V 14 | ENDIF 15 | K=CL/V 16 | S1=V 17 | $ERROR 18 | IF (ICALL.EQ.4) THEN 19 | Y=F+F*EPS(1) 20 | ELSE 21 | Y=F+F*EPS(2) 22 | ENDIF 23 | $THETA (0,.0625) (10 FIX) (0,12) 24 | $OMEGA .09 (.05 FIX) (.04 FIX) 4 25 | $SIGMA (.01 FIX) .03 26 | $SIMULATION (9215690) SUBPROBLEMS=10 27 | $ESTIMATION 28 | $TABLE ID TIME WT AMT NOPRINT FILE=SIMDATA3 NOHEADER 29 | -------------------------------------------------------------------------------- /tests/written/1001.ctl: -------------------------------------------------------------------------------- 1 | $PROB 1001 phase1 1CMT 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN2 TRANS2 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) 7 | V =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | S2=V 10 | $ERROR 11 | Y=F*EXP(ERR(1)) + ERR(2) 12 | IPRE=F 13 | $THETA 10 ; CL 14 | 10 ; V 15 | 0.2 ; KA 16 | $OMEGA 0.09 17 | 0.09 18 | 0.09 19 | $SIGMA 0.09 20 | 0.10 21 | $ESTIMATION MAXEVAL=9999 PRINT=5 NOABORT METHOD=1 INTER MSFO=./1001.msf 22 | $COV PRINT=E 23 | 24 | $TABLE ID AMT TIME EVID PRED IPRE CWRES APPEND ONEHEADER NOPRINT FILE=./1001.tab 25 | $TABLE ID TIME CL V KA ETA1 ETA2 ETA3 APPEND ONEHEADER NOPRINT FILE=./1001par.tab 26 | -------------------------------------------------------------------------------- /tests/written/TestData1SIM_missingtab.con: -------------------------------------------------------------------------------- 1 | $PROB System Test 2 2 | $INPUT SID SEX AGE RACE HT SMOK HCTZ PROP CON AMT WT TIME SECR DV DROP=RATE EVID SS II ID OCC 3 | $DATA Data1 IGNORE=@ 4 | $SUBROUTINE ADVAN2 TRANS2 5 | $PK 6 | TVCL=THETA(1) 7 | TVV=THETA(2) 8 | TVKA=THETA(3) 9 | CL=TVCL*EXP(ETA(1)) 10 | V =TVV *EXP(ETA(2)) 11 | KA=TVKA*EXP(ETA(3)) 12 | S2=V 13 | $THETA 19.6 14 | 84.6 15 | 1.66 16 | $OMEGA 0.164 17 | 0.165 18 | $OMEGA 1.3 19 | $ERROR 20 | IPRED = F 21 | IRES = DV - F 22 | W = F 23 | IF(W.EQ.0) W = 1 24 | IWRES = IRES/W 25 | Y = IPRED + W*EPS(1) 26 | $SIGMA 0.0202 27 | $SIM (20050213) SUBPROBLEMS= 5 28 | $EST NOABORT POSTHOC 29 | $TABLE ID TIME IPRED IWRES APPEND ONEHEADER NOPRINT FILE=XXXX 30 | -------------------------------------------------------------------------------- /tests/originals/1.ctl: -------------------------------------------------------------------------------- 1 | $PROB 1 phase1 2 CMT like 1004 but diff. initial on V3 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV SUBJ HOUR HEIGHT WT SEX AGE DOSE FED 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) * THETA(6)**SEX * (WT/70)**THETA(7) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4) 10 | V3=THETA(5) 11 | S2=V2 12 | 13 | $ERROR 14 | Y=F*(1+ERR(1)) + ERR(2) 15 | IPRE=F 16 | ; 17 | $THETA 7.565 18 | 19.23 19 | 0.0667 20 | 3.882 21 | 107.5 22 | 1.102 23 | 1.34 24 | $OMEGA 0.1847 25 | 0.154 26 | 0.1363 27 | $SIGMA 0.06894 28 | $SIMULATION ( 7996 NEW) ( 8997 UNIFORM) ONLYSIMULATION 29 | $TABLE ID TIME DV WT SEX LDOS NOPRINT NOAPPEND FILE=sim.tab 30 | -------------------------------------------------------------------------------- /tests/originals/2.ctl: -------------------------------------------------------------------------------- 1 | $PROB 2 phase1 2 CMT like 1004 but diff. initial on V3 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV SUBJ HOUR HEIGHT WT SEX AGE DOSE FED 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) * THETA(6)**SEX * (WT/70)**THETA(7) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4) 10 | V3=THETA(5) 11 | S2=V2 12 | 13 | $ERROR 14 | Y=F*(1+ERR(1)) + ERR(2) 15 | IPRE=F 16 | ; 17 | $THETA 6.531 18 | 20.18 19 | 0.06637 20 | 3.861 21 | 102.6 22 | 1.068 23 | 2.325 24 | $OMEGA 0.2862 25 | 0.12 26 | 0.164 27 | $SIGMA 0.06099 28 | $SIMULATION ( 7997 NEW) ( 8998 UNIFORM) ONLYSIMULATION 29 | $TABLE ID TIME DV WT SEX LDOS NOPRINT NOAPPEND FILE=sim.tab 30 | -------------------------------------------------------------------------------- /tests/originals/4.ctl: -------------------------------------------------------------------------------- 1 | $PROB 4 phase1 2 CMT like 1004 but diff. initial on V3 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV SUBJ HOUR HEIGHT WT SEX AGE DOSE FED 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) * THETA(6)**SEX * (WT/70)**THETA(7) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4) 10 | V3=THETA(5) 11 | S2=V2 12 | 13 | $ERROR 14 | Y=F*(1+ERR(1)) + ERR(2) 15 | IPRE=F 16 | ; 17 | $THETA 6.394 18 | 19.65 19 | 0.06679 20 | 3.521 21 | 92.78 22 | 0.94 23 | 2.011 24 | $OMEGA 0.1886 25 | 0.1146 26 | 0.0846 27 | $SIGMA 0.077 28 | $SIMULATION ( 7999 NEW) ( 9000 UNIFORM) ONLYSIMULATION 29 | $TABLE ID TIME DV WT SEX LDOS NOPRINT NOAPPEND FILE=sim.tab 30 | -------------------------------------------------------------------------------- /tests/written/1.ctl: -------------------------------------------------------------------------------- 1 | $PROB 1 phase1 2 CMT like 1004 but diff. initial on V3 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV SUBJ HOUR HEIGHT WT SEX AGE DOSE FED 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) * THETA(6)**SEX * (WT/70)**THETA(7) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4) 10 | V3=THETA(5) 11 | S2=V2 12 | $ERROR 13 | Y=F*(1+ERR(1)) + ERR(2) 14 | IPRE=F 15 | $THETA 7.565 16 | 19.23 17 | 0.0667 18 | 3.882 19 | 107.5 20 | 1.102 21 | 1.34 22 | $OMEGA 0.1847 23 | 0.1540 24 | 0.1363 25 | $SIGMA 0.06894 26 | $SIMULATION (7996 NEW) (8997 UNIFORM) ONLYSIMULATION 27 | $TABLE ID TIME DV WT SEX LDOS NOAPPEND ONEHEADER NOPRINT FILE=sim.tab 28 | -------------------------------------------------------------------------------- /tests/written/4.ctl: -------------------------------------------------------------------------------- 1 | $PROB 4 phase1 2 CMT like 1004 but diff. initial on V3 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV SUBJ HOUR HEIGHT WT SEX AGE DOSE FED 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) * THETA(6)**SEX * (WT/70)**THETA(7) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4) 10 | V3=THETA(5) 11 | S2=V2 12 | $ERROR 13 | Y=F*(1+ERR(1)) + ERR(2) 14 | IPRE=F 15 | $THETA 6.394 16 | 19.65 17 | 0.06679 18 | 3.521 19 | 92.78 20 | 0.94 21 | 2.011 22 | $OMEGA 0.1886 23 | 0.1146 24 | 0.0846 25 | $SIGMA 0.077 26 | $SIMULATION (7999 NEW) (9000 UNIFORM) ONLYSIMULATION 27 | $TABLE ID TIME DV WT SEX LDOS NOAPPEND ONEHEADER NOPRINT FILE=sim.tab 28 | -------------------------------------------------------------------------------- /tests/originals/3.ctl: -------------------------------------------------------------------------------- 1 | $PROB 3 phase1 2 CMT like 1004 but diff. initial on V3 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV SUBJ HOUR HEIGHT WT SEX AGE DOSE FED 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) * THETA(6)**SEX * (WT/70)**THETA(7) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4) 10 | V3=THETA(5) 11 | S2=V2 12 | 13 | $ERROR 14 | Y=F*(1+ERR(1)) + ERR(2) 15 | IPRE=F 16 | ; 17 | $THETA 8.257 18 | 21.93 19 | 0.06598 20 | 3.722 21 | 74.43 22 | 0.8294 23 | 2.14 24 | $OMEGA 0.1647 25 | 0.1277 26 | 0.113 27 | $SIGMA 0.06041 28 | $SIMULATION ( 7998 NEW) ( 8999 UNIFORM) ONLYSIMULATION 29 | $TABLE ID TIME DV WT SEX LDOS NOPRINT NOAPPEND FILE=sim.tab 30 | -------------------------------------------------------------------------------- /tests/originals/5.ctl: -------------------------------------------------------------------------------- 1 | $PROB 5 phase1 2 CMT like 1004 but diff. initial on V3 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV SUBJ HOUR HEIGHT WT SEX AGE DOSE FED 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) * THETA(6)**SEX * (WT/70)**THETA(7) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4) 10 | V3=THETA(5) 11 | S2=V2 12 | 13 | $ERROR 14 | Y=F*(1+ERR(1)) + ERR(2) 15 | IPRE=F 16 | ; 17 | $THETA 7.266 18 | 20.13 19 | 0.07281 20 | 4.136 21 | 114 22 | 0.9471 23 | 1.937 24 | $OMEGA 0.1526 25 | 0.08448 26 | 0.1314 27 | $SIGMA 0.06269 28 | $SIMULATION ( 8000 NEW) ( 9001 UNIFORM) ONLYSIMULATION 29 | $TABLE ID TIME DV WT SEX LDOS NOPRINT NOAPPEND FILE=sim.tab 30 | -------------------------------------------------------------------------------- /tests/originals/6.ctl: -------------------------------------------------------------------------------- 1 | $PROB 6 phase1 2 CMT like 1004 but diff. initial on V3 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV SUBJ HOUR HEIGHT WT SEX AGE DOSE FED 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) * THETA(6)**SEX * (WT/70)**THETA(7) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4) 10 | V3=THETA(5) 11 | S2=V2 12 | 13 | $ERROR 14 | Y=F*(1+ERR(1)) + ERR(2) 15 | IPRE=F 16 | ; 17 | $THETA 8.205 18 | 21.46 19 | 0.0748 20 | 4.221 21 | 116.3 22 | 0.934 23 | 1.544 24 | $OMEGA 0.2462 25 | 0.1764 26 | 0.08805 27 | $SIGMA 0.07274 28 | $SIMULATION ( 8001 NEW) ( 9002 UNIFORM) ONLYSIMULATION 29 | $TABLE ID TIME DV WT SEX LDOS NOPRINT NOAPPEND FILE=sim.tab 30 | -------------------------------------------------------------------------------- /tests/originals/7.ctl: -------------------------------------------------------------------------------- 1 | $PROB 7 phase1 2 CMT like 1004 but diff. initial on V3 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV SUBJ HOUR HEIGHT WT SEX AGE DOSE FED 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) * THETA(6)**SEX * (WT/70)**THETA(7) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4) 10 | V3=THETA(5) 11 | S2=V2 12 | 13 | $ERROR 14 | Y=F*(1+ERR(1)) + ERR(2) 15 | IPRE=F 16 | ; 17 | $THETA 8.495 18 | 23.5 19 | 0.07476 20 | 4.147 21 | 78.29 22 | 1.061 23 | 1.906 24 | $OMEGA 0.2221 25 | 0.1444 26 | 0.09957 27 | $SIGMA 0.0616 28 | $SIMULATION ( 8002 NEW) ( 9003 UNIFORM) ONLYSIMULATION 29 | $TABLE ID TIME DV WT SEX LDOS NOPRINT NOAPPEND FILE=sim.tab 30 | -------------------------------------------------------------------------------- /tests/originals/8.ctl: -------------------------------------------------------------------------------- 1 | $PROB 8 phase1 2 CMT like 1004 but diff. initial on V3 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV SUBJ HOUR HEIGHT WT SEX AGE DOSE FED 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) * THETA(6)**SEX * (WT/70)**THETA(7) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4) 10 | V3=THETA(5) 11 | S2=V2 12 | 13 | $ERROR 14 | Y=F*(1+ERR(1)) + ERR(2) 15 | IPRE=F 16 | ; 17 | $THETA 7.988 18 | 21.95 19 | 0.07318 20 | 4.524 21 | 98.36 22 | 0.9228 23 | 1.7 24 | $OMEGA 0.2287 25 | 0.1382 26 | 0.06118 27 | $SIGMA 0.06692 28 | $SIMULATION ( 8003 NEW) ( 9004 UNIFORM) ONLYSIMULATION 29 | $TABLE ID TIME DV WT SEX LDOS NOPRINT NOAPPEND FILE=sim.tab 30 | -------------------------------------------------------------------------------- /tests/originals/9.ctl: -------------------------------------------------------------------------------- 1 | $PROB 9 phase1 2 CMT like 1004 but diff. initial on V3 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV SUBJ HOUR HEIGHT WT SEX AGE DOSE FED 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) * THETA(6)**SEX * (WT/70)**THETA(7) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4) 10 | V3=THETA(5) 11 | S2=V2 12 | 13 | $ERROR 14 | Y=F*(1+ERR(1)) + ERR(2) 15 | IPRE=F 16 | ; 17 | $THETA 8.268 18 | 19.21 19 | 0.07017 20 | 3.554 21 | 68.39 22 | 0.9785 23 | 1.814 24 | $OMEGA 0.1765 25 | 0.1231 26 | 0.08504 27 | $SIGMA 0.06092 28 | $SIMULATION ( 8004 NEW) ( 9005 UNIFORM) ONLYSIMULATION 29 | $TABLE ID TIME DV WT SEX LDOS NOPRINT NOAPPEND FILE=sim.tab 30 | -------------------------------------------------------------------------------- /tests/written/2.ctl: -------------------------------------------------------------------------------- 1 | $PROB 2 phase1 2 CMT like 1004 but diff. initial on V3 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV SUBJ HOUR HEIGHT WT SEX AGE DOSE FED 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) * THETA(6)**SEX * (WT/70)**THETA(7) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4) 10 | V3=THETA(5) 11 | S2=V2 12 | $ERROR 13 | Y=F*(1+ERR(1)) + ERR(2) 14 | IPRE=F 15 | $THETA 6.531 16 | 20.18 17 | 0.06637 18 | 3.861 19 | 102.6 20 | 1.068 21 | 2.325 22 | $OMEGA 0.2862 23 | 0.1200 24 | 0.1640 25 | $SIGMA 0.06099 26 | $SIMULATION (7997 NEW) (8998 UNIFORM) ONLYSIMULATION 27 | $TABLE ID TIME DV WT SEX LDOS NOAPPEND ONEHEADER NOPRINT FILE=sim.tab 28 | -------------------------------------------------------------------------------- /tests/written/3.ctl: -------------------------------------------------------------------------------- 1 | $PROB 3 phase1 2 CMT like 1004 but diff. initial on V3 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV SUBJ HOUR HEIGHT WT SEX AGE DOSE FED 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) * THETA(6)**SEX * (WT/70)**THETA(7) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4) 10 | V3=THETA(5) 11 | S2=V2 12 | $ERROR 13 | Y=F*(1+ERR(1)) + ERR(2) 14 | IPRE=F 15 | $THETA 8.257 16 | 21.93 17 | 0.06598 18 | 3.722 19 | 74.43 20 | 0.8294 21 | 2.14 22 | $OMEGA 0.1647 23 | 0.1277 24 | 0.1130 25 | $SIGMA 0.06041 26 | $SIMULATION (7998 NEW) (8999 UNIFORM) ONLYSIMULATION 27 | $TABLE ID TIME DV WT SEX LDOS NOAPPEND ONEHEADER NOPRINT FILE=sim.tab 28 | -------------------------------------------------------------------------------- /tests/written/5.ctl: -------------------------------------------------------------------------------- 1 | $PROB 5 phase1 2 CMT like 1004 but diff. initial on V3 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV SUBJ HOUR HEIGHT WT SEX AGE DOSE FED 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) * THETA(6)**SEX * (WT/70)**THETA(7) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4) 10 | V3=THETA(5) 11 | S2=V2 12 | $ERROR 13 | Y=F*(1+ERR(1)) + ERR(2) 14 | IPRE=F 15 | $THETA 7.266 16 | 20.13 17 | 0.07281 18 | 4.136 19 | 114 20 | 0.9471 21 | 1.937 22 | $OMEGA 0.15260 23 | 0.08448 24 | 0.13140 25 | $SIGMA 0.06269 26 | $SIMULATION (8000 NEW) (9001 UNIFORM) ONLYSIMULATION 27 | $TABLE ID TIME DV WT SEX LDOS NOAPPEND ONEHEADER NOPRINT FILE=sim.tab 28 | -------------------------------------------------------------------------------- /tests/written/6.ctl: -------------------------------------------------------------------------------- 1 | $PROB 6 phase1 2 CMT like 1004 but diff. initial on V3 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV SUBJ HOUR HEIGHT WT SEX AGE DOSE FED 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) * THETA(6)**SEX * (WT/70)**THETA(7) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4) 10 | V3=THETA(5) 11 | S2=V2 12 | $ERROR 13 | Y=F*(1+ERR(1)) + ERR(2) 14 | IPRE=F 15 | $THETA 8.205 16 | 21.46 17 | 0.0748 18 | 4.221 19 | 116.3 20 | 0.934 21 | 1.544 22 | $OMEGA 0.24620 23 | 0.17640 24 | 0.08805 25 | $SIGMA 0.07274 26 | $SIMULATION (8001 NEW) (9002 UNIFORM) ONLYSIMULATION 27 | $TABLE ID TIME DV WT SEX LDOS NOAPPEND ONEHEADER NOPRINT FILE=sim.tab 28 | -------------------------------------------------------------------------------- /tests/written/7.ctl: -------------------------------------------------------------------------------- 1 | $PROB 7 phase1 2 CMT like 1004 but diff. initial on V3 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV SUBJ HOUR HEIGHT WT SEX AGE DOSE FED 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) * THETA(6)**SEX * (WT/70)**THETA(7) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4) 10 | V3=THETA(5) 11 | S2=V2 12 | $ERROR 13 | Y=F*(1+ERR(1)) + ERR(2) 14 | IPRE=F 15 | $THETA 8.495 16 | 23.5 17 | 0.07476 18 | 4.147 19 | 78.29 20 | 1.061 21 | 1.906 22 | $OMEGA 0.22210 23 | 0.14440 24 | 0.09957 25 | $SIGMA 0.0616 26 | $SIMULATION (8002 NEW) (9003 UNIFORM) ONLYSIMULATION 27 | $TABLE ID TIME DV WT SEX LDOS NOAPPEND ONEHEADER NOPRINT FILE=sim.tab 28 | -------------------------------------------------------------------------------- /tests/written/8.ctl: -------------------------------------------------------------------------------- 1 | $PROB 8 phase1 2 CMT like 1004 but diff. initial on V3 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV SUBJ HOUR HEIGHT WT SEX AGE DOSE FED 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) * THETA(6)**SEX * (WT/70)**THETA(7) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4) 10 | V3=THETA(5) 11 | S2=V2 12 | $ERROR 13 | Y=F*(1+ERR(1)) + ERR(2) 14 | IPRE=F 15 | $THETA 7.988 16 | 21.95 17 | 0.07318 18 | 4.524 19 | 98.36 20 | 0.9228 21 | 1.7 22 | $OMEGA 0.22870 23 | 0.13820 24 | 0.06118 25 | $SIGMA 0.06692 26 | $SIMULATION (8003 NEW) (9004 UNIFORM) ONLYSIMULATION 27 | $TABLE ID TIME DV WT SEX LDOS NOAPPEND ONEHEADER NOPRINT FILE=sim.tab 28 | -------------------------------------------------------------------------------- /tests/written/9.ctl: -------------------------------------------------------------------------------- 1 | $PROB 9 phase1 2 CMT like 1004 but diff. initial on V3 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV SUBJ HOUR HEIGHT WT SEX AGE DOSE FED 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) * THETA(6)**SEX * (WT/70)**THETA(7) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4) 10 | V3=THETA(5) 11 | S2=V2 12 | $ERROR 13 | Y=F*(1+ERR(1)) + ERR(2) 14 | IPRE=F 15 | $THETA 8.268 16 | 19.21 17 | 0.07017 18 | 3.554 19 | 68.39 20 | 0.9785 21 | 1.814 22 | $OMEGA 0.17650 23 | 0.12310 24 | 0.08504 25 | $SIGMA 0.06092 26 | $SIMULATION (8004 NEW) (9005 UNIFORM) ONLYSIMULATION 27 | $TABLE ID TIME DV WT SEX LDOS NOAPPEND ONEHEADER NOPRINT FILE=sim.tab 28 | -------------------------------------------------------------------------------- /tests/originals/10.ctl: -------------------------------------------------------------------------------- 1 | $PROB 10 phase1 2 CMT like 1004 but diff. initial on V3 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV SUBJ HOUR HEIGHT WT SEX AGE DOSE FED 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) * THETA(6)**SEX * (WT/70)**THETA(7) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4) 10 | V3=THETA(5) 11 | S2=V2 12 | 13 | $ERROR 14 | Y=F*(1+ERR(1)) + ERR(2) 15 | IPRE=F 16 | ; 17 | $THETA 8.144 18 | 20.51 19 | 0.06545 20 | 3.754 21 | 100.9 22 | 1.009 23 | 1.511 24 | $OMEGA 0.2116 25 | 0.1194 26 | 0.09954 27 | $SIGMA 0.06269 28 | $SIMULATION ( 8005 NEW) ( 9006 UNIFORM) ONLYSIMULATION 29 | $TABLE ID TIME DV WT SEX LDOS NOPRINT NOAPPEND FILE=sim.tab 30 | -------------------------------------------------------------------------------- /tests/written/10.ctl: -------------------------------------------------------------------------------- 1 | $PROB 10 phase1 2 CMT like 1004 but diff. initial on V3 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV SUBJ HOUR HEIGHT WT SEX AGE DOSE FED 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) * THETA(6)**SEX * (WT/70)**THETA(7) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4) 10 | V3=THETA(5) 11 | S2=V2 12 | $ERROR 13 | Y=F*(1+ERR(1)) + ERR(2) 14 | IPRE=F 15 | $THETA 8.144 16 | 20.51 17 | 0.06545 18 | 3.754 19 | 100.9 20 | 1.009 21 | 1.511 22 | $OMEGA 0.21160 23 | 0.11940 24 | 0.09954 25 | $SIGMA 0.06269 26 | $SIMULATION (8005 NEW) (9006 UNIFORM) ONLYSIMULATION 27 | $TABLE ID TIME DV WT SEX LDOS NOAPPEND ONEHEADER NOPRINT FILE=sim.tab 28 | -------------------------------------------------------------------------------- /tests/originals/TestData1SIM_missingtab.con: -------------------------------------------------------------------------------- 1 | $PROB System Test 2 2 | $INPUT SID SEX AGE RACE HT SMOK HCTZ PROP CON AMT WT TIME SECR 3 | DV DROP=RATE EVID SS II ID OCC 4 | $DATA Data1 IGNORE=@ 5 | $SUBROUTINE ADVAN2 TRANS2 6 | $PK 7 | TVCL=THETA(1) 8 | TVV=THETA(2) 9 | TVKA=THETA(3) 10 | CL=TVCL*EXP(ETA(1)) 11 | V =TVV *EXP(ETA(2)) 12 | KA=TVKA*EXP(ETA(3)) 13 | S2=V 14 | $THETA 19.6 84.6 1.66 15 | $OMEGA .164 .165 16 | $OMEGA 1.30 17 | $ERROR 18 | IPRED = F 19 | IRES = DV - F 20 | W = F 21 | IF(W.EQ.0) W = 1 22 | IWRES = IRES/W 23 | Y = IPRED + W*EPS(1) 24 | 25 | $SIGMA 0.0202 26 | $SIM (20050213) SUBPROBLEMS=5 27 | $EST NOABORT POSTHOC 28 | $TABLE ID TIME IPRED IWRES 29 | NOPRINT ONEHEADER FILE=XXXX -------------------------------------------------------------------------------- /tests/written/simexampl.ctl: -------------------------------------------------------------------------------- 1 | $PROBLEM Simulation of population data w/ covariates 2 | $INPUT ID TIME WT AMT DV 3 | $DATA SIMORIG IGNORE=# 4 | $SUBROUTINE ADVAN1 5 | $PK 6 | IF (ICALL.EQ.4) THEN 7 | WT=70+70*ETA(3) 8 | ENDIF 9 | CL=THETA(1)*WT*EXP(ETA(1)) 10 | IF (ICALL.EQ.4) THEN 11 | V=THETA(2)*EXP(ETA(2)) ; Simulated V 12 | ELSE 13 | V=THETA(3)+ETA(4) ; Non-simulated V 14 | ENDIF 15 | K=CL/V 16 | S1=V 17 | $ERROR 18 | IF (ICALL.EQ.4) THEN 19 | Y=F+F*EPS(1) 20 | ELSE 21 | Y=F+F*EPS(2) 22 | ENDIF 23 | $THETA (0, 0.0625, ) 24 | 10 FIX 25 | (0, 12, ) 26 | $OMEGA 0.09 27 | 0.05 FIX 28 | 0.04 FIX 29 | 4.00 30 | $SIGMA 0.01 FIX 31 | 0.03 32 | $SIMULATION (9215690) SUBPROBLEMS= 10 33 | $ESTIMATION 34 | $TABLE ID TIME WT AMT APPEND NOHEADER NOPRINT FILE=SIMDATA3 35 | -------------------------------------------------------------------------------- /inst/exdata/Theophylline.mod: -------------------------------------------------------------------------------- 1 | $PROB Analysis of 1 compartment oral model for theophyline data 2 | $INPUT ID BWT AMT TIME DV MDV 3 | 4 | $DATA THEO.DAT IGNORE=# 5 | $SUBS ADVAN2 TRANS2 6 | $PK 7 | TVKA=THETA(1) 8 | TVCL=THETA(2) 9 | TVV=THETA(3) 10 | 11 | CL=TVCL*EXP(ETA(2)) 12 | V=TVV*EXP(ETA(3)) 13 | K=CL/V 14 | KA=TVKA*EXP(ETA(1)) 15 | S2=V 16 | 17 | $ERROR 18 | IPRED = F 19 | IRES = DV - F 20 | W = F 21 | IF (W.EQ.0) W=1 22 | IWRES = IRES / W 23 | Y=F+EPS(1) 24 | $THETA (0,1.5) (0,0.04) (0,0.4) 25 | $OMEGA 0.8 0.08 0.02 26 | $SIGMA 0.5 27 | 28 | $ESTIMATION SIGDIGITS=3 POSTHOC METHOD=CONDITIONAL 29 | $COVARIANCE 30 | 31 | $TABLE ID TIME IPRED IRES RES PRED WRES NOPRINT ONEHEADER FILE=sdtab0 32 | $TABLE ID CL V KA ETA(1) ETA(2) ETA(3) NOPRINT NOAPPEND ONEHEADER FILE=patab0 33 | 34 | -------------------------------------------------------------------------------- /tests/originals/Theophylline.mod: -------------------------------------------------------------------------------- 1 | $PROB Analysis of 1 compartment oral model for theophyline data 2 | $INPUT ID BWT AMT TIME DV MDV 3 | 4 | $DATA THEO.DAT IGNORE=# 5 | $SUBS ADVAN2 TRANS2 6 | $PK 7 | TVKA=THETA(1) 8 | TVCL=THETA(2) 9 | TVV=THETA(3) 10 | 11 | CL=TVCL*EXP(ETA(2)) 12 | V=TVV*EXP(ETA(3)) 13 | K=CL/V 14 | KA=TVKA*EXP(ETA(1)) 15 | S2=V 16 | 17 | $ERROR 18 | IPRED = F 19 | IRES = DV - F 20 | W = F 21 | IF (W.EQ.0) W=1 22 | IWRES = IRES / W 23 | Y=F+EPS(1) 24 | $THETA (0,1.5) (0,0.04) (0,0.4) 25 | $OMEGA 0.8 0.08 0.02 26 | $SIGMA 0.5 27 | 28 | $ESTIMATION SIGDIGITS=3 POSTHOC METHOD=CONDITIONAL 29 | $COVARIANCE 30 | 31 | $TABLE ID TIME IPRED IRES RES PRED WRES NOPRINT ONEHEADER FILE=sdtab0 32 | $TABLE ID CL V KA ETA(1) ETA(2) ETA(3) NOPRINT NOAPPEND ONEHEADER FILE=patab0 33 | 34 | -------------------------------------------------------------------------------- /tests/written/Theophylline.mod: -------------------------------------------------------------------------------- 1 | $PROB Analysis of 1 compartment oral model for theophyline data 2 | $INPUT ID BWT AMT TIME DV MDV 3 | $DATA THEO.DAT IGNORE=# 4 | $SUBS ADVAN2 TRANS2 5 | $PK 6 | TVKA=THETA(1) 7 | TVCL=THETA(2) 8 | TVV=THETA(3) 9 | CL=TVCL*EXP(ETA(2)) 10 | V=TVV*EXP(ETA(3)) 11 | K=CL/V 12 | KA=TVKA*EXP(ETA(1)) 13 | S2=V 14 | $ERROR 15 | IPRED = F 16 | IRES = DV - F 17 | W = F 18 | IF (W.EQ.0) W=1 19 | IWRES = IRES / W 20 | Y=F+EPS(1) 21 | $THETA (0, 1.5, ) 22 | (0, 0.04, ) 23 | (0, 0.4, ) 24 | $OMEGA 0.80 25 | 0.08 26 | 0.02 27 | $SIGMA 0.5 28 | $ESTIMATION SIGDIGITS=3 POSTHOC METHOD=CONDITIONAL 29 | $COV 30 | 31 | $TABLE ID TIME IPRED IRES RES PRED WRES APPEND ONEHEADER NOPRINT FILE=sdtab0 32 | $TABLE ID CL V KA ETA(1) ETA(2) ETA(3) NOAPPEND ONEHEADER NOPRINT FILE=patab0 33 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: rspeaksnonmem 2 | Type: Package 3 | Title: Read, Modify and run NONMEM from within R 4 | Version: 0.0.1 5 | Date: 2016-07-30 6 | Authors@R: c(person("Mike K", "Smith", email = "mike.k.smith@pfizer.com",role = c("aut", "cre")), 7 | person("Andrew", "Hooker", email = "andrew.hooker@farmbio.uu.se",role = c("aut")), 8 | person("Devin", "Pastoor", email = "devin.pastoor@gmail.com", role=c("ctb")), 9 | person("Ron", "Keizer", email = "ronkeizer@gmail.com",role = c("ctb")) 10 | ) 11 | Description: Read, Modify and run NONMEM from within R. Also calls PsN to run more complex tasks. 12 | License: License: LGPL 13 | LazyData: TRUE 14 | Depends: R (>= 2.6.1) 15 | Imports: RNMImport, knitr, dplyr, stringr 16 | Suggests: testthat 17 | VignetteBuilder: knitr 18 | -------------------------------------------------------------------------------- /tests/originals/1002.ctl: -------------------------------------------------------------------------------- 1 | $PROB 1002 phase1 2 CMT 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4)*EXP(ETA(4)) 10 | V3=THETA(5) *EXP(ETA(5)) 11 | S2=V2 12 | 13 | $ERROR 14 | Y=F*EXP(ERR(1)) + ERR(2) 15 | IPRE=F 16 | 17 | $THETA 18 | (10) ;CL 19 | (10) ;V 20 | (0.2) ;KA 21 | (10) ;Q 22 | (10) ;V3 23 | 24 | $OMEGA 0.09 0.09 0.09 0.09 0.09 25 | $SIGMA 0.09 0.1 26 | $ESTIMATION MAXEVAL=9999 PRINT=5 NOABORT METHOD=1 INTER MSFO=./1002.msf 27 | $COV PRINT=E 28 | $TABLE NOPRINT FILE=./1002.tab ONEHEADER ID AMT TIME EVID PRED IPRE CWRES 29 | $TABLE NOPRINT FILE=./1002par.tab ONEHEADER ID TIME CL Q V2 V3 KA ETA1 ETA2 ETA3 ETA4 ETA5 30 | -------------------------------------------------------------------------------- /tests/written/1002.ctl: -------------------------------------------------------------------------------- 1 | $PROB 1002 phase1 2 CMT 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4)*EXP(ETA(4)) 10 | V3=THETA(5) *EXP(ETA(5)) 11 | S2=V2 12 | $ERROR 13 | Y=F*EXP(ERR(1)) + ERR(2) 14 | IPRE=F 15 | $THETA 10 ; CL 16 | 10 ; V 17 | 0.2 ; KA 18 | 10 ; Q 19 | 10 ; V3 20 | $OMEGA 0.09 21 | 0.09 22 | 0.09 23 | 0.09 24 | 0.09 25 | $SIGMA 0.09 26 | 0.10 27 | $ESTIMATION MAXEVAL=9999 PRINT=5 NOABORT METHOD=1 INTER MSFO=./1002.msf 28 | $COV PRINT=E 29 | 30 | $TABLE ID AMT TIME EVID PRED IPRE CWRES APPEND ONEHEADER NOPRINT FILE=./1002.tab 31 | $TABLE ID TIME CL Q V2 V3 KA ETA1 ETA2 ETA3 ETA4 ETA5 APPEND ONEHEADER NOPRINT FILE=./1002par.tab 32 | -------------------------------------------------------------------------------- /tests/written/sde6.ctl: -------------------------------------------------------------------------------- 1 | $PROBLEM PK ODE HANDS ON ONE 2 | $INPUT ID TIME DV AMT CMT FLAG 3 | $DATA sde6.csv IGNORE=@ 4 | $SUBROUTINE ADVAN6 TOL 10 DP 5 | $MODEL 6 | COMP = (CENTRAL); 7 | $PK 8 | IF(NEWIND.NE.2) OT = 0 9 | TVCL = THETA(1) 10 | CL = TVCL*EXP(ETA(1)) 11 | TVVD = THETA(2) 12 | VD = TVVD*EXP(ETA(2)) 13 | $DES 14 | DADT(1) = - CL/VD*A(1) ;+SGW1 15 | $ERROR 16 | IPRED = A(1)/VD 17 | IRES = DV - IPRED 18 | W = THETA(3) 19 | IWRES = IRES/W 20 | Y = IPRED+W*EPS(1) 21 | $THETA (0, 10, ) ; 1 CL 22 | (0, 32, ) ; 2 VD 23 | (0, 2, ) ; 4 SIGMA 24 | $OMEGA 0.1 ; 1 CL 25 | $OMEGA 0.01 ; 2 VD 26 | $SIGMA 1 FIX ; PK 27 | $EST MAXEVAL=9999 METHOD=1 LAPLACE NUMERICAL SLOW INTER NOABORT SIGDIGITS=3 PRINT=1 MSFO=sde6.msf 28 | $COV MATRIX=R 29 | 30 | $TABLE ID TIME FLAG AMT CMT IPRED IRES IWRES APPEND ONEHEADER NOPRINT FILE=sde6.fit 31 | -------------------------------------------------------------------------------- /tests/originals/control4.con: -------------------------------------------------------------------------------- 1 | ; control 4 example from NONMEM guide part VIII 2 | $PROB THEOPHYLLINE POPULATION DATA 3 | $INPUT ID DOSE TIME CP=DV WT 4 | $DATA THEO 5 | $PRED 6 | ;THETA(1)=MEAN ABSORPTION RATE CONSTANT (1/HR) 7 | ;THETA(2)=MEAN ELIMINATION RATE CONSTANT (1/HR) 8 | ;THETA(3)=SLOPE OF CLEARANCE VS WEIGHT RELATIONSHIP (LITERS/HR/KG) 9 | ;DOSE=WT-ADJUSTED DOSE (MG/KG) 10 | ;DS=NON-WT-ADJUSTED DOSE (MG) 11 | IF (DOSE.NE.0) THEN 12 | DS=DOSE*WT 13 | W=WT 14 | ENDIF 15 | KA=THETA(1)+ETA(1) 16 | KE=THETA(2)+ETA(2) 17 | CL=THETA(3)*W+ETA(3) 18 | D=EXP(-KE*TIME)-EXP(-KA*TIME) 19 | E=CL*(KA-KE) 20 | F=DS*KE*KA/E*D 21 | Y=F+EPS(1) 22 | $THETA (.1,3,5) ;A 23 | $THETA (.008,.08,.5) ;B 24 | $THETA (.004,.04,.9) ;C 25 | $OMEGA BLOCK(3) 6 .005 .0002 .3 .006 .4 26 | $SIGMA .4 27 | $EST MAXEVAL=450 PRINT=5 28 | $COV 29 | $TABLE ID DOSE WT TIME FILE=tab4.tab 30 | -------------------------------------------------------------------------------- /tests/written/TestData1.ctl: -------------------------------------------------------------------------------- 1 | $PROB NM7 test 1 2 | $INPUT SID SEX AGE RACE HT SMOK HCTZ PROP CON AMT WT TIME SECR DV DROP=RATE EVID SS II ID OCC 3 | $DATA Data1 IGNORE=@ 4 | $SUBROUTINE ADVAN2 TRANS2 5 | $PK 6 | TVCL=THETA(1) 7 | TVV=THETA(2) 8 | TVKA=THETA(3) 9 | CL=TVCL*EXP(ETA(1)) 10 | V =TVV *EXP(ETA(2)) 11 | KA=TVKA*EXP(ETA(3)) 12 | S2=V 13 | $THETA 18.7 14 | 87.3 15 | 2.13 16 | $OMEGA 0.128 17 | 0.142 18 | $OMEGA 1.82 19 | $ERROR 20 | IPRED = F 21 | IRES = DV - F 22 | W = F 23 | IF(W.EQ.0) W = 1 24 | IWRES = IRES/W 25 | Y = IPRED + W*EPS(1) 26 | $SIGMA 0.0231 27 | $EST METHOD=ITS INTERACTION FILE=TestData1.EXT CTYPE=3 NITER=1000 PRINT=5 NOABORT MSFO=testdata1.MSF NSIG=3 SIGL=6 28 | $EST METHOD=SAEM NBURN=2000 NITER=500 PRINT=100 29 | $COV MATRIX=R 30 | 31 | $TABLE ID TIME IPRED IWRES WT ETA1 APPEND ONEHEADER NOPRINT FILE=tab1 32 | -------------------------------------------------------------------------------- /tests/written/TestData1_missingtab.ctl: -------------------------------------------------------------------------------- 1 | $PROB NM7 test 1 2 | $INPUT SID SEX AGE RACE HT SMOK HCTZ PROP CON AMT WT TIME SECR DV DROP=RATE EVID SS II ID OCC 3 | $DATA Data1 IGNORE=@ 4 | $SUBROUTINE ADVAN2 TRANS2 5 | $PK 6 | TVCL=THETA(1) 7 | TVV=THETA(2) 8 | TVKA=THETA(3) 9 | CL=TVCL*EXP(ETA(1)) 10 | V =TVV *EXP(ETA(2)) 11 | KA=TVKA*EXP(ETA(3)) 12 | S2=V 13 | $THETA 18.7 14 | 87.3 15 | 2.13 16 | $OMEGA 0.128 17 | 0.142 18 | $OMEGA 1.82 19 | $ERROR 20 | IPRED = F 21 | IRES = DV - F 22 | W = F 23 | IF(W.EQ.0) W = 1 24 | IWRES = IRES/W 25 | Y = IPRED + W*EPS(1) 26 | $SIGMA 0.0231 27 | $EST METHOD=ITS INTERACTION FILE=TestData1.EXT CTYPE=3 NITER=1000 PRINT=5 NOABORT MSFO=testdata1.MSF NSIG=3 SIGL=6 28 | $EST METHOD=SAEM NBURN=2000 NITER=500 PRINT=100 29 | $COV MATRIX=R 30 | 31 | $TABLE ID TIME IPRED IWRES WT ETA1 APPEND ONEHEADER NOPRINT FILE=XXXX 32 | -------------------------------------------------------------------------------- /tests/originals/1003.ctl: -------------------------------------------------------------------------------- 1 | $PROB 1003 phase1 2 CMT like 1002 but no eta on Q/v3 and no + err 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4);*EXP(ETA(4)) 10 | V3=THETA(5); *EXP(ETA(5)) 11 | S2=V2 12 | 13 | $ERROR 14 | Y=F*EXP(ERR(1)); + ERR(2) 15 | IPRE=F 16 | 17 | $THETA 18 | (10) ;CL 19 | (10) ;V 20 | (0.2) ;KA 21 | (10) ;Q 22 | (10) ;V3 23 | 24 | $OMEGA 0.09 0.09 0.09 ;0.09 0.09 25 | $SIGMA 0.09 ;0.1 26 | $ESTIMATION MAXEVAL=9999 PRINT=5 NOABORT METHOD=1 INTER MSFO=./1003.msf 27 | $COV PRINT=E 28 | $TABLE NOPRINT FILE=./1003.tab ONEHEADER ID AMT TIME EVID PRED IPRE CWRES 29 | $TABLE NOPRINT FILE=./1003par.tab ONEHEADER ID TIME CL Q V2 V3 KA ETA1 ETA2 ETA3 30 | -------------------------------------------------------------------------------- /tests/written/1003.ctl: -------------------------------------------------------------------------------- 1 | $PROB 1003 phase1 2 CMT like 1002 but no eta on Q/v3 and no + err 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4);*EXP(ETA(4)) 10 | V3=THETA(5); *EXP(ETA(5)) 11 | S2=V2 12 | $ERROR 13 | Y=F*EXP(ERR(1)); + ERR(2) 14 | IPRE=F 15 | $THETA 10 ; CL 16 | 10 ; V 17 | 0.2 ; KA 18 | 10 ; Q 19 | 10 ; V3 20 | $OMEGA 0.09 ; 0.09 0.09 21 | 0.09 ; 0.09 0.09 22 | 0.09 ; 0.09 0.09 23 | $SIGMA 0.09 ; 0.1 24 | $ESTIMATION MAXEVAL=9999 PRINT=5 NOABORT METHOD=1 INTER MSFO=./1003.msf 25 | $COV PRINT=E 26 | 27 | $TABLE ID AMT TIME EVID PRED IPRE CWRES APPEND ONEHEADER NOPRINT FILE=./1003.tab 28 | $TABLE ID TIME CL Q V2 V3 KA ETA1 ETA2 ETA3 APPEND ONEHEADER NOPRINT FILE=./1003par.tab 29 | -------------------------------------------------------------------------------- /tests/written/control4.con: -------------------------------------------------------------------------------- 1 | $PROB THEOPHYLLINE POPULATION DATA 2 | $INPUT ID DOSE TIME CP=DV WT 3 | $DATA 'THEO' 4 | $PRED 5 | ;THETA(1)=MEAN ABSORPTION RATE CONSTANT (1/HR) 6 | ;THETA(2)=MEAN ELIMINATION RATE CONSTANT (1/HR) 7 | ;THETA(3)=SLOPE OF CLEARANCE VS WEIGHT RELATIONSHIP (LITERS/HR/KG) 8 | ;DOSE=WT-ADJUSTED DOSE (MG/KG) 9 | ;DS=NON-WT-ADJUSTED DOSE (MG) 10 | IF (DOSE.NE.0) THEN 11 | DS=DOSE*WT 12 | W=WT 13 | ENDIF 14 | KA=THETA(1)+ETA(1) 15 | KE=THETA(2)+ETA(2) 16 | CL=THETA(3)*W+ETA(3) 17 | D=EXP(-KE*TIME)-EXP(-KA*TIME) 18 | E=CL*(KA-KE) 19 | F=DS*KE*KA/E*D 20 | Y=F+EPS(1) 21 | $THETA (0.1, 3, 5) ; A 22 | (0.008, 0.08, 0.5) ; B 23 | (0.004, 0.04, 0.9) ; C 24 | $OMEGA BLOCK(3) 6 ; 1 25 | 0.005 2e-04 ; 2 26 | 0.3 0.006 0.4 ; 3 27 | 28 | $SIGMA 0.4 29 | $EST MAXEVAL=450 PRINT=5 30 | $COV 31 | 32 | $TABLE ID DOSE WT TIME APPEND ONEHEADER NOPRINT FILE=tab4.tab 33 | -------------------------------------------------------------------------------- /tests/originals/1004.ctl: -------------------------------------------------------------------------------- 1 | $PROB 1004 phase1 2 CMT like 1003 but better bounds 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4);*EXP(ETA(4)) 10 | V3=THETA(5); *EXP(ETA(5)) 11 | S2=V2 12 | 13 | $ERROR 14 | Y=F*EXP(ERR(1)); + ERR(2) 15 | IPRE=F 16 | 17 | $THETA 18 | (0,10,50) ;CL 19 | (0,10,100) ;V 20 | (0,0.2, 5) ;KA 21 | (0,10,50) ;Q 22 | (0,10,1000) ;V3 23 | 24 | $OMEGA 0.09 0.09 0.09 ;0.09 0.09 25 | $SIGMA 0.09 ;0.1 26 | $ESTIMATION MAXEVAL=9999 PRINT=5 NOABORT METHOD=1 INTER MSFO=./1004.msf 27 | $COV PRINT=E 28 | $TABLE NOPRINT FILE=./1004.tab ONEHEADER ID AMT TIME EVID PRED IPRE CWRES 29 | $TABLE NOPRINT FILE=./1004par.tab ONEHEADER ID TIME CL Q V2 V3 KA ETA1 ETA2 ETA3 30 | -------------------------------------------------------------------------------- /tests/written/1004.ctl: -------------------------------------------------------------------------------- 1 | $PROB 1004 phase1 2 CMT like 1003 but better bounds 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4);*EXP(ETA(4)) 10 | V3=THETA(5); *EXP(ETA(5)) 11 | S2=V2 12 | $ERROR 13 | Y=F*EXP(ERR(1)); + ERR(2) 14 | IPRE=F 15 | $THETA (0, 10, 50) ; CL 16 | (0, 10, 100) ; V 17 | (0, 0.2, 5) ; KA 18 | (0, 10, 50) ; Q 19 | (0, 10, 1000) ; V3 20 | $OMEGA 0.09 ; 0.09 0.09 21 | 0.09 ; 0.09 0.09 22 | 0.09 ; 0.09 0.09 23 | $SIGMA 0.09 ; 0.1 24 | $ESTIMATION MAXEVAL=9999 PRINT=5 NOABORT METHOD=1 INTER MSFO=./1004.msf 25 | $COV PRINT=E 26 | 27 | $TABLE ID AMT TIME EVID PRED IPRE CWRES APPEND ONEHEADER NOPRINT FILE=./1004.tab 28 | $TABLE ID TIME CL Q V2 V3 KA ETA1 ETA2 ETA3 APPEND ONEHEADER NOPRINT FILE=./1004par.tab 29 | -------------------------------------------------------------------------------- /tests/originals/TestData1.ctl: -------------------------------------------------------------------------------- 1 | $PROB NM7 test 1 2 | $INPUT SID SEX AGE RACE HT SMOK HCTZ PROP CON AMT WT TIME SECR 3 | DV DROP=RATE EVID SS II ID OCC 4 | $DATA Data1 IGNORE=@ 5 | $SUBROUTINE ADVAN2 TRANS2 6 | $PK 7 | TVCL=THETA(1) 8 | TVV=THETA(2) 9 | TVKA=THETA(3) 10 | CL=TVCL*EXP(ETA(1)) 11 | V =TVV *EXP(ETA(2)) 12 | KA=TVKA*EXP(ETA(3)) 13 | S2=V 14 | $THETA 18.7 87.3 2.13 15 | $OMEGA .128 .142 16 | $OMEGA 1.82 17 | $ERROR 18 | IPRED = F 19 | IRES = DV - F 20 | W = F 21 | IF(W.EQ.0) W = 1 22 | IWRES = IRES/W 23 | Y = IPRED + W*EPS(1) 24 | 25 | $SIGMA 0.0231 26 | $EST METHOD=ITS INTERACTION FILE=TestData1.EXT CTYPE=3 27 | NITER=1000 PRINT=5 NOABORT MSFO=testdata1.MSF NSIG=3 SIGL=6 28 | $EST METHOD=SAEM NBURN=2000 NITER=500 PRINT=100 29 | $COV MATRIX=R 30 | $TABLE ID TIME IPRED IWRES WT ETA1 31 | NOPRINT ONEHEADER FILE=tab1 32 | 33 | -------------------------------------------------------------------------------- /tests/originals/TestData1_missingtab.ctl: -------------------------------------------------------------------------------- 1 | $PROB NM7 test 1 2 | $INPUT SID SEX AGE RACE HT SMOK HCTZ PROP CON AMT WT TIME SECR 3 | DV DROP=RATE EVID SS II ID OCC 4 | $DATA Data1 IGNORE=@ 5 | $SUBROUTINE ADVAN2 TRANS2 6 | $PK 7 | TVCL=THETA(1) 8 | TVV=THETA(2) 9 | TVKA=THETA(3) 10 | CL=TVCL*EXP(ETA(1)) 11 | V =TVV *EXP(ETA(2)) 12 | KA=TVKA*EXP(ETA(3)) 13 | S2=V 14 | $THETA 18.7 87.3 2.13 15 | $OMEGA .128 .142 16 | $OMEGA 1.82 17 | $ERROR 18 | IPRED = F 19 | IRES = DV - F 20 | W = F 21 | IF(W.EQ.0) W = 1 22 | IWRES = IRES/W 23 | Y = IPRED + W*EPS(1) 24 | 25 | $SIGMA 0.0231 26 | $EST METHOD=ITS INTERACTION FILE=TestData1.EXT CTYPE=3 27 | NITER=1000 PRINT=5 NOABORT MSFO=testdata1.MSF NSIG=3 SIGL=6 28 | $EST METHOD=SAEM NBURN=2000 NITER=500 PRINT=100 29 | $COV MATRIX=R 30 | $TABLE ID TIME IPRED IWRES WT ETA1 31 | NOPRINT ONEHEADER FILE=XXXX 32 | 33 | -------------------------------------------------------------------------------- /tests/originals/multiprob1.mod: -------------------------------------------------------------------------------- 1 | $PROB READ THE MODEL SPECIFICATION FILE 2 | $DATA DATA.csv 3 | $INPUT ID DOSE WT TIME DV 4 | $SUBROUTINE PRIOR=prior 5 | $PRED 6 | ; 7 | ; THETA(1)=MEAN ABSORPTION RATE CONSTANT - MEAN ELIM. RATE CONSTANT (l/HR) 8 | ; THETA(2)=MEAN ELIM. RATE CONSTANT (1/HR) 9 | ; THETA(3)=SLOPE OF CLEARANCE VS WEIGHT RELATIONSHIP (LITERS/HR/KG) 10 | ; DOSE=WEIGHT-ADJUSTED DOSE (MG/KG) 11 | ; 12 | IF (NEWIND.NE.2) THEN 13 | AMT=DOSE*WT 14 | W=WT 15 | ENDIF 16 | T0=THETA(1)*EXP(ETA(1)) 17 | T2=THETA(2)*EXP(ETA(2)) 18 | T1=T2+T0 19 | T3=THETA(3)*W*EXP(ETA(3)) 20 | A=EXP(-T2*TIME) 21 | B=EXP(-T1*TIME) 22 | C=T1-T2 23 | D=A-B 24 | E=T3*C 25 | Y=AMT*T1*T2/E*D+EPS(2) 26 | $MSFI msf1 ONLYREAD 27 | $PROB POPULATION DATA WITH PRIOR ON THETA AND OMEGA 28 | $INPUT ID DOSE WT TIME DV 29 | $DATA data 30 | $THETA (0,4,5) (0,.09,.5) (.004,.01,.9) 31 | $OMEGA BLOCK (3) .7 .04 .05 .02 .06 .08 32 | $SIGMA .4 FIX .5 33 | $SIM (547676) ONLY 34 | -------------------------------------------------------------------------------- /tests/written/TestData1SIM.con: -------------------------------------------------------------------------------- 1 | $PROB System Test 2 2 | $INPUT SID SEX AGE RACE HT SMOK HCTZ PROP CON AMT WT TIME SECR DV DROP=RATE EVID SS II ID OCC 3 | $DATA Data1 IGNORE=@ 4 | $SUBROUTINE ADVAN2 TRANS2 5 | $PK 6 | TVCL=THETA(1) 7 | TVV=THETA(2) 8 | TVKA=THETA(3) 9 | CL=TVCL*EXP(ETA(1)) 10 | V =TVV *EXP(ETA(2)) 11 | KA=TVKA*EXP(ETA(3)) 12 | S2=V 13 | $THETA 19.6 14 | 84.6 15 | 1.66 16 | $OMEGA 0.164 17 | 0.165 18 | $OMEGA 1.3 19 | $ERROR 20 | IPRED = F 21 | IRES = DV - F 22 | W = F 23 | IF(W.EQ.0) W = 1 24 | IWRES = IRES/W 25 | Y = IPRED + W*EPS(1) 26 | $SIGMA 0.0202 27 | $SIM (20050213) SUBPROBLEMS= 5 28 | $EST NOABORT POSTHOC 29 | $TABLE ID TIME IPRED IWRES APPEND ONEHEADER NOPRINT FILE=sdtab1 30 | $TABLE ID CL V KA APPEND ONEHEADER NOPRINT FILE=patab1 31 | $TABLE ID AGE HT WT SECR APPEND ONEHEADER NOPRINT FILE=cotab1 32 | $TABLE ID SEX RACE SMOK HCTZ PROP CON APPEND ONEHEADER NOPRINT FILE=catab1 33 | $TABLE ID OCC TIME IPRED IWRES APPEND ONEHEADER NOPRINT FILE=mutab1 34 | $TABLE SID APPEND ONEHEADER NOPRINT FILE=mytab1 35 | -------------------------------------------------------------------------------- /R/PsNHeader.R: -------------------------------------------------------------------------------- 1 | PsNHeader <- function(problem = NULL, 2 | parentRun = NULL, 3 | description = NULL, 4 | runLabel = NULL, 5 | structure = NULL, 6 | covariates = NULL, 7 | IIV = NULL, 8 | IOV = NULL, 9 | RUV = NULL, 10 | estimation = NULL) { 11 | 12 | paste(problem, "\n", 13 | ";; 1. Based on:", parentRun, "\n", 14 | ";; 2. Description:\n", ";; ", description, "\n", 15 | ";; 3. Label:\n", ";; ", runLabel, "\n", 16 | ";; 4. Structural model:\n", ";; ", structure, "\n", 17 | ";; 5. Covariate model:\n", ";; ", covariates, "\n", 18 | ";; 6. Inter-individual variability:\n", ";; ", IIV, "\n", 19 | ";; 7. Inter-occasion variability:\n", ";; ", IOV, "\n", 20 | ";; 8. Residual variability:\n", ";; ", RUV, "\n", 21 | ";; 9. Estimation:\n", ";; ", estimation, sep = "") 22 | 23 | } 24 | -------------------------------------------------------------------------------- /tests/originals/sde6.ctl: -------------------------------------------------------------------------------- 1 | $PROBLEM PK ODE HANDS ON ONE 2 | 3 | $INPUT ID TIME DV AMT CMT FLAG 4 | 5 | $DATA sde6.csv 6 | IGNORE=@ 7 | 8 | $SUBROUTINE ADVAN6 TOL 10 DP 9 | 10 | $MODEL 11 | COMP = (CENTRAL); 12 | 13 | $PK 14 | IF(NEWIND.NE.2) OT = 0 15 | 16 | TVCL = THETA(1) 17 | CL = TVCL*EXP(ETA(1)) 18 | 19 | TVVD = THETA(2) 20 | VD = TVVD*EXP(ETA(2)) 21 | 22 | 23 | $DES 24 | DADT(1) = - CL/VD*A(1) ;+SGW1 25 | 26 | $ERROR 27 | 28 | IPRED = A(1)/VD 29 | IRES = DV - IPRED 30 | W = THETA(3) 31 | IWRES = IRES/W 32 | Y = IPRED+W*EPS(1) 33 | 34 | $THETA (0,10) ;1 CL 35 | $THETA (0,32) ;2 VD 36 | $THETA (0, 2) ;4 SIGMA 37 | 38 | $OMEGA 0.1 ;1 CL 39 | $OMEGA 0.01 ;2 VD 40 | 41 | $SIGMA 1 FIX ; PK 42 | 43 | $EST MAXEVAL=9999 METHOD=1 LAPLACE NUMERICAL SLOW INTER NOABORT SIGDIGITS=3 PRINT=1 MSFO=sde6.msf 44 | $COV MATRIX=R 45 | 46 | $TABLE ID TIME FLAG AMT CMT IPRED IRES IWRES 47 | ONEHEADER NOPRINT FILE=sde6.fit 48 | -------------------------------------------------------------------------------- /R/basicGOF_Xpose.R: -------------------------------------------------------------------------------- 1 | #' Finds the run number from sdtab, creates an xpdb and runs basic GOF plots 2 | #' 3 | #' @param runno NONMEM run number (based on sdtab). 4 | #' @return Xpose core diagnostic plots 5 | #' @examples 6 | #' basicGOF_Xpose(1) 7 | 8 | basicGOF_Xpose <- function(runno = NULL, ...) { 9 | ## ----setupRunnoforXpose-------------------------------------------------- 10 | if (!length(runno) > 0) 11 | runno <- as.numeric(gsub("[a-z]", "", list.files(pattern = "^sdtab")[1])) 12 | 13 | ## ----createXpdb---------------------------------------------------------- 14 | xpdb <- xpose4::xpose.data(runno, quiet = T) 15 | # save(base.xpdb, file='Xpose database.RData') 16 | 17 | ## ----xposeGOF------------------------------------------------------------ 18 | print(xpose4::dv.vs.pred.ipred(xpdb)) 19 | print(xpose4::pred.vs.idv(xpdb)) 20 | print(xpose4::ipred.vs.idv(xpdb)) 21 | print(xpose4::wres.vs.idv(xpdb)) 22 | print(xpose4::wres.vs.pred(xpdb)) 23 | print(xpose4::ranpar.hist(xpdb)) 24 | print(xpose4::ind.plots(xpdb, layout = c(4, 4))) 25 | } 26 | -------------------------------------------------------------------------------- /tests/originals/TestData1SIM.con: -------------------------------------------------------------------------------- 1 | $PROB System Test 2 2 | $INPUT SID SEX AGE RACE HT SMOK HCTZ PROP CON AMT WT TIME SECR 3 | DV DROP=RATE EVID SS II ID OCC 4 | $DATA Data1 IGNORE=@ 5 | $SUBROUTINE ADVAN2 TRANS2 6 | $PK 7 | TVCL=THETA(1) 8 | TVV=THETA(2) 9 | TVKA=THETA(3) 10 | CL=TVCL*EXP(ETA(1)) 11 | V =TVV *EXP(ETA(2)) 12 | KA=TVKA*EXP(ETA(3)) 13 | S2=V 14 | $THETA 19.6 84.6 1.66 15 | $OMEGA .164 .165 16 | $OMEGA 1.30 17 | $ERROR 18 | IPRED = F 19 | IRES = DV - F 20 | W = F 21 | IF(W.EQ.0) W = 1 22 | IWRES = IRES/W 23 | Y = IPRED + W*EPS(1) 24 | 25 | $SIGMA 0.0202 26 | $SIM (20050213) SUBPROBLEMS=5 27 | $EST NOABORT POSTHOC 28 | $TABLE ID TIME IPRED IWRES 29 | NOPRINT ONEHEADER FILE=sdtab1 30 | 31 | $TABLE ID CL V KA 32 | NOPRINT ONEHEADER FILE=patab1 33 | 34 | $TABLE ID AGE HT WT SECR 35 | NOPRINT ONEHEADER FILE=cotab1 36 | 37 | $TABLE ID SEX RACE SMOK HCTZ PROP CON 38 | NOPRINT ONEHEADER FILE=catab1 39 | 40 | $TABLE ID OCC TIME IPRED IWRES 41 | NOPRINT ONEHEADER FILE=mutab1 42 | $TABLE SID NOPRINT ONEHEADER FILE=mytab1 43 | -------------------------------------------------------------------------------- /tests/written/warfarin.ctl: -------------------------------------------------------------------------------- 1 | $PROB WARFARIN PK 2 | $INPUT ID TIME WT AGE SEX AMT DVID DV MDV 3 | $DATA warfarin_conc_pca.csv IGNORE=# 4 | IGNORE=(DVID.EQ.2) 5 | $SUBR 6 | ADVAN2 TRANS2 7 | $PK 8 | GRPCL = THETA(1)*(WT/70)**0.75 9 | GRPV = THETA(2)*WT/70 10 | GRPKA = THETA(3) 11 | GRPLG = THETA(4) 12 | CL = GRPCL*EXP(ETA(1)) 13 | V = GRPV*EXP(ETA(2)) 14 | KA = GRPKA*EXP(ETA(3)) 15 | ALAG1 = GRPLG*EXP(ETA(4)) 16 | S2 = V 17 | $ERROR 18 | CONC = A(2)/V 19 | IPRED=F 20 | IF(F.GT.0) IPRED=F 21 | IRES = DV - IPRED 22 | W = THETA(5)+THETA(6)*CONC 23 | Y = IPRED + W*EPS(1) 24 | $THETA (0.001, 0.1, ) ; POP_CL 25 | (0.001, 8, ) ; POP_V 26 | (0.001, 2, ) ; POP_KA 27 | 0.25 FIX ; POP_TLAG 28 | 0 FIX ; RUV_ADD 29 | 0.05 ; RUV_PROP 30 | $OMEGA BLOCK(2) 0.1 ; PPV_CL 31 | 0.01 0.1 ; PPV_V 32 | 33 | $OMEGA 0.1 ; PPV_KA 34 | 0.0 FIX ; PPV_TLAG 35 | $SIGMA 1 FIX 36 | $EST METHOD=COND INTER MAX=9990 SIG=3 NOABORT 37 | $COV 38 | 39 | $TABLE ID TIME IPRED IRES RES PRED WRES APPEND ONEHEADER NOPRINT FILE=sdtab0 40 | $TABLE ID CL V KA ALAG1 ETA(1) ETA(2) ETA(3) ETA(4) NOAPPEND ONEHEADER NOPRINT FILE=patab0 41 | $TABLE ID AGE WT NOAPPEND ONEHEADER NOPRINT FILE=cotab0 42 | $TABLE ID SEX NOAPPEND ONEHEADER NOPRINT FILE=catab0 43 | -------------------------------------------------------------------------------- /tests/written/warfarin_boot.ctl: -------------------------------------------------------------------------------- 1 | $PROB WARFARIN PK 2 | $INPUT ID TIME WT AGE SEX AMT DVID DV MDV 3 | $DATA warfarin_boot50.dta IGNORE=# 4 | IGNORE=(DVID.EQ.2) 5 | $SUBR 6 | ADVAN2 TRANS2 7 | $PK 8 | GRPCL = THETA(1)*(WT/70)**0.75 9 | GRPV = THETA(2)*WT/70 10 | GRPKA = THETA(3) 11 | GRPLG = THETA(4) 12 | CL = GRPCL*EXP(ETA(1)) 13 | V = GRPV*EXP(ETA(2)) 14 | KA = GRPKA*EXP(ETA(3)) 15 | ALAG1 = GRPLG*EXP(ETA(4)) 16 | S2 = V 17 | $ERROR 18 | CONC = A(2)/V 19 | IPRED=F 20 | IF(F.GT.0) IPRED=F 21 | IRES = DV - IPRED 22 | W = THETA(5)+THETA(6)*CONC 23 | Y = IPRED + W*EPS(1) 24 | $THETA (0.001, 0.1, ) ; POP_CL 25 | (0.001, 8, ) ; POP_V 26 | (0.001, 2, ) ; POP_KA 27 | 0.25 FIX ; POP_TLAG 28 | 0 FIX ; RUV_ADD 29 | 0.05 ; RUV_PROP 30 | $OMEGA BLOCK(2) 0.1 ; PPV_CL 31 | 0.01 0.1 ; PPV_V 32 | 33 | $OMEGA 0.1 ; PPV_KA 34 | 0.0 FIX ; PPV_TLAG 35 | $SIGMA 1 FIX 36 | $EST METHOD=COND INTER MAX=9990 SIG=3 NOABORT 37 | $COV 38 | 39 | $TABLE ID TIME IPRED IRES RES PRED WRES APPEND ONEHEADER NOPRINT FILE=sdtab0 40 | $TABLE ID CL V KA ALAG1 ETA(1) ETA(2) ETA(3) ETA(4) NOAPPEND ONEHEADER NOPRINT FILE=patab0 41 | $TABLE ID AGE WT NOAPPEND ONEHEADER NOPRINT FILE=cotab0 42 | $TABLE ID SEX NOAPPEND ONEHEADER NOPRINT FILE=catab0 43 | -------------------------------------------------------------------------------- /vignettes/using_pharmpy.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Installing and using pharmpy within R" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Installing and using pharmpy within R} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | ```{r, include = FALSE} 11 | knitr::opts_chunk$set( 12 | collapse = TRUE, 13 | comment = "#>" 14 | ) 15 | ``` 16 | 17 | ```{r setup} 18 | library(rspeaksnonmem) 19 | ``` 20 | 21 | 22 | ```{r FirstTime_setup, eval=FALSE} 23 | library(reticulate) 24 | conda_create("r-rspeaksnonmem") 25 | conda_install("r-rspeaksnonmem", "pharmpy-core", pip = TRUE) 26 | ``` 27 | 28 | ```{r Subsequent_setup} 29 | library(reticulate) 30 | use_condaenv("r-rspeaksnonmem") 31 | pharmpy <- import("pharmpy") 32 | ``` 33 | 34 | ```{r read_NONMEM_using_pharmpy} 35 | model <- pharmpy$Model(system.file("extdata","warfarin.ctl", package="rspeaksnonmem")) 36 | model$parameters 37 | ``` 38 | 39 | ```{r update_parameters} 40 | params <- model$parameters 41 | params$inits <- list('THETA(1)'=2) # set initial estimate of THETA(1) to 2 42 | model$parameters <- params 43 | model$parameters 44 | ``` 45 | 46 | ```{r write_model, eval=FALSE} 47 | model$write(path = "warfarin_updated.ctl") 48 | ``` 49 | -------------------------------------------------------------------------------- /tests/written/sde7.ctl: -------------------------------------------------------------------------------- 1 | $PROBLEM PK ODE HANDS ON ONE 2 | $INPUT ID HOUR DV AMT CMT FLAG EVID MDV SDE TIME 3 | $DATA sde7.csv IGNORE=@ 4 | $SUBROUTINE ADVAN6 TOL 10 DP 5 | $MODEL 6 | COMP = (CENTRAL); 7 | COMP = (P1) 8 | $THETA (0, 10, ) ; 1 CL 9 | (0, 32, ) ; 2 VD 10 | (0, 2, ) ; 4 SIGMA 11 | (0, 1, ) ; SGW1 12 | $OMEGA 0.1 ; 1 CL 13 | $OMEGA 0.01 ; 2 VD 14 | $SIGMA 1 FIX ; PK 15 | $PK 16 | IF(NEWIND.NE.2) OT = 0 17 | TVCL = THETA(1) 18 | CL = TVCL*EXP(ETA(1)) 19 | TVVD = THETA(2) 20 | VD = TVVD*EXP(ETA(2)) 21 | SGW1 = THETA(4) 22 | IF(NEWIND.NE.2) THEN 23 | AHT1 = 0 24 | PHT1 = 0 25 | ENDIF 26 | IF(EVID.NE.3) THEN 27 | A1 = A(1) 28 | A2 = A(2) 29 | ELSE 30 | A1 = A1 31 | A2 = A2 32 | ENDIF 33 | IF(EVID.EQ.0) OBS = DV 34 | IF(EVID.GT.2.AND.SDE.EQ.2) THEN 35 | RVAR = A2*(1/VD)**2+ THETA(3)**2 36 | K1 = A2*(1/VD)/RVAR 37 | AHT1 = A1 + K1*(OBS -( A1/VD)) 38 | PHT1 = A2 - K1*RVAR*K1 39 | ENDIF 40 | IF(EVID.GT.2.AND.SDE.EQ.3) THEN 41 | AHT1 = A1 42 | PHT1 = 0 43 | ENDIF 44 | IF(EVID.GT.2.AND.SDE.EQ.4) THEN 45 | AHT1 = 0 46 | PHT1 = A2 47 | ENDIF 48 | IF(A_0FLG.EQ.1) THEN 49 | A_0(1) = AHT1 50 | A_0(2) = PHT1 51 | ENDIF 52 | $DES 53 | DADT(1) = - CL/VD*A(1) ;+0 54 | DADT(2) = (-CL/VD)*(A(2))+(-CL/VD)*(A(2))+SGW1*SGW1 55 | $ERROR (OBS ONLY) 56 | IPRED = A(1)/VD 57 | IRES = DV - IPRED 58 | W=SQRT(A(2)*(1/VD)**2+ THETA(3)**2) 59 | IWRES = IRES/W 60 | Y = IPRED+W*EPS(1) 61 | $EST MAXEVAL=9999 METHOD=1 LAPLACE NUMERICAL SLOW INTER NOABORT SIGDIGITS=3 PRINT=1 MSFO=sde7.msf 62 | $COV MATRIX=R 63 | 64 | $TABLE ID TIME FLAG AMT CMT IPRED IRES IWRES EVID APPEND ONEHEADER NOPRINT FILE=sde7.fit 65 | -------------------------------------------------------------------------------- /tests/written/sde8.ctl: -------------------------------------------------------------------------------- 1 | $PROBLEM PK ODE HANDS ON ONE 2 | $INPUT ID TIME DV AMT CMT FLAG MDV EVID SDE QA=XVID1 QB=XVID2 QZ=XVID3 3 | $DATA sde8.csv IGNORE=@ 4 | $SUBROUTINE ADVAN6 TOL 10 DP 5 | $MODEL 6 | COMP = (CENTRAL); 7 | COMP = (P1) 8 | $THETA (0, 10, ) ; 1 CL 9 | (0, 32, ) ; 2 VD 10 | (0, 2, ) ; 4 SIGMA 11 | (0, 1, ) ; SGW1 12 | $OMEGA 0.1 ; 1 CL 13 | $OMEGA 0.01 ; 2 VD 14 | $SIGMA 1 FIX ; PK 15 | $PK 16 | IF(NEWIND.NE.2) OT = 0 17 | TVCL = THETA(1) 18 | CL = TVCL*EXP(ETA(1)) 19 | TVVD = THETA(2) 20 | VD = TVVD*EXP(ETA(2)) 21 | SGW1 = THETA(4) 22 | IF(NEWIND.NE.2) THEN 23 | AHT1 = 0 24 | PHT1 = 0 25 | ENDIF 26 | IF(EVID.NE.3) THEN 27 | A1 = A(1) 28 | A2 = A(2) 29 | ELSE 30 | A1 = A1 31 | A2 = A2 32 | ENDIF 33 | IF(EVID.EQ.0) OBS = DV 34 | IF(EVID.GT.2.AND.SDE.EQ.2) THEN 35 | RVAR = A2*(1/VD)**2+ THETA(3)**2 36 | K1 = A2*(1/VD)/RVAR 37 | AHT1 = A1 + K1*(OBS -( A1/VD)) 38 | PHT1 = A2 - K1*RVAR*K1 39 | ENDIF 40 | IF(EVID.GT.2.AND.SDE.EQ.3) THEN 41 | AHT1 = A1 42 | PHT1 = 0 43 | ENDIF 44 | IF(EVID.GT.2.AND.SDE.EQ.4) THEN 45 | AHT1 = 0 46 | PHT1 = A2 47 | ENDIF 48 | IF(A_0FLG.EQ.1) THEN 49 | A_0(1) = AHT1 50 | A_0(2) = PHT1 51 | ENDIF 52 | $DES 53 | DADT(1) = - CL/VD*A(1) ;+0 54 | DADT(2) = (-CL/VD)*(A(2))+(-CL/VD)*(A(2))+SGW1*SGW1 55 | $ERROR (OBS ONLY) 56 | IPRED = A(1)/VD 57 | IRES = DV - IPRED 58 | W=SQRT(A(2)*(1/VD)**2+ THETA(3)**2) 59 | IWRES = IRES/W 60 | Y = IPRED+W*EPS(1) 61 | $EST MAXEVAL=9999 METHOD=1 LAPLACE NUMERICAL SLOW INTER NOABORT SIGDIGITS=3 PRINT=1 MSFO=sde8.msf 62 | $COV MATRIX=R 63 | 64 | $TABLE ID TIME FLAG AMT CMT IPRED IRES IWRES EVID APPEND ONEHEADER NOPRINT FILE=sde8.fit 65 | -------------------------------------------------------------------------------- /tests/originals/subprob1.mod: -------------------------------------------------------------------------------- 1 | $PROB COMPUTE PERCENTAGE OF POP. WITH CP>5 AT DOSE=200, TIME=5 2 | $INPUT ID TIME DOSE DV 3 | $DATA dataB 4 | $PRED 5 | IF (ICALL.EQ.0) THEN 6 | BIAS=0 ; initialize 7 | TRUE=0 8 | ENDIF 9 | IF (ICALL.EQ.1) THEN 10 | IF (IPROB.EQ.1.OR.IPROB.EQ.4) N=0 ; see rocm14 11 | CALL SUPP (1,1) 12 | ENDIF 13 | KA=THETA(1)*EXP(ETA(1)) 14 | KE=THETA(2)*EXP(ETA(2)) 15 | V=THETA(3)*EXP(ETA(3)) 16 | A=EXP(-KE*TIME) 17 | B=EXP(-KA*TIME) 18 | C=KA-KE 19 | D=A-B 20 | E=KA*DOSE/(V*C) 21 | F=E*D 22 | Y=F+ERR(1) 23 | IF (ICALL.EQ.4) THEN 24 | IF (IPROB.EQ.1.OR.IPROB.EQ.4) THEN 25 | IF (F.GT.5) N=N+1 26 | IF (IREP.EQ.NREP) THEN ; see rocm10 27 | PER=100.*N/NREP 28 | IF (IPROB.EQ.1) TRUE=PER 29 | IF (IPROB.EQ.4) THEN 30 | BIAS=BIAS+(PER-TRUE)/TRUE 31 | IF (S1IT.EQ.S1NIT) THEN 32 | BIAS=BIAS/S1NIT 33 | WRITE (42,*) BIAS 34 | ENDIF 35 | ENDIF 36 | ENDIF 37 | ENDIF 38 | ENDIF 39 | $THTA (.4,1.7,7) (.025,.102,.4) (10,29,80) 40 | $OMEGA .04 .04 .04 41 | $SIGMA 1.5 42 | $SIM (5566898) ONLY SUB=1000 43 | ; 44 | ; $SUPER SCOPE=3 ITERATIONS=10 45 | $PROB SIMULATION 46 | $INPUT ID TIME DOSE DV 47 | $DATA dataA 48 | $THTA (.4,1.7,7) (.025,.102,.4) (10,29,80) 49 | $OMEGA .04 .04 .04 50 | $SIGMA 1.5 51 | $SIM (-1) ONLY 52 | $TABLE ID DV TIME DOSE FILE=simulation NOHEADER NOPRINT NOFORWARD 53 | ; 54 | $PROB ESTIMATION 55 | $INPUT ID TIME DOSE DV 56 | $DATA simulation (4E12.0) NRECS=500 NOOPEN 57 | $THTA (.4,1.7,7) (.025,.102,.4) (10,29,80) 58 | $OMEGA .04 .04 .04 59 | $SIGMA 1.5 60 | $EST PRINT=0 MSFO=msf 61 | ; 62 | $PROB ESTIMATE PERCENTAGE OF POP. WITH CP>5 AT DOSE=200, TIME=5 63 | $INPUT ID TIME DOSE DV 64 | $DATA dataB 65 | $MSFI msf 66 | $SIM (-1) ONLY SUB=100 67 | -------------------------------------------------------------------------------- /R/sumo_PsN.R: -------------------------------------------------------------------------------- 1 | #' Use PsN to summarise NONMEM output 2 | #' 3 | #' @param command Explicit PsN command to be run at shell/DOS prompt. 4 | #' @param tool PsN tool name. To be used in conjunction with \code{"installPath"} 5 | #' and \code{"version"}. Defaults to "sumo". 6 | #' @param installPath Installation path for Perl / PsN. e.g. "c:/strawberry/perl" 7 | #' @param version Version of PsN as a character string. e.g. "4.6.0" 8 | #' @param lstFile NONMEM output file name 9 | #' @param psnOpts List of additional PsN command line arguments 10 | #' (format: argumentName = value or argumentName=TRUE/FALSE ) 11 | #' @param working.dir Working directory containing control stream and where 12 | #' output files should be stored 13 | #' @details Either specify an explicit command to run at the system prompt 14 | #' or specify a combination of tool, installPath and version. 15 | #' @return PsN sumo output 16 | #' @examples 17 | #' sumo_PsN(modelFile='warfarin_PK_CONC_MKS.ctl', working.dir='./data') 18 | #' @export 19 | 20 | sumo_PsN <- function(command = NULL, 21 | tool = "sumo", 22 | installPath = NULL, 23 | version = NULL, 24 | lstFile = NULL, 25 | psnOpts = NULL, 26 | working.dir = NULL) { 27 | 28 | if (!is.null(working.dir)) { 29 | psnOpts <- c(list(directory = working.dir), 30 | psnOpts) 31 | } 32 | 33 | callPsN(command = command, 34 | tool = "sumo", 35 | installPath = installPath, 36 | version = version, 37 | file = lstFile, 38 | psnOpts = psnOpts) 39 | } 40 | -------------------------------------------------------------------------------- /tests/written/subprob1.mod: -------------------------------------------------------------------------------- 1 | $PROB COMPUTE PERCENTAGE OF POP. WITH CP>5 AT DOSE=200, TIME=5 2 | $INPUT ID TIME DOSE DV 3 | $DATA 'dataB' 4 | $PRED 5 | IF (ICALL.EQ.0) THEN 6 | BIAS=0 ; initialize 7 | TRUE=0 8 | ENDIF 9 | IF (ICALL.EQ.1) THEN 10 | IF (IPROB.EQ.1.OR.IPROB.EQ.4) N=0 ; see rocm14 11 | CALL SUPP (1,1) 12 | ENDIF 13 | KA=THETA(1)*EXP(ETA(1)) 14 | KE=THETA(2)*EXP(ETA(2)) 15 | V=THETA(3)*EXP(ETA(3)) 16 | A=EXP(-KE*TIME) 17 | B=EXP(-KA*TIME) 18 | C=KA-KE 19 | D=A-B 20 | E=KA*DOSE/(V*C) 21 | F=E*D 22 | Y=F+ERR(1) 23 | IF (ICALL.EQ.4) THEN 24 | IF (IPROB.EQ.1.OR.IPROB.EQ.4) THEN 25 | IF (F.GT.5) N=N+1 26 | IF (IREP.EQ.NREP) THEN ; see rocm10 27 | PER=100.*N/NREP 28 | IF (IPROB.EQ.1) TRUE=PER 29 | IF (IPROB.EQ.4) THEN 30 | BIAS=BIAS+(PER-TRUE)/TRUE 31 | IF (S1IT.EQ.S1NIT) THEN 32 | BIAS=BIAS/S1NIT 33 | WRITE (42,*) BIAS 34 | ENDIF 35 | ENDIF 36 | ENDIF 37 | ENDIF 38 | ENDIF 39 | $THTA (0.4, 1.7, 7) 40 | (0.025, 0.102, 0.4) 41 | (10, 29, 80) 42 | $OMEGA 0.04 43 | 0.04 44 | 0.04 45 | $SIGMA 1.5 46 | $SIM (5566898) SUBPROBLEMS= 1000 ONLYSIMULATION 47 | $PROB SIMULATION 48 | $INPUT ID TIME DOSE DV 49 | $DATA 'dataA' 50 | $THTA (0.4, 1.7, 7) 51 | (0.025, 0.102, 0.4) 52 | (10, 29, 80) 53 | $OMEGA 0.04 54 | 0.04 55 | 0.04 56 | $SIGMA 1.5 57 | $SIM ONLYSIMULATION 58 | $TABLE ID DV TIME DOSE APPEND NOHEADER NOPRINT FILE=simulation 59 | $PROB ESTIMATION 60 | $INPUT ID TIME DOSE DV 61 | $DATA 'simulation' 62 | $THTA (0.4, 1.7, 7) 63 | (0.025, 0.102, 0.4) 64 | (10, 29, 80) 65 | $OMEGA 0.04 66 | 0.04 67 | 0.04 68 | $SIGMA 1.5 69 | $EST PRINT=0 MSFO=msf 70 | $PROB ESTIMATE PERCENTAGE OF POP. WITH CP>5 AT DOSE=200, TIME=5 71 | $INPUT ID TIME DOSE DV 72 | $DATA 'dataB' 73 | 74 | $SIM SUBPROBLEMS= 100 ONLYSIMULATION 75 | -------------------------------------------------------------------------------- /tests/written/sde10.ctl: -------------------------------------------------------------------------------- 1 | $PROBLEM PK ODE HANDS ON ONE 2 | $INPUT ID HOUR DV AMT CMT FLAG EVID MDV SDE TIME 3 | $DATA sde7.csv IGNORE=@ 4 | $SUBROUTINE ADVAN6 TOL 10 DP 5 | $MODEL 6 | COMP = (CENTRAL); 7 | COMP = (P1) 8 | $THETA (0, 2.3, ) ; 1 CL 9 | (0, 3.5, ) ; 2 VD 10 | (0, 2, ) ; 4 SIGMA 11 | (0, 1, ) ; SGW1 12 | $OMEGA 0.1 ; 1 CL 13 | $OMEGA 0.01 ; 2 VD 14 | $SIGMA 1 FIX ; PK 15 | $PK 16 | IF(NEWIND.NE.2) OT = 0 17 | MU_1 = THETA(1) 18 | CL = EXP(MU_1+ETA(1)) 19 | MU_2 = THETA(2) 20 | VD = EXP(MU_2+ETA(2)) 21 | SGW1 = THETA(4) 22 | IF(NEWIND.NE.2) THEN 23 | AHT1 = 0 24 | PHT1 = 0 25 | ENDIF 26 | IF(EVID.NE.3) THEN 27 | A1 = A(1) 28 | A2 = A(2) 29 | ELSE 30 | A1 = A1 31 | A2 = A2 32 | ENDIF 33 | IF(EVID.EQ.0) OBS = DV 34 | IF(EVID.GT.2.AND.SDE.EQ.2) THEN 35 | RVAR = A2*(1/VD)**2+ THETA(3)**2 36 | K1 = A2*(1/VD)/RVAR 37 | AHT1 = A1 + K1*(OBS -( A1/VD)) 38 | PHT1 = A2 - K1*RVAR*K1 39 | ENDIF 40 | IF(EVID.GT.2.AND.SDE.EQ.3) THEN 41 | AHT1 = A1 42 | PHT1 = 0 43 | ENDIF 44 | IF(EVID.GT.2.AND.SDE.EQ.4) THEN 45 | AHT1 = 0 46 | PHT1 = A2 47 | ENDIF 48 | IF(A_0FLG.EQ.1) THEN 49 | A_0(1) = AHT1 50 | A_0(2) = PHT1 51 | ENDIF 52 | $DES 53 | DADT(1) = - CL/VD*A(1) ;+0 54 | DADT(2) = (-CL/VD)*(A(2))+(-CL/VD)*(A(2))+SGW1*SGW1 55 | $ERROR (OBS ONLY) 56 | IPRED = A(1)/VD 57 | IRES = DV - IPRED 58 | W=SQRT(ABS(A(2))*(1/VD)**2+ THETA(3)**2) 59 | IWRES = IRES/W 60 | Y = IPRED+W*EPS(1) 61 | $EST METHOD=ITS INTERACTION LAPLACE NUMERICAL SLOW NOABORT PRINT=1 CTYPE=3 62 | $EST METHOD=IMP INTERACTION NOABORT SIGL=5 PRINT=1 IACCEPT=1.0 CTYPE=3 63 | $EST MAXEVAL=9999 METHOD=1 LAPLACE INTER NOABORT NUMERICAL SLOW NSIG=3 PRINT=1 MSFO=sde10.msf 64 | $COV MATRIX=R 65 | 66 | $TABLE ID TIME FLAG AMT CMT IPRED IRES IWRES EVID APPEND ONEHEADER NOPRINT FILE=sde10.fit 67 | -------------------------------------------------------------------------------- /inst/exdata/warfarin.ctl: -------------------------------------------------------------------------------- 1 | ;O'Reilly RA, Aggeler PM, Leong LS. Studies of the coumarin anticoagulant 2 | ;drugs: The pharmacodynamics of warfarin in man. 3 | ;Journal of Clinical Investigation 1963;42(10):1542-1551 4 | ;O'Reilly RA, Aggeler PM. Studies on coumarin anticoagulant drugs 5 | ;Initiation of warfarin therapy without a loading dose. 6 | ;Circulation 1968;38:169-177 7 | 8 | $PROB WARFARIN PK 9 | $INPUT 10 | ID TIME WT AGE SEX AMT DVID DV MDV 11 | 12 | $DATA warfarin_conc_pca.csv 13 | IGNORE=# 14 | IGNORE (DVID.EQ.2) 15 | 16 | 17 | $SUBR 18 | ADVAN2 TRANS2 19 | 20 | 21 | $PK 22 | GRPCL = THETA(1)*(WT/70)**0.75 23 | GRPV = THETA(2)*WT/70 24 | GRPKA = THETA(3) 25 | GRPLG = THETA(4) 26 | CL = GRPCL*EXP(ETA(1)) 27 | V = GRPV*EXP(ETA(2)) 28 | KA = GRPKA*EXP(ETA(3)) 29 | ALAG1 = GRPLG*EXP(ETA(4)) 30 | S2 = V 31 | 32 | $ERROR (ONLY OBSERVATIONS) 33 | CENTRAL = F 34 | CC = (CENTRAL/V) 35 | IPRED = CC 36 | 37 | W = THETA(5)+THETA(6)*CC 38 | Y = CC + W*EPS(1) 39 | IRES = DV - IPRED 40 | IWRES = IRES/W 41 | 42 | IF (ICALL.EQ.4) THEN 43 | IF (F.GT.0) THEN 44 | Y = CC 45 | ELSE 46 | Y = 0 47 | ENDIF 48 | ENDIF 49 | 50 | $THETA 51 | (0.001, 0.1, ) ; POP_CL 52 | (0.001, 8, ) ; POP_V 53 | (0.001, 2, ) ; POP_KA 54 | 0.25 FIX ; POP_TLAG 55 | 56 | (0, 0.01) ; RUV_ADD 57 | (0, 0.05) ; RUV_PROP 58 | 59 | $OMEGA BLOCK (2) 60 | 0.1 ; PPV_CL 61 | 0.01 0.1 ; PPV_V 62 | 63 | $OMEGA 64 | 0.1 ; PPV_KA 65 | 0 FIX ; PPV_TLAG 66 | 67 | $SIGMA 68 | 1.0 FIX 69 | 70 | $EST METHOD=COND INTER 71 | MAX=9990 SIG=3 NOABORT ;PRINT=1 72 | $COV 73 | 74 | $TABLE ID TIME IPRED IRES RES PRED WRES NOPRINT ONEHEADER FILE=sdtab0 75 | $TABLE ID CL V KA ALAG1 ETA(1) ETA(2) ETA(3) ETA(4) NOPRINT NOAPPEND ONEHEADER FILE=patab0 76 | $TABLE ID AGE WT NOPRINT NOAPPEND ONEHEADER FILE=cotab0 77 | $TABLE ID SEX NOPRINT NOAPPEND ONEHEADER FILE=catab0 78 | -------------------------------------------------------------------------------- /R/bootstrap_PsN.R: -------------------------------------------------------------------------------- 1 | #' Performs PsN bootstrap for a given control file and dataset 2 | #' 3 | #' @param command Explicit PsN command to be run at shell/DOS prompt. 4 | #' @param tool PsN tool name. To be used in conjunction with \code{"installPath"} 5 | #' and \code{"version"}. Defaults to "bootstrap". 6 | #' @param installPath Installation path for Perl / PsN. e.g. "c:/strawberry/perl" 7 | #' @param version Version of PsN as a character string. e.g. "4.6.0" 8 | #' @param modelFile NONMEM control stream file name (without extension) 9 | #' @param psnOpts List of additional PsN command line arguments 10 | #' (format: argumentName = value or argumentName=TRUE/FALSE ) 11 | #' @param clean Clean up working directory following completion. PsN option. 12 | #' Default = 1. 13 | #' @param working.dir Working directory containing control stream and where 14 | #' output files should be stored 15 | #' @return PsN SSE output 16 | #' @examples 17 | #' @export 18 | 19 | bootstrap_PsN <- function(command = NULL, 20 | tool = "bootstrap", 21 | installPath = NULL, 22 | version = NULL, 23 | modelFile = NULL, 24 | psnOpts = NULL, 25 | clean = 1, 26 | working.dir = NULL) { 27 | 28 | if (!is.null(working.dir)) { 29 | psnOpts <- c(list(directory = working.dir), 30 | psnOpts) 31 | } 32 | 33 | if (clean != 1) { 34 | psnOpts <- c(list(clean = clean), 35 | psnOpts) 36 | } 37 | 38 | callPsN(command = command, 39 | tool = "bootstrap", 40 | installPath = installPath, 41 | version = version, 42 | file = modelFile, 43 | psnOpts = psnOpts) 44 | } 45 | 46 | -------------------------------------------------------------------------------- /tests/originals/sde7.ctl: -------------------------------------------------------------------------------- 1 | $PROBLEM PK ODE HANDS ON ONE 2 | $INPUT ID HOUR DV AMT CMT FLAG EVID MDV SDE TIME 3 | $DATA sde7.csv 4 | IGNORE=@ 5 | $SUBROUTINE ADVAN6 TOL 10 DP 6 | $MODEL 7 | COMP = (CENTRAL); 8 | COMP = (P1) 9 | 10 | $THETA (0,10) ;1 CL 11 | $THETA (0,32) ;2 VD 12 | $THETA (0, 2) ;4 SIGMA 13 | $THETA (0,1) ; SGW1 14 | 15 | $OMEGA 0.1 ;1 CL 16 | $OMEGA 0.01 ;2 VD 17 | 18 | $SIGMA 1 FIX ; PK 19 | 20 | $PK 21 | IF(NEWIND.NE.2) OT = 0 22 | TVCL = THETA(1) 23 | CL = TVCL*EXP(ETA(1)) 24 | TVVD = THETA(2) 25 | VD = TVVD*EXP(ETA(2)) 26 | SGW1 = THETA(4) 27 | 28 | IF(NEWIND.NE.2) THEN 29 | AHT1 = 0 30 | PHT1 = 0 31 | ENDIF 32 | 33 | IF(EVID.NE.3) THEN 34 | A1 = A(1) 35 | A2 = A(2) 36 | ELSE 37 | A1 = A1 38 | A2 = A2 39 | ENDIF 40 | 41 | IF(EVID.EQ.0) OBS = DV 42 | 43 | IF(EVID.GT.2.AND.SDE.EQ.2) THEN 44 | RVAR = A2*(1/VD)**2+ THETA(3)**2 45 | K1 = A2*(1/VD)/RVAR 46 | AHT1 = A1 + K1*(OBS -( A1/VD)) 47 | PHT1 = A2 - K1*RVAR*K1 48 | ENDIF 49 | 50 | IF(EVID.GT.2.AND.SDE.EQ.3) THEN 51 | AHT1 = A1 52 | PHT1 = 0 53 | ENDIF 54 | 55 | IF(EVID.GT.2.AND.SDE.EQ.4) THEN 56 | AHT1 = 0 57 | PHT1 = A2 58 | ENDIF 59 | 60 | IF(A_0FLG.EQ.1) THEN 61 | A_0(1) = AHT1 62 | A_0(2) = PHT1 63 | ENDIF 64 | 65 | $DES 66 | DADT(1) = - CL/VD*A(1) ;+0 67 | DADT(2) = (-CL/VD)*(A(2))+(-CL/VD)*(A(2))+SGW1*SGW1 68 | 69 | $ERROR (OBS ONLY) 70 | IPRED = A(1)/VD 71 | IRES = DV - IPRED 72 | W=SQRT(A(2)*(1/VD)**2+ THETA(3)**2) 73 | IWRES = IRES/W 74 | Y = IPRED+W*EPS(1) 75 | 76 | $EST MAXEVAL=9999 METHOD=1 LAPLACE NUMERICAL SLOW INTER NOABORT SIGDIGITS=3 PRINT=1 MSFO=sde7.msf 77 | $COV MATRIX=R 78 | $TABLE ID TIME FLAG AMT CMT IPRED IRES IWRES EVID 79 | ONEHEADER NOPRINT FILE=sde7.fit 80 | -------------------------------------------------------------------------------- /tests/originals/sde8.ctl: -------------------------------------------------------------------------------- 1 | $PROBLEM PK ODE HANDS ON ONE 2 | $INPUT ID TIME DV AMT CMT FLAG MDV EVID SDE QA=XVID1 QB=XVID2 QZ=XVID3 3 | $DATA sde8.csv 4 | IGNORE=@ 5 | $SUBROUTINE ADVAN6 TOL 10 DP 6 | $MODEL 7 | COMP = (CENTRAL); 8 | COMP = (P1) 9 | 10 | $THETA (0,10) ;1 CL 11 | $THETA (0,32) ;2 VD 12 | $THETA (0, 2) ;4 SIGMA 13 | $THETA (0,1) ; SGW1 14 | 15 | $OMEGA 0.1 ;1 CL 16 | $OMEGA 0.01 ;2 VD 17 | 18 | $SIGMA 1 FIX ; PK 19 | 20 | $PK 21 | IF(NEWIND.NE.2) OT = 0 22 | TVCL = THETA(1) 23 | CL = TVCL*EXP(ETA(1)) 24 | TVVD = THETA(2) 25 | VD = TVVD*EXP(ETA(2)) 26 | SGW1 = THETA(4) 27 | 28 | IF(NEWIND.NE.2) THEN 29 | AHT1 = 0 30 | PHT1 = 0 31 | ENDIF 32 | 33 | IF(EVID.NE.3) THEN 34 | A1 = A(1) 35 | A2 = A(2) 36 | ELSE 37 | A1 = A1 38 | A2 = A2 39 | ENDIF 40 | 41 | IF(EVID.EQ.0) OBS = DV 42 | 43 | IF(EVID.GT.2.AND.SDE.EQ.2) THEN 44 | RVAR = A2*(1/VD)**2+ THETA(3)**2 45 | K1 = A2*(1/VD)/RVAR 46 | AHT1 = A1 + K1*(OBS -( A1/VD)) 47 | PHT1 = A2 - K1*RVAR*K1 48 | ENDIF 49 | 50 | IF(EVID.GT.2.AND.SDE.EQ.3) THEN 51 | AHT1 = A1 52 | PHT1 = 0 53 | ENDIF 54 | 55 | IF(EVID.GT.2.AND.SDE.EQ.4) THEN 56 | AHT1 = 0 57 | PHT1 = A2 58 | ENDIF 59 | 60 | IF(A_0FLG.EQ.1) THEN 61 | A_0(1) = AHT1 62 | A_0(2) = PHT1 63 | ENDIF 64 | 65 | $DES 66 | DADT(1) = - CL/VD*A(1) ;+0 67 | DADT(2) = (-CL/VD)*(A(2))+(-CL/VD)*(A(2))+SGW1*SGW1 68 | 69 | $ERROR (OBS ONLY) 70 | IPRED = A(1)/VD 71 | IRES = DV - IPRED 72 | W=SQRT(A(2)*(1/VD)**2+ THETA(3)**2) 73 | IWRES = IRES/W 74 | Y = IPRED+W*EPS(1) 75 | $EST MAXEVAL=9999 METHOD=1 LAPLACE NUMERICAL SLOW INTER NOABORT SIGDIGITS=3 PRINT=1 MSFO=sde8.msf 76 | $COV MATRIX=R 77 | $TABLE ID TIME FLAG AMT CMT IPRED IRES IWRES EVID 78 | ONEHEADER NOPRINT FILE=sde8.fit 79 | -------------------------------------------------------------------------------- /tests/written/moxonidine.mod: -------------------------------------------------------------------------------- 1 | $PROBLEM run1.mod run1.ctl MOXONIDINE PK ANALYSIS 2 | $INPUT ID PAT=DROP VISI XAT2=DROP DGRP=DROP DOSE=DROP FLAG=DROP ONO=DROP XIME=DROP DVO=DROP NEUY=DROP SCR=DROP AGE SEX NYHA=DROP WT COMP ACE DIG DIU NUMB=DROP TAD TIME VIDD=DROP CLCR AMT SS II VID CMT=DROP CONO=DROP DV EVID=DROP OVID=DROP RGRP 3 | $DATA mx2007.csv IGNORE=@ 4 | $SUBROUTINE ADVAN2 TRANS1 5 | $PK 6 | ;-----------OCCASIONS---------- 7 | VIS3 = 0 8 | IF(VISI.EQ.3) VIS3 = 1 9 | VIS8 = 0 10 | IF(VISI.EQ.8) VIS8 = 1 11 | ;----------IOV-------------------- 12 | KPCL = VIS3*ETA(4)+VIS8*ETA(5) 13 | KPKA = VIS3*ETA(6)+VIS8*ETA(7) 14 | ;---------- PK model ------------------ 15 | TVCL = THETA(1)*(1+THETA(7)*(CLCR-65)) 16 | TVV = THETA(2)*WT 17 | TVKA = THETA(3) 18 | CL = TVCL*EXP(ETA(1)+KPCL) 19 | V = TVV*EXP(ETA(2)) 20 | KA = TVKA*EXP(ETA(3)+KPKA) 21 | ALAG1 = THETA(4) 22 | K = CL/V 23 | S2 = V 24 | $ERROR 25 | IPRED = LOG(.025) 26 | IF(F.GT.0) IPRED = LOG(F) 27 | W = (THETA(6) + THETA(5)/IPRED) ;* EXP(ETA(8)) 28 | IRES = IPRED-DV 29 | IWRES = IRES/W 30 | Y = IPRED+EPS(1)*W 31 | $THETA (0, 27.1, ) ; 1 32 | (0, 1.49, ) ; This is in L per kg WT 33 | (0, 3.52, ) ; 3 34 | (0, 0.227, ) ; 4 35 | 0 FIX ; 5 36 | (0, 0.343, ) ; 6 37 | (0, 0.00646, 0.02941) ; 7 38 | $OMEGA BLOCK(2) 0.0489 ; 1 39 | 0.0256 0.0156 ; 2 40 | 41 | $OMEGA BLOCK(1) 1.98 ; 1 42 | 43 | $OMEGA BLOCK(1) 0.013 ; 1 44 | 45 | $OMEGA BLOCK(1) SAME 46 | 47 | $OMEGA BLOCK(1) 0.0481 ; 1 48 | 49 | $OMEGA BLOCK(1) SAME 50 | 51 | $SIGMA 1 FIX ; 1 52 | $ESTIMATION METHOD=1 MAXEVALS=9999 PRINT=1 MSFO=msf1 53 | $TAB ID TAD IPRED IWRES CWRES APPEND ONEHEADER NOPRINT FILE=sdtab1 54 | $TAB ID ETA1 ETA2 ETA3 ETA4 ETA5 ETA6 ETA7 NOAPPEND ONEHEADER NOPRINT FILE=patab1 55 | $TAB ID AGE WT CLCR NOAPPEND ONEHEADER NOPRINT FILE=cotab1 56 | $TAB ID SEX ACE DIG DIU COMP VISI NOAPPEND ONEHEADER NOPRINT FILE=catab1 57 | -------------------------------------------------------------------------------- /R/updateModel.R: -------------------------------------------------------------------------------- 1 | #' Change elements of the Model based on inputs 2 | #' 3 | #' @param parsedObject R object containing parsed NONMEM objects 4 | #' @param problem $Problem (NONMEM $PROB) list within the R Model Object 5 | #' @param theta $Theta list (NONEMM $THETA) within the R Model Object 6 | #' @param omega $Omega list (NONMEM $OMEGA) within the R Model Object 7 | #' @param sigma $Sigma list (NONMEM $SIGMA) within the R Model Object 8 | #' @param task $Estimates list (NONMEM $EST, $SIM) within the R Model Object 9 | #' @param data $Data list (NONMEM $DATA) within the R Model Object 10 | #' @param dataNames $Input list (NONMEM $INPUT) within the R Model Object 11 | #' @param tables $Tables list (NONMEM $TABLES) within the R Model Object 12 | #' @param addPsNHeader Logical - whether to include PsN Header information. 13 | #' Default FALSE. 14 | #' @return NONMEM estimation output files 15 | #' @examples 16 | #' @export 17 | 18 | updateModel <- function(parsedObject, problem = parsedObject$Problem, 19 | theta = parsedObject$Theta, omega = parsedObject$Omega, 20 | sigma = parsedObject$Sigma, task = parsedObject$Estimates, 21 | data = parsedObject$Data, dataNames = parsedObject$Input, 22 | tables = parsedObject$Tables, 23 | addPsNHeader = F, runno = 0, ...) { 24 | newObject <- parsedObject 25 | newObject$Problem <- problem 26 | newObject$Theta <- theta 27 | newObject$Omega <- omega 28 | newObject$Sigma <- sigma 29 | newObject$Estimates <- task 30 | newObject$Data <- data 31 | newObject$Input <- dataNames 32 | newObject$Tables <- tables 33 | 34 | newObject$Tables$File <- gsub("[0:9]", runno, parsedObject$Tables$File) 35 | 36 | if (addPsNHeader) 37 | newObject$Problem <- PsNHeader(parsedObject, ...) 38 | return(newObject) 39 | } 40 | -------------------------------------------------------------------------------- /R/execute_PsN.R: -------------------------------------------------------------------------------- 1 | #' Estimates parameters using PsN execute 2 | #' 3 | #' @param command Explicit PsN command to be run at shell/DOS prompt. 4 | #' @param tool PsN tool name. To be used in conjunction with \code{"installPath"} 5 | #' and \code{"version"}. Defaults to "execute". 6 | #' @param installPath Installation path for Perl / PsN. e.g. "c:/strawberry/perl" 7 | #' @param version Version of PsN as a character string. e.g. "4.6.0" 8 | #' @param modelFile NONMEM control stream file name (without extension) 9 | #' @param psnOpts List of additional PsN command line arguments 10 | #' (format: argumentName = value or argumentName=TRUE/FALSE ) 11 | #' @param clean Whether to clean up additional NONMEM files and folders 12 | #' following PsN call. PsN option. Default = 1. 13 | #' @param working.dir Working directory containing control stream and where 14 | #' output files should be stored 15 | #' @return NONMEM estimation output files 16 | #' @examples 17 | #' execute_PsN(modelFile='warfarin_PK_CONC_MKS.ctl', working.dir='./data') 18 | #' @export 19 | #' 20 | execute_PsN <- function(command = NULL, 21 | tool = "execute", 22 | installPath = NULL, 23 | version = NULL, 24 | modelFile = NULL, 25 | psnOpts = NULL, 26 | clean = 1, 27 | working.dir = NULL, ...) { 28 | 29 | if (!is.null(working.dir)) { 30 | psnOpts <- c(list(directory = working.dir), 31 | psnOpts) 32 | } 33 | 34 | if (clean != 1) { 35 | psnOpts <- c(list(clean = clean), 36 | psnOpts) 37 | } 38 | 39 | 40 | callPsN(command = command, 41 | tool = "execute", 42 | installPath = installPath, 43 | version = version, 44 | file = modelFile, 45 | psnOpts = psnOpts) 46 | } 47 | -------------------------------------------------------------------------------- /tests/originals/warfarin.ctl: -------------------------------------------------------------------------------- 1 | ;generated by MDL2NMTRAN v.5.1.4 2 | 3 | 4 | 5 | $PROB WARFARIN PK 6 | ;O'Reilly RA, Aggeler PM, Leong LS. Studies of the coumarin anticoagulant 7 | ;drugs: The pharmacodynamics of warfarin in man. 8 | ;Journal of Clinical Investigation 1963;42(10):1542-1551 9 | ;O'Reilly RA, Aggeler PM. Studies on coumarin anticoagulant drugs 10 | ;Initiation of warfarin therapy without a loading dose. 11 | ;Circulation 1968;38:169-177 12 | 13 | $INPUT 14 | ID TIME WT AGE SEX AMT DVID DV MDV 15 | 16 | $DATA warfarin_conc_pca.csv 17 | IGNORE=# 18 | IGNORE (DVID.EQ.2) 19 | 20 | 21 | $SUBR 22 | ADVAN2 TRANS2 23 | 24 | 25 | $PK 26 | GRPCL = THETA(1)*(WT/70)**0.75 27 | GRPV = THETA(2)*WT/70 28 | GRPKA = THETA(3) 29 | GRPLG = THETA(4) 30 | CL = GRPCL*EXP(ETA(1)) 31 | V = GRPV*EXP(ETA(2)) 32 | KA = GRPKA*EXP(ETA(3)) 33 | ALAG1 = GRPLG*EXP(ETA(4)) 34 | S2 = V 35 | 36 | $ERROR 37 | CONC = A(2)/V 38 | 39 | IPRED=F 40 | IF(F.GT.0) IPRED=F 41 | 42 | IRES = DV - IPRED 43 | 44 | W = THETA(5)+THETA(6)*CONC 45 | Y = IPRED + W*EPS(1) 46 | 47 | $THETA 48 | (0.001, 0.1, INF) ; POP_CL 49 | (0.001, 8, INF) ; POP_V 50 | (0.001, 2, INF) ; POP_KA 51 | 0.25 FIX ; POP_TLAG 52 | 53 | 0 FIX ; RUV_ADD 54 | (0.05) ; RUV_PROP 55 | 56 | $OMEGA BLOCK (2) 57 | 0.1 ; PPV_CL 58 | 0.01 0.1 ; PPV_V 59 | 60 | $OMEGA 61 | 0.1 ; PPV_KA 62 | 0 FIX ; PPV_TLAG 63 | 64 | $SIGMA 65 | 1.0 FIX 66 | 67 | $EST METHOD=COND INTER 68 | MAX=9990 SIG=3 NOABORT ;PRINT=1 69 | $COV 70 | 71 | ;$TABLE 72 | ;ID TIME WT SEX AGE CL V KA ALAG1 DVID Y 73 | ;ONEHEADER NOPRINT FILE=warfarin_PK_CONC_task.fit 74 | 75 | ; Changed Table file statements to conform to Xpose expected input 76 | $TABLE ID TIME IPRED IRES RES PRED WRES NOPRINT ONEHEADER FILE=sdtab0 77 | $TABLE ID CL V KA ALAG1 ETA(1) ETA(2) ETA(3) ETA(4) NOPRINT NOAPPEND ONEHEADER FILE=patab0 78 | $TABLE ID AGE WT NOPRINT NOAPPEND ONEHEADER FILE=cotab0 79 | $TABLE ID SEX NOPRINT NOAPPEND ONEHEADER FILE=catab0 80 | -------------------------------------------------------------------------------- /tests/originals/warfarin_boot.ctl: -------------------------------------------------------------------------------- 1 | ;generated by MDL2NMTRAN v.5.1.4 2 | 3 | 4 | 5 | $PROB WARFARIN PK 6 | ;O'Reilly RA, Aggeler PM, Leong LS. Studies of the coumarin anticoagulant 7 | ;drugs: The pharmacodynamics of warfarin in man. 8 | ;Journal of Clinical Investigation 1963;42(10):1542-1551 9 | ;O'Reilly RA, Aggeler PM. Studies on coumarin anticoagulant drugs 10 | ;Initiation of warfarin therapy without a loading dose. 11 | ;Circulation 1968;38:169-177 12 | 13 | $INPUT 14 | ID TIME WT AGE SEX AMT DVID DV MDV 15 | 16 | $DATA warfarin_boot50.dta 17 | IGNORE=# 18 | IGNORE (DVID.EQ.2) 19 | 20 | 21 | $SUBR 22 | ADVAN2 TRANS2 23 | 24 | 25 | $PK 26 | GRPCL = THETA(1)*(WT/70)**0.75 27 | GRPV = THETA(2)*WT/70 28 | GRPKA = THETA(3) 29 | GRPLG = THETA(4) 30 | CL = GRPCL*EXP(ETA(1)) 31 | V = GRPV*EXP(ETA(2)) 32 | KA = GRPKA*EXP(ETA(3)) 33 | ALAG1 = GRPLG*EXP(ETA(4)) 34 | S2 = V 35 | 36 | $ERROR 37 | CONC = A(2)/V 38 | 39 | IPRED=F 40 | IF(F.GT.0) IPRED=F 41 | 42 | IRES = DV - IPRED 43 | 44 | W = THETA(5)+THETA(6)*CONC 45 | Y = IPRED + W*EPS(1) 46 | 47 | $THETA 48 | (0.001, 0.1, INF) ; POP_CL 49 | (0.001, 8, INF) ; POP_V 50 | (0.001, 2, INF) ; POP_KA 51 | 0.25 FIX ; POP_TLAG 52 | 53 | 0 FIX ; RUV_ADD 54 | (0.05) ; RUV_PROP 55 | 56 | $OMEGA BLOCK (2) 57 | 0.1 ; PPV_CL 58 | 0.01 0.1 ; PPV_V 59 | 60 | $OMEGA 61 | 0.1 ; PPV_KA 62 | 0 FIX ; PPV_TLAG 63 | 64 | $SIGMA 65 | 1.0 FIX 66 | 67 | $EST METHOD=COND INTER 68 | MAX=9990 SIG=3 NOABORT ;PRINT=1 69 | $COV 70 | 71 | ;$TABLE 72 | ;ID TIME WT SEX AGE CL V KA ALAG1 DVID Y 73 | ;ONEHEADER NOPRINT FILE=warfarin_PK_CONC_task.fit 74 | 75 | ; Changed Table file statements to conform to Xpose expected input 76 | $TABLE ID TIME IPRED IRES RES PRED WRES NOPRINT ONEHEADER FILE=sdtab0 77 | $TABLE ID CL V KA ALAG1 ETA(1) ETA(2) ETA(3) ETA(4) NOPRINT NOAPPEND ONEHEADER FILE=patab0 78 | $TABLE ID AGE WT NOPRINT NOAPPEND ONEHEADER FILE=cotab0 79 | $TABLE ID SEX NOPRINT NOAPPEND ONEHEADER FILE=catab0 80 | -------------------------------------------------------------------------------- /tests/originals/sde10.ctl: -------------------------------------------------------------------------------- 1 | $PROBLEM PK ODE HANDS ON ONE 2 | $INPUT ID HOUR DV AMT CMT FLAG EVID MDV SDE TIME 3 | $DATA sde7.csv 4 | IGNORE=@ 5 | $SUBROUTINE ADVAN6 TOL 10 DP 6 | $MODEL 7 | COMP = (CENTRAL); 8 | COMP = (P1) 9 | 10 | $THETA (0,2.3) ;1 CL 11 | $THETA (0,3.5) ;2 VD 12 | $THETA (0, 2) ;4 SIGMA 13 | $THETA (0,1) ; SGW1 14 | 15 | $OMEGA 0.1 ;1 CL 16 | $OMEGA 0.01 ;2 VD 17 | 18 | $SIGMA 1 FIX ; PK 19 | 20 | $PK 21 | IF(NEWIND.NE.2) OT = 0 22 | 23 | MU_1 = THETA(1) 24 | CL = EXP(MU_1+ETA(1)) 25 | MU_2 = THETA(2) 26 | VD = EXP(MU_2+ETA(2)) 27 | SGW1 = THETA(4) 28 | 29 | IF(NEWIND.NE.2) THEN 30 | AHT1 = 0 31 | PHT1 = 0 32 | ENDIF 33 | 34 | IF(EVID.NE.3) THEN 35 | A1 = A(1) 36 | A2 = A(2) 37 | ELSE 38 | A1 = A1 39 | A2 = A2 40 | ENDIF 41 | 42 | IF(EVID.EQ.0) OBS = DV 43 | 44 | IF(EVID.GT.2.AND.SDE.EQ.2) THEN 45 | RVAR = A2*(1/VD)**2+ THETA(3)**2 46 | K1 = A2*(1/VD)/RVAR 47 | AHT1 = A1 + K1*(OBS -( A1/VD)) 48 | PHT1 = A2 - K1*RVAR*K1 49 | ENDIF 50 | 51 | IF(EVID.GT.2.AND.SDE.EQ.3) THEN 52 | AHT1 = A1 53 | PHT1 = 0 54 | ENDIF 55 | 56 | IF(EVID.GT.2.AND.SDE.EQ.4) THEN 57 | AHT1 = 0 58 | PHT1 = A2 59 | ENDIF 60 | 61 | IF(A_0FLG.EQ.1) THEN 62 | A_0(1) = AHT1 63 | A_0(2) = PHT1 64 | ENDIF 65 | 66 | $DES 67 | DADT(1) = - CL/VD*A(1) ;+0 68 | DADT(2) = (-CL/VD)*(A(2))+(-CL/VD)*(A(2))+SGW1*SGW1 69 | 70 | $ERROR (OBS ONLY) 71 | IPRED = A(1)/VD 72 | IRES = DV - IPRED 73 | W=SQRT(ABS(A(2))*(1/VD)**2+ THETA(3)**2) 74 | IWRES = IRES/W 75 | Y = IPRED+W*EPS(1) 76 | 77 | $EST METHOD=ITS INTERACTION LAPLACE NUMERICAL SLOW NOABORT PRINT=1 CTYPE=3 78 | $EST METHOD=IMP INTERACTION NOABORT SIGL=5 PRINT=1 IACCEPT=1.0 CTYPE=3 79 | $EST MAXEVAL=9999 METHOD=1 LAPLACE INTER NOABORT NUMERICAL SLOW NSIG=3 PRINT=1 MSFO=sde10.msf 80 | $COV MATRIX=R 81 | $TABLE ID TIME FLAG AMT CMT IPRED IRES IWRES EVID 82 | ONEHEADER NOPRINT FILE=sde10.fit 83 | -------------------------------------------------------------------------------- /R/SSE_PsN.R: -------------------------------------------------------------------------------- 1 | #' Performs PsN SSE for a given control file and dataset 2 | #' 3 | #' @param command Explicit PsN command to be run at shell/DOS prompt. 4 | #' @param tool PsN tool name. To be used in conjunction with \code{"installPath"} 5 | #' and \code{"version"}. Defaults to "sse". 6 | #' @param installPath Installation path for Perl / PsN. e.g. "c:/strawberry/perl" 7 | #' @param version Version of PsN as a character string. e.g. "4.6.0" 8 | #' @param modelFile NONMEM control stream file name (without extension) 9 | #' @param samples Number of samples for SSE. Required argument. Default = 100. 10 | #' @param psnOpts List of additional PsN command line arguments 11 | #' (format: argumentName = value or argumentName=TRUE/FALSE ) 12 | #' @param clean Whether to clean up additional NONMEM files and folders 13 | #' following PsN call. PsN option. Default = 1. 14 | #' @param working.dir Working directory containing control stream and where 15 | #' output files should be stored 16 | #' @return PsN SSE output 17 | #' @examples 18 | #' @export 19 | #' 20 | #'## ----SSE: 21 | SSE_PsN <- function(command = NULL, 22 | tool = "sse", 23 | installPath = NULL, 24 | version = NULL, 25 | modelFile = NULL, 26 | samples = 100, 27 | psnOpts = NULL, 28 | clean = 1, 29 | working.dir = NULL) { 30 | 31 | if (!is.null(working.dir)) { 32 | psnOpts <- c(list(directory = working.dir), 33 | psnOpts) 34 | } 35 | 36 | if (clean != 1) { 37 | psnOpts <- c(list(clean = clean), 38 | psnOpts) 39 | } 40 | 41 | psnOpts <- c(list(samples = samples), 42 | psnOpts) 43 | 44 | callPsN(command = command, 45 | tool = "sse", 46 | installPath = installPath, 47 | version = version, 48 | file = modelFile, 49 | psnOpts = psnOpts) 50 | } 51 | -------------------------------------------------------------------------------- /tests/written/sde9b.ctl: -------------------------------------------------------------------------------- 1 | $PROBLEM PK ODE HANDS ON ONE 2 | $INPUT ID TIME DV AMT CMT FLAG MDV SDE 3 | $DATA sde9.csv IGNORE=@ 4 | $SUBROUTINE ADVAN6 TOL=10 DP OTHER=sde.f90 5 | $MODEL 6 | COMP = (CENTRAL); 7 | COMP = (DFDX1) 8 | COMP = (DPDT11) 9 | $PK 10 | IF(NEWIND.NE.2) OT = 0 11 | MU_1 = THETA(1) 12 | CL = EXP(MU_1+ETA(1)) 13 | MU_2 = THETA(2) 14 | VD = EXP(MU_2+ETA(2)) 15 | SGW1 = THETA(4) 16 | $DES 17 | " FIRST 18 | " REAL*8 SGW(3) 19 | " FIRSTEM=1 20 | DADT(1) = - CL/VD*A(1) 21 | ; NEXT DERIVATIVES ARE ACUALLY PREDICTIVE VALUES FOR COMPARTMENTS 1 AND 2, RESPECTIVELY 22 | ; Derivatives of these with respect to A() will be calcualted symbolically by DES routine created by NMTRAN 23 | DADT(2) = A(1)/VD 24 | ; DUMMY PLACEMENT FOR DERIVATIVES OF THE STOCHASTIC ERROR SYSTEM. THESE ARE FILLED OUT BY SDE_DER 25 | " SGW(1)=SGW1 26 | ; the DA() array THEN contains all derivatives of DADT (=DXDT) with respect to A(=X). 27 | ; Number of compartments=1, number of base model derivative equations=1 28 | "LAST 29 | " CALL SDE_DER(DADT,A,DA,IR,SGW,1.0d+00,1.0d+00) 30 | $ERROR (OBS ONLY) 31 | IPRED = A(1)/VD 32 | IRES = DV - IPRED 33 | W = THETA(3) 34 | IWRES = IRES/W 35 | WS=1000.0 36 | ; CENTRAL COMPARTMENT, PLASMA LEVELS 37 | ; EPS(1) = USER MODEL ERROR CONTRIBUTION 38 | ; EPS(2) = STOCHASTIC ERROR CONTRIBUTION. THE WS IS JUST A PLACEHOLDER COEFFICIENT. SDE_CADD WILL REPLACE THIS 39 | ; WITH THE CORRECT VALUE 40 | Y = IPRED+W*EPS(1) + WS*EPS(2) 41 | ; SDE_CADD WILL EVALUATE THE TRUE COEFFICIENTS (WS) TO THE STOCHASTIC COMPONENTS. 42 | ; Number of compartments=1, number of base model derivative equations=1 43 | "LAST 44 | " CALL SDE_CADD(A,HH,TIME,DV,CMT,1.0D+00,1.0D+00,SDE) 45 | $THETA (0, 2.3, ) ; 1 CL 46 | (0, 3.5, ) ; 2 VD 47 | (0, 2, ) ; 4 SIGMA 48 | (0, 1, ) ; SGW1 49 | $OMEGA 0.1 ; 1 CL 50 | $OMEGA 0.01 ; 2 VD 51 | $SIGMA 1 FIX ; PK 52 | 1 FIX ; PK 53 | $EST METHOD=ITS INTERACTION LAPLACE NUMERICAL SLOW NOABORT PRINT=1 CTYPE=3 54 | $EST METHOD=IMP INTERACTION NOABORT SIGL=5 PRINT=1 IACCEPT=1.0 CTYPE=3 55 | $EST MAXEVAL=9999 METHOD=1 LAPLACE INTER NOABORT NUMERICAL SLOW NSIG=3 PRINT=1 MSFO=sde9.msf 56 | $COV MATRIX=R 57 | 58 | $TABLE ID TIME FLAG AMT CMT IPRED IRES IWRES APPEND ONEHEADER NOPRINT FILE=sde9.fit 59 | -------------------------------------------------------------------------------- /tests/written/sde9.ctl: -------------------------------------------------------------------------------- 1 | $PROBLEM PK ODE HANDS ON ONE 2 | $INPUT ID TIME DV AMT CMT FLAG MDV SDE 3 | $DATA sde9.csv IGNORE=@ 4 | $SUBROUTINE ADVAN6 TOL=9 DP OTHER=sde.f90 5 | $MODEL 6 | COMP = (CENTRAL); 7 | COMP = (DFDX1) 8 | COMP = (DPDT11) 9 | $PK 10 | IF(NEWIND.NE.2) OT = 0 11 | MU_1 = THETA(1) 12 | CL = EXP(MU_1+ETA(1)) 13 | MU_2 = THETA(2) 14 | VD = EXP(MU_2+ETA(2)) 15 | SGW1 = THETA(4) 16 | $DES 17 | " FIRST 18 | " REAL*8 SGW(3) 19 | FIRSTEM=1 20 | DADT(1) = - CL/VD*A(1) 21 | ; NEXT DERIVATIVES ARE ACUALLY PREDICTIVE VALUES FOR COMPARTMENTS 1 AND 2, RESPECTIVELY 22 | ; Derivatives of these with respect to A() will be calcualted symbolically by DES routine created by NMTRAN 23 | DADT(2) = A(1)/VD 24 | ; DUMMY PLACEMENT FOR DERIVATIVES OF THE STOCHASTIC ERROR SYSTEM. THESE ARE FILLED OUT BY SDE_DER 25 | " SGW(1)=SGW1 26 | ; the DA() array THEN contains all derivatives of DADT (=DXDT) with respect to A(=X). 27 | ; Number of compartments=1, number of base model derivative equations=1 28 | "LAST 29 | " CALL SDE_DER(DADT,A,DA,IR,SGW,1.0d+00,1.0d+00) 30 | $ERROR (OBS ONLY) 31 | IPRED = A(1)/VD 32 | IRES = DV - IPRED 33 | W = THETA(3) 34 | IWRES = IRES/W 35 | WS=1000.0 36 | ; CENTRAL COMPARTMENT, PLASMA LEVELS 37 | ; EPS(1) = USER MODEL ERROR CONTRIBUTION 38 | ; EPS(2) = STOCHASTIC ERROR CONTRIBUTION. THE WS IS JUST A PLACEHOLDER COEFFICIENT. SDE_CADD WILL REPLACE THIS 39 | ; WITH THE CORRECT VALUE 40 | Y = IPRED+W*EPS(1) + WS*EPS(2) 41 | ; SDE_CADD WILL EVALUATE THE TRUE COEFFICIENTS (WS) TO THE STOCHASTIC COMPONENTS. 42 | ; Number of compartments=1, number of base model derivative equations=1 43 | "LAST 44 | " CALL SDE_CADD(A,HH,TIME,DV,CMT,1.0D+00,1.0D+00,SDE) 45 | $THETA (0, 2.3, ) ; 1 CL 46 | (0, 3.5, ) ; 2 VD 47 | (0, 2, ) ; 4 SIGMA 48 | (0, 1, ) ; SGW1 49 | $OMEGA 0.1 ; 1 CL 50 | $OMEGA 0.01 ; 2 VD 51 | $SIGMA 1 FIX ; PK 52 | 1 FIX ; PK 53 | $EST METHOD=ITS INTERACTION LAPLACE NUMERICAL SLOW NOABORT PRINT=1 CTYPE=3 SIGL=5 54 | $EST METHOD=IMP INTERACTION NOABORT SIGL=5 PRINT=1 IACCEPT=1.0 CTYPE=3 55 | $EST MAXEVAL=9999 METHOD=1 LAPLACE INTER NOABORT NUMERICAL SLOW NSIG=3 PRINT=1 MSFO=sde9.msf 56 | $COV MATRIX=R 57 | 58 | $TABLE ID TIME FLAG AMT CMT IPRED IRES IWRES APPEND ONEHEADER NOPRINT FILE=sde9.fit 59 | -------------------------------------------------------------------------------- /R/estimate_NM.R: -------------------------------------------------------------------------------- 1 | #' Estimates parameters using NONMEM 2 | #' 3 | #' @param command Explicit command for running NONMEM as would be run at the 4 | #' shell/DOS prompt. 5 | #' @param tool Tool name e.g. "nmfe". To be used in conjunction with 6 | #' \code{"installPath"} and \code{"version"}. 7 | #' @param installPath Installation path for NONMEM / PsN. e.g. "c:/nm72" 8 | #' @param version Version of NONMEM as a character string. e.g. "7.2" 9 | #' @param modelFile NONMEM control stream file name (without extension) 10 | #' @param lstFile NONMEM output file name. e.g. Run1 11 | #' @param lstFileExtension NONMEM output file extension to be inferred from 12 | #' control stream name if an lstFile isn't explicitly given. Defaults to '.lst'. 13 | #' @param working.dir Working directory containing control stream and where 14 | #' output files should be stored 15 | #' @param cleanup Whether to clean up additional NONMEM files and folders 16 | #' following estimation. Defaults to TRUE. 17 | #' @return NONMEM estimation output files 18 | #' @examples 19 | #' estimate.NM(command = "c:/nm72/run/nmfe72.bat", 20 | #' modelFile='Theophylline.mod', lstFile="Theophylline.lst", 21 | #' working.dir='./data') 22 | 23 | estimate_NM <- function(command = NULL, 24 | tool = NULL, 25 | installPath = NULL, 26 | version = NULL, 27 | modelFile = NULL, 28 | lstFile = NULL, 29 | lstFileExtension = "lst", 30 | clean = 1) { 31 | 32 | baseCommand <- ifelse(is.null(command), 33 | defineExecutable(tool = tool, 34 | installPath = installPath, 35 | version = version), 36 | defineExecutable(command = command)) 37 | lstFile <- ifelse(is.null(lstFile), 38 | paste(tools::file_path_sans_ext(modelFile), 39 | sub("\\.", "", lstFileExtension), sep = "."), 40 | lstFile) 41 | 42 | command <- paste(baseCommand, shQuote(modelFile), shQuote(lstFile)) 43 | 44 | cat(paste(command, "\n")) 45 | execute(command) 46 | 47 | if (clean > 0) cleanup() 48 | } 49 | -------------------------------------------------------------------------------- /R/VPC_PsN.R: -------------------------------------------------------------------------------- 1 | #' Performs VPC of a model using PsN VPC 2 | #' 3 | #' @param command Explicit PsN command to be run at shell/DOS prompt. 4 | #' @param tool PsN tool name. To be used in conjunction with \code{"installPath"} 5 | #' and \code{"version"}. Defaults to "vpc". 6 | #' @param installPath Installation path for Perl / PsN. e.g. "c:/strawberry/perl" 7 | #' @param version Version of PsN as a character string. e.g. "4.6.0" 8 | #' @param samples Number of samples for VPC. Mandatory option for PsN VPC. 9 | #' Default = 100. 10 | #' @param psnOpts List of additional PsN command line options 11 | #' (format: optionName = value or optionName=TRUE/FALSE ) 12 | #' @param modelFile NONMEM control stream file name (without extension) 13 | #' @param clean Whether to clean up additional NONMEM files and folders 14 | #' following estimation. PsN option. Default = 1. 15 | #' @param working.dir Working directory containing control stream and where 16 | #' output files should be stored 17 | #' @return VPC output files 18 | #' @examples 19 | #' VPC_PsN(modelFile='warfarin_PK_CONC_MKS.ctl', working.dir='./data') 20 | #' @export 21 | 22 | VPC_PsN <- function(command = NULL, 23 | tool = "vpc", 24 | installPath = NULL, 25 | version = NULL, 26 | samples = 100, 27 | psnOpts = NULL, 28 | modelFile = NULL, 29 | clean = 1, 30 | working.dir = NULL, ...) { 31 | 32 | if (!is.null(working.dir)) { 33 | psnOpts <- c(list(directory = working.dir), 34 | psnOpts) 35 | } 36 | 37 | if (clean != 1) { 38 | psnOpts <- c(list(clean = clean), 39 | psnOpts) 40 | } 41 | 42 | psnOpts <- c(list(samples = samples, dir = working.dir, clean = clean), 43 | psnOpts) 44 | 45 | baseCommand <- ifelse(is.null(command), 46 | defineExecutable(tool = "vpc", 47 | installPath = installPath, 48 | version = version), 49 | defineExecutable(command = command)) 50 | 51 | callPsN(command = command, 52 | tool = "vpc", 53 | installPath = installPath, 54 | version = version, 55 | file = modelFile, 56 | psnOpts = psnOpts) 57 | } 58 | 59 | 60 | -------------------------------------------------------------------------------- /tests/originals/sde9b.ctl: -------------------------------------------------------------------------------- 1 | $PROBLEM PK ODE HANDS ON ONE 2 | 3 | $INPUT ID TIME DV AMT CMT FLAG MDV SDE 4 | 5 | $DATA sde9.csv 6 | IGNORE=@ 7 | 8 | $SUBROUTINE ADVAN6 TOL=10 DP OTHER=sde.f90 9 | 10 | $MODEL 11 | COMP = (CENTRAL); 12 | COMP = (DFDX1) 13 | COMP = (DPDT11) 14 | 15 | $PK 16 | IF(NEWIND.NE.2) OT = 0 17 | 18 | MU_1 = THETA(1) 19 | CL = EXP(MU_1+ETA(1)) 20 | MU_2 = THETA(2) 21 | VD = EXP(MU_2+ETA(2)) 22 | SGW1 = THETA(4) 23 | 24 | 25 | $DES 26 | " FIRST 27 | " REAL*8 SGW(3) 28 | " FIRSTEM=1 29 | DADT(1) = - CL/VD*A(1) 30 | ; NEXT DERIVATIVES ARE ACUALLY PREDICTIVE VALUES FOR COMPARTMENTS 1 AND 2, RESPECTIVELY 31 | ; Derivatives of these with respect to A() will be calcualted symbolically by DES routine created by NMTRAN 32 | DADT(2) = A(1)/VD 33 | ; DUMMY PLACEMENT FOR DERIVATIVES OF THE STOCHASTIC ERROR SYSTEM. THESE ARE FILLED OUT BY SDE_DER 34 | " SGW(1)=SGW1 35 | ; the DA() array THEN contains all derivatives of DADT (=DXDT) with respect to A(=X). 36 | ; Number of compartments=1, number of base model derivative equations=1 37 | "LAST 38 | " CALL SDE_DER(DADT,A,DA,IR,SGW,1.0d+00,1.0d+00) 39 | 40 | $ERROR (OBS ONLY) 41 | 42 | IPRED = A(1)/VD 43 | IRES = DV - IPRED 44 | W = THETA(3) 45 | IWRES = IRES/W 46 | WS=1000.0 47 | ; CENTRAL COMPARTMENT, PLASMA LEVELS 48 | ; EPS(1) = USER MODEL ERROR CONTRIBUTION 49 | ; EPS(2) = STOCHASTIC ERROR CONTRIBUTION. THE WS IS JUST A PLACEHOLDER COEFFICIENT. SDE_CADD WILL REPLACE THIS 50 | ; WITH THE CORRECT VALUE 51 | Y = IPRED+W*EPS(1) + WS*EPS(2) 52 | ; SDE_CADD WILL EVALUATE THE TRUE COEFFICIENTS (WS) TO THE STOCHASTIC COMPONENTS. 53 | ; Number of compartments=1, number of base model derivative equations=1 54 | "LAST 55 | " CALL SDE_CADD(A,HH,TIME,DV,CMT,1.0D+00,1.0D+00,SDE) 56 | 57 | 58 | 59 | $THETA (0,2.3) ;1 CL 60 | $THETA (0,3.5) ;2 VD 61 | $THETA (0, 2) ;4 SIGMA 62 | $THETA (0,1) ; SGW1 63 | 64 | $OMEGA 0.1 ;1 CL 65 | $OMEGA 0.01 ;2 VD 66 | 67 | $SIGMA (1 FIX) (1 FIX) ; PK 68 | 69 | $EST METHOD=ITS INTERACTION LAPLACE NUMERICAL SLOW NOABORT PRINT=1 CTYPE=3 70 | $EST METHOD=IMP INTERACTION NOABORT SIGL=5 PRINT=1 IACCEPT=1.0 CTYPE=3 71 | $EST MAXEVAL=9999 METHOD=1 LAPLACE INTER NOABORT NUMERICAL SLOW NSIG=3 PRINT=1 MSFO=sde9.msf 72 | $COV MATRIX=R 73 | 74 | $TABLE ID TIME FLAG AMT CMT IPRED IRES IWRES 75 | ONEHEADER NOPRINT FILE=sde9.fit 76 | -------------------------------------------------------------------------------- /R/callPsN.R: -------------------------------------------------------------------------------- 1 | #' callPsN 2 | #' 3 | #' @param command Explicit PsN command to be run at shell/DOS prompt. 4 | #' @param tool PsN tool name. To be used in conjunction with \code{"installPath"} 5 | #' and \code{"version"}. 6 | #' @param installPath Installation path for Perl / PsN. e.g. "c:/strawberry/perl" 7 | #' @param version Version of PsN as a character string. e.g. "4.6.0" 8 | #' @param file File for action with PsN. Usually the model file. 9 | #' For sumo it can be the lstFile. 10 | #' @param psnOpts Additional PsN command line arguments in list format. 11 | #' (format: optionName = value or optionName=TRUE/FALSE ) 12 | #' @details The user has two options: to provide the explicit command for 13 | #' execution at the command or shell prompt OR to provide the tool name, 14 | #' installation path of Perl and version of PsN. 15 | #' callPsN checks option names and value types against expected options for the 16 | #' PsN tool before execution. 17 | #' @return Validate the options and execute the PsN command 18 | #' @export 19 | 20 | callPsN <- function(command = NULL, 21 | tool = NULL, 22 | installPath = NULL, 23 | version = NULL, 24 | file = NULL, 25 | psnOpts = NULL) { 26 | 27 | ## if the user has specified a tool they must also specify the installPath 28 | if (is.null(command)) { 29 | if (is.null(installPath)) stop("Please specify an installPath for PsN") 30 | if (is.null(version)) stop("Please specify a version of PsN") 31 | } 32 | 33 | if (!file.exists(file)) stop(paste("File",file,"cannot be found")) 34 | 35 | psnOptsText <- ifelse(!is.null(psnOpts), 36 | validate_PsN_options(tool = tool, 37 | installPath = installPath, 38 | version = version, 39 | psnOpts = psnOpts), 40 | "") 41 | 42 | baseCommand <- ifelse(is.null(command), 43 | defineExecutable(tool = tool, 44 | installPath = installPath, 45 | version = version), 46 | defineExecutable(command = command)) 47 | 48 | command <- paste(baseCommand, " ", 49 | shQuote(file), 50 | psnOptsText) 51 | 52 | cat(paste(command, "\n")) 53 | execute(command = command) 54 | } 55 | -------------------------------------------------------------------------------- /tests/originals/sde9.ctl: -------------------------------------------------------------------------------- 1 | $PROBLEM PK ODE HANDS ON ONE 2 | 3 | $INPUT ID TIME DV AMT CMT FLAG MDV SDE 4 | 5 | $DATA sde9.csv 6 | IGNORE=@ 7 | 8 | $SUBROUTINE ADVAN6 TOL=9 DP OTHER=sde.f90 9 | 10 | $MODEL 11 | COMP = (CENTRAL); 12 | COMP = (DFDX1) 13 | COMP = (DPDT11) 14 | 15 | $PK 16 | IF(NEWIND.NE.2) OT = 0 17 | 18 | MU_1 = THETA(1) 19 | CL = EXP(MU_1+ETA(1)) 20 | MU_2 = THETA(2) 21 | VD = EXP(MU_2+ETA(2)) 22 | SGW1 = THETA(4) 23 | 24 | 25 | $DES 26 | " FIRST 27 | " REAL*8 SGW(3) 28 | FIRSTEM=1 29 | DADT(1) = - CL/VD*A(1) 30 | ; NEXT DERIVATIVES ARE ACUALLY PREDICTIVE VALUES FOR COMPARTMENTS 1 AND 2, RESPECTIVELY 31 | ; Derivatives of these with respect to A() will be calcualted symbolically by DES routine created by NMTRAN 32 | DADT(2) = A(1)/VD 33 | ; DUMMY PLACEMENT FOR DERIVATIVES OF THE STOCHASTIC ERROR SYSTEM. THESE ARE FILLED OUT BY SDE_DER 34 | " SGW(1)=SGW1 35 | ; the DA() array THEN contains all derivatives of DADT (=DXDT) with respect to A(=X). 36 | ; Number of compartments=1, number of base model derivative equations=1 37 | "LAST 38 | " CALL SDE_DER(DADT,A,DA,IR,SGW,1.0d+00,1.0d+00) 39 | 40 | $ERROR (OBS ONLY) 41 | 42 | IPRED = A(1)/VD 43 | IRES = DV - IPRED 44 | W = THETA(3) 45 | IWRES = IRES/W 46 | WS=1000.0 47 | ; CENTRAL COMPARTMENT, PLASMA LEVELS 48 | ; EPS(1) = USER MODEL ERROR CONTRIBUTION 49 | ; EPS(2) = STOCHASTIC ERROR CONTRIBUTION. THE WS IS JUST A PLACEHOLDER COEFFICIENT. SDE_CADD WILL REPLACE THIS 50 | ; WITH THE CORRECT VALUE 51 | Y = IPRED+W*EPS(1) + WS*EPS(2) 52 | ; SDE_CADD WILL EVALUATE THE TRUE COEFFICIENTS (WS) TO THE STOCHASTIC COMPONENTS. 53 | ; Number of compartments=1, number of base model derivative equations=1 54 | "LAST 55 | " CALL SDE_CADD(A,HH,TIME,DV,CMT,1.0D+00,1.0D+00,SDE) 56 | 57 | 58 | 59 | $THETA (0,2.3) ;1 CL 60 | $THETA (0,3.5) ;2 VD 61 | $THETA (0, 2) ;4 SIGMA 62 | $THETA (0,1) ; SGW1 63 | 64 | $OMEGA 0.1 ;1 CL 65 | $OMEGA 0.01 ;2 VD 66 | 67 | $SIGMA (1 FIX) (1 FIX) ; PK 68 | 69 | $EST METHOD=ITS INTERACTION LAPLACE NUMERICAL SLOW NOABORT PRINT=1 CTYPE=3 SIGL=5 70 | $EST METHOD=IMP INTERACTION NOABORT SIGL=5 PRINT=1 IACCEPT=1.0 CTYPE=3 71 | $EST MAXEVAL=9999 METHOD=1 LAPLACE INTER NOABORT NUMERICAL SLOW NSIG=3 PRINT=1 MSFO=sde9.msf 72 | $COV MATRIX=R 73 | 74 | $TABLE ID TIME FLAG AMT CMT IPRED IRES IWRES 75 | ONEHEADER NOPRINT FILE=sde9.fit 76 | -------------------------------------------------------------------------------- /inst/exdata/moxonidine.mod: -------------------------------------------------------------------------------- 1 | $PROBLEM run1.mod run1.ctl MOXONIDINE PK ANALYSIS 2 | $INPUT ID PAT=DROP VISI XAT2=DROP DGRP=DROP DOSE=DROP FLAG=DROP ONO=DROP 3 | XIME=DROP DVO=DROP NEUY=DROP SCR=DROP AGE SEX NYHA=DROP WT 4 | COMP ACE DIG DIU NUMB=DROP TAD TIME VIDD=DROP CLCR AMT SS 5 | II VID CMT=DROP CONO=DROP DV EVID=DROP OVID=DROP RGRP 6 | $DATA mx2007.csv IGNORE=@ 7 | $SUBROUTINE ADVAN2 TRANS1 8 | $PK 9 | 10 | ;-----------OCCASIONS---------- 11 | VIS3 = 0 12 | IF(VISI.EQ.3) VIS3 = 1 13 | VIS8 = 0 14 | IF(VISI.EQ.8) VIS8 = 1 15 | 16 | ;----------IOV-------------------- 17 | 18 | KPCL = VIS3*ETA(4)+VIS8*ETA(5) 19 | KPKA = VIS3*ETA(6)+VIS8*ETA(7) 20 | 21 | ;---------- PK model ------------------ 22 | 23 | TVCL = THETA(1)*(1+THETA(7)*(CLCR-65)) 24 | TVV = THETA(2)*WT 25 | TVKA = THETA(3) 26 | 27 | CL = TVCL*EXP(ETA(1)+KPCL) 28 | V = TVV*EXP(ETA(2)) 29 | KA = TVKA*EXP(ETA(3)+KPKA) 30 | ALAG1 = THETA(4) 31 | K = CL/V 32 | S2 = V 33 | 34 | $ERROR 35 | 36 | IPRED = LOG(.025) 37 | IF(F.GT.0) IPRED = LOG(F) 38 | W = (THETA(6) + THETA(5)/IPRED) ;* EXP(ETA(8)) 39 | IRES = IPRED-DV 40 | IWRES = IRES/W 41 | Y = IPRED+EPS(1)*W 42 | 43 | $THETA (0,27.1) ;TVCL ; 1 44 | $THETA (0,1.49) ;TVV ; 2 ;This is in L per kg WT 45 | $THETA (0,3.52) ;TVKA ; 3 46 | $THETA (0,.227) ;LAG ; 4 47 | $THETA 0 FIX ;Add.err ; 5 48 | $THETA (0,.343) ;Prop.err ; 6 49 | $THETA (0,.00646,.02941) ;CRCL.on.CL ; 7 50 | 51 | $OMEGA BLOCK(2) 0.0489 ;IIV.CL ; 1 52 | 0.0256 ;COV.ETA.CL.V; 1-2 53 | 0.0156 ;IIV.V ; 2 54 | $OMEGA BLOCK(1) 1.98 ;IIV.KA ; 3 55 | $OMEGA BLOCK(1) 0.013 ;IOV.CL ; 4 56 | $OMEGA BLOCK(1) SAME ;IOV.CL.2 ; 5 57 | $OMEGA BLOCK(1) 0.0481 ;IOV.KA ; 6 58 | $OMEGA BLOCK(1) SAME ;IOV.KA.2 ; 7 59 | ;$OMEGA 0.001 ;IIV.EPS ; 8 60 | 61 | $SIGMA 1 FIX ;ResFixed ; 1 62 | $ESTIMATION METHOD=1 MAXEVALS=9999 PRINT=1 MSFO=msf1 63 | ;$COVARIANCE PRINT=E 64 | 65 | $TAB ID TAD IPRED IWRES CWRES ONEHEADER NOPRINT FILE = sdtab1 66 | $TAB ID ETA1 ETA2 ETA3 ETA4 ETA5 ETA6 ETA7 ONEHEADER NOPRINT FILE = patab1 NOAPPEND 67 | $TAB ID AGE WT CLCR ONEHEADER NOPRINT FILE = cotab1 NOAPPEND 68 | $TAB ID SEX ACE DIG DIU COMP VISI ONEHEADER NOPRINT FILE = catab1 NOAPPEND 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /tests/originals/moxonidine.mod: -------------------------------------------------------------------------------- 1 | $PROBLEM run1.mod run1.ctl MOXONIDINE PK ANALYSIS 2 | $INPUT ID PAT=DROP VISI XAT2=DROP DGRP=DROP DOSE=DROP FLAG=DROP ONO=DROP 3 | XIME=DROP DVO=DROP NEUY=DROP SCR=DROP AGE SEX NYHA=DROP WT 4 | COMP ACE DIG DIU NUMB=DROP TAD TIME VIDD=DROP CLCR AMT SS 5 | II VID CMT=DROP CONO=DROP DV EVID=DROP OVID=DROP RGRP 6 | $DATA mx2007.csv IGNORE=@ 7 | $SUBROUTINE ADVAN2 TRANS1 8 | $PK 9 | 10 | ;-----------OCCASIONS---------- 11 | VIS3 = 0 12 | IF(VISI.EQ.3) VIS3 = 1 13 | VIS8 = 0 14 | IF(VISI.EQ.8) VIS8 = 1 15 | 16 | ;----------IOV-------------------- 17 | 18 | KPCL = VIS3*ETA(4)+VIS8*ETA(5) 19 | KPKA = VIS3*ETA(6)+VIS8*ETA(7) 20 | 21 | ;---------- PK model ------------------ 22 | 23 | TVCL = THETA(1)*(1+THETA(7)*(CLCR-65)) 24 | TVV = THETA(2)*WT 25 | TVKA = THETA(3) 26 | 27 | CL = TVCL*EXP(ETA(1)+KPCL) 28 | V = TVV*EXP(ETA(2)) 29 | KA = TVKA*EXP(ETA(3)+KPKA) 30 | ALAG1 = THETA(4) 31 | K = CL/V 32 | S2 = V 33 | 34 | $ERROR 35 | 36 | IPRED = LOG(.025) 37 | IF(F.GT.0) IPRED = LOG(F) 38 | W = (THETA(6) + THETA(5)/IPRED) ;* EXP(ETA(8)) 39 | IRES = IPRED-DV 40 | IWRES = IRES/W 41 | Y = IPRED+EPS(1)*W 42 | 43 | $THETA (0,27.1) ;TVCL ; 1 44 | $THETA (0,1.49) ;TVV ; 2 ;This is in L per kg WT 45 | $THETA (0,3.52) ;TVKA ; 3 46 | $THETA (0,.227) ;LAG ; 4 47 | $THETA 0 FIX ;Add.err ; 5 48 | $THETA (0,.343) ;Prop.err ; 6 49 | $THETA (0,.00646,.02941) ;CRCL.on.CL ; 7 50 | 51 | $OMEGA BLOCK(2) 0.0489 ;IIV.CL ; 1 52 | 0.0256 ;COV.ETA.CL.V; 1-2 53 | 0.0156 ;IIV.V ; 2 54 | $OMEGA BLOCK(1) 1.98 ;IIV.KA ; 3 55 | $OMEGA BLOCK(1) 0.013 ;IOV.CL ; 4 56 | $OMEGA BLOCK(1) SAME ;IOV.CL.2 ; 5 57 | $OMEGA BLOCK(1) 0.0481 ;IOV.KA ; 6 58 | $OMEGA BLOCK(1) SAME ;IOV.KA.2 ; 7 59 | ;$OMEGA 0.001 ;IIV.EPS ; 8 60 | 61 | $SIGMA 1 FIX ;ResFixed ; 1 62 | $ESTIMATION METHOD=1 MAXEVALS=9999 PRINT=1 MSFO=msf1 63 | ;$COVARIANCE PRINT=E 64 | 65 | $TAB ID TAD IPRED IWRES CWRES ONEHEADER NOPRINT FILE = sdtab1 66 | $TAB ID ETA1 ETA2 ETA3 ETA4 ETA5 ETA6 ETA7 ONEHEADER NOPRINT FILE = patab1 NOAPPEND 67 | $TAB ID AGE WT CLCR ONEHEADER NOPRINT FILE = cotab1 NOAPPEND 68 | $TAB ID SEX ACE DIG DIU COMP VISI ONEHEADER NOPRINT FILE = catab1 NOAPPEND 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # :no_entry: [DEPRECATED] rspeaksnonmem 2 | R package for working with and executing NONMEM control files, also integrating PsN. 3 | 4 | This package is deprecated and will not be updated or further maintained. I suggest instead using the package {Pharmpy} and {Pharmr} developed by Uppsala University, Sweden. https://pharmpy.github.io/latest/index.html. These packages implement much of the functionality in {rspeaksnonmem} in a better and more consistent way, and are actively maintained. 5 | 6 | ## Description 7 | 8 | `rspeaksnonmem` is designed to allow the user to craft workflows based on a given NONMEM model. 9 | 10 | After importing and parsing a control stream to an R object (using the `RNMImport` package), `rspeaksnonmem` allows the user to easily change initial estimates, change data attributes or change task properties (estimation or simulation settings) without having to change the model. This saves a lot of textual searching by the user. The resulting data, parameter, 11 | model and task information is then written back out to file using an existing (possibly the original) model as a 12 | template. 13 | 14 | `rspeaksnonmem` also allows the user to run NONMEM models from R either directly running the nmfe.bat or by 15 | calling [Perl speaks NONMEM](http://psn.sourceforge.net) functions like "execute". Other PsN functions can be run from 16 | R - VPC (Visual Predictive Check), bootstrap, SSE (Stochastic Simulation and Estimation). 17 | 18 | ### ISOP Study Group demonstration 19 | `rspeaksnonmem` was demonstrated at an ISOP Study Group webinar which is available on YouTube: https://www.youtube.com/watch?v=VFdGnWrRXw8. 20 | 21 | ## Installation 22 | 23 | Eventually, `rspeaksnonmem` will be released to CRAN, but while still in development `rspeaksnonmem` can most easily be installed from GitHub using the `devtools` package: 24 | 25 | library(devtools) 26 | install_github("MikeKSmith/rspeaksnonmem") 27 | 28 | ## Dependencies 29 | 30 | `rspeaksnonmem` relies on the package [`RNMImport`](https://r-forge.r-project.org/R/?group_id=1922) function 31 | `importNmMod` which reads and parses the NONMEM control stream. `rspeaksnonmem` then works with 32 | the data, parameter values, and task information separately from the model. 33 | 34 | Before installation of `rspeaksnonmem`, the package `RNMImport` needs to be installed. This package is not on CRAN but is available on R-Forge. You can install from there using: 35 | 36 | install.packages("RNMImport", repos="http://R-Forge.R-project.org") 37 | 38 | or download the `.tar` file from [R-Forge](https://r-forge.r-project.org/R/?group_id=1922) and run in R: 39 | 40 | install.packages("~/Downloads/RNMImport_4.0-27.tar.gz", repos=NULL, type = "source") 41 | 42 | -------------------------------------------------------------------------------- /R/bs_summary.R: -------------------------------------------------------------------------------- 1 | #' Parses the PsN bootstrap results file (bootstrap_results.csv) 2 | #' 3 | #' @param fileName fileName for the bootstrap results file. Default 4 | #' 'bootstrap_results.csv' 5 | #' @param bs.dir Directory containing control stream and where bootstrap 6 | #' results file (bootstrap_results.csv) is stored. Defaults to './bootstrap_dir1' 7 | #' as PsN default. 8 | #' @return list containing parsed blocks from bootstrap_results.csv 9 | #' @examples 10 | #' 11 | bs_summary <- function(fileName = "bootstrap_results.csv", 12 | working.dir = NULL) { 13 | 14 | # If the working.dir argument is populated then create a full file path 15 | # Otherwise assume that fileName argument is a full file path. 16 | if(!is.null(working.dir)) fileName <- file.path(working.dir, fileName) 17 | text <- readLines(fileName) 18 | 19 | diagnostics <- read.csv(fileName, skip = grep("^diagnostic", text), header = T, 20 | nrows = 1)[-1] 21 | 22 | means <- read.csv(fileName, skip = grep("^means", text) + 1, header = F, nrows = 1)[-1] 23 | names(means) <- gsub("\\s", "", read.csv(fileName, skip = grep("^means", text), 24 | nrows = 1, header = F, stringsAsFactors = F)[-1]) 25 | 26 | bias <- read.csv(fileName, skip = grep("^bias", text) + 1, header = F, nrows = 1)[-1] 27 | names(bias) <- gsub("\\s", "", read.csv(fileName, skip = grep("^bias", text), 28 | nrows = 1, header = F, stringsAsFactors = F)[-1]) 29 | 30 | se_CI <- read.csv(fileName, skip = grep("^standard.error.confidence", text) + 31 | 1, nrows = 8, header = F, row.names = 1) 32 | names(se_CI) <- gsub("\\s", "", read.csv(fileName, skip = grep("^standard.error.confidence", 33 | text), nrows = 1, header = F, stringsAsFactors = F)[-1]) 34 | row.names(se_CI) <- gsub("\\s", "", row.names(se_CI)) 35 | 36 | se <- read.csv(fileName, skip = grep("^standard.error", text) + 1, header = F, 37 | nrows = 1)[-1] 38 | names(se) <- gsub("\\s", "", read.csv(fileName, skip = grep("^standard.error", 39 | text), nrows = 1, header = F, stringsAsFactors = F)[-1]) 40 | 41 | medians <- read.csv(fileName, skip = grep("^medians", text) + 1, header = F, 42 | nrows = 1)[-1] 43 | names(medians) <- gsub("\\s", "", read.csv(fileName, skip = grep("^medians", 44 | text), nrows = 1, header = F, stringsAsFactors = F)[-1]) 45 | 46 | perc_CI <- read.csv(fileName, skip = grep("^percentile", text) + 1, nrows = 8, 47 | header = F, row.names = 1) 48 | names(perc_CI) <- gsub("\\s", "", read.csv(fileName, skip = grep("^percentile", 49 | text), nrows = 1, header = F, stringsAsFactors = F)[-1]) 50 | row.names(perc_CI) <- gsub("\\s", "", row.names(perc_CI)) 51 | 52 | out <- list(diagnostics = diagnostics, means = means, bias = bias, se_CI = se_CI, 53 | se = se, medians = medians, perc_CI = perc_CI) 54 | out 55 | } 56 | -------------------------------------------------------------------------------- /vignettes/rspeaksnonmem_with_PsN_rplots.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "rspeaksnonmem with PsN rplots .Rmd files" 3 | author: "Mike K Smith" 4 | date: "03 July 2017" 5 | output: html_document 6 | params: 7 | rplots: 1 8 | psnRunDir: "run1" 9 | --- 10 | 11 | ```{r setup, message = FALSE} 12 | # devtools::install_github(repo = "MikeKSmith/rspeaksnonmem") 13 | # devtools::install_github(repo = "MangoTheCat/RNMImport") 14 | 15 | library(rspeaksnonmem) 16 | setwd(".") 17 | ``` 18 | 19 | ```{r copyFiles,echo=FALSE,results='hide',message=FALSE, warning=FALSE} 20 | file.copy(from = file.path(system.file("exdata", package = "rspeaksnonmem"), 21 | "warfarin_conc_pca.csv"), 22 | to = getwd(), overwrite = T ) 23 | file.copy(from = file.path(system.file("exdata", package = "rspeaksnonmem"), 24 | "warfarin.ctl"), 25 | to = getwd(), overwrite = T ) 26 | file.rename(from = "warfarin.ctl", "run0.ctl") 27 | ``` 28 | 29 | Being able to run PsN from within R means that you can easily combine execution 30 | with the PsN output plot markdown files (.Rmd files within the PsN working 31 | directory). Here we're going to run the PsN `execute` function with the option 32 | to create diagnostic plots `rplots=1`. 33 | 34 | We have parameterised this report by including the following parameters in the 35 | YAML header for this report: 36 | ``` 37 | --- 38 | title: "rspeaksnonmem with PsN rplots .Rmd files" 39 | author: "Mike K Smith" 40 | date: "03 July 2017" 41 | output: html_document 42 | params: 43 | rplots: 1 44 | psnRunDir: "run0" 45 | --- 46 | ``` 47 | 48 | We can then use these parameters within the R code by referencing params$rplots 49 | or params$psnRunDir. Having these as parameters of the document means that we 50 | can re-run the document and change these parameters without having to change 51 | code ***within*** the document. 52 | 53 | ## Run Execute 54 | ```{r PsN_execute_with_plots, message = FALSE, warning = FALSE} 55 | execute_PsN(installPath = "c:/strawberry/perl", 56 | version = "4.7.0", 57 | modelFile = 'run0.ctl', 58 | rplots = params$rplots, 59 | working.dir = params$psnRunDir) 60 | ``` 61 | 62 | We search within the working directory for the .Rmd file and include this as 63 | a child document to this parent markdown file. `rplotOutput` contains the name 64 | of the PsN `rplots` output .Rmd file. In case we change the option above, we 65 | also create a boolean variable `includeRplotOutput`. 66 | 67 | ```{r, results = "hide"} 68 | rplotOutput <- list.files(path = params$psnRunDir, 69 | recursive = TRUE, 70 | pattern = "plots.Rmd", 71 | full.names = TRUE) 72 | includeRplotOutput <- params$rplots > 0 73 | ``` 74 | We use the boolean `includeRplotOutput` to conditionally execute the chunk below. 75 | 76 | ```{r, child=rplotOutput, eval = includeRplotOutput} 77 | ``` 78 | -------------------------------------------------------------------------------- /R/runRecord_PsN.R: -------------------------------------------------------------------------------- 1 | #' Uses PsN RunRecord function to create a Run Record 2 | #' 3 | #' @param command Explicit PsN command to be run at shell/DOS prompt. 4 | #' @param tool PsN tool name. To be used in conjunction with \code{"installPath"} 5 | #' and \code{"version"}. Defaults to "runrecord". 6 | #' @param installPath Installation path for Perl / PsN. e.g. "c:/strawberry/perl" 7 | #' @param version Version of PsN as a character string. e.g. "4.6.0" 8 | #' @param to Run numbers to include in the Run Record. 9 | #' @param runRoot Root for Run control and output files e.g. Run1.mod, Run1.lst 10 | #' would have runRoot='Run' 11 | #' @param modelExtension Extension for NONMEM control stream files. 12 | #' Default is '.mod'. 13 | #' @param outputExtension Extension for NONMEM output files. Default is '.lst'. 14 | #' @param psnOpts Additional arguments for PsN runrecord function. 15 | #' @param clean Clean up working directory following completion. PsN option. 16 | #' Default = 1. 17 | #' @param working.dir Working directory containing control streams and where 18 | #' output files should be stored 19 | #' @return PsN Run Record output 20 | #' @examples 21 | #' @export 22 | #' 23 | runRecord_PsN <- function(command = NULL, 24 | tool = "runrecord", 25 | installPath = NULL, 26 | version = NULL, 27 | to = NULL, 28 | runRoot = "Run", 29 | modelExtension = ".mod", 30 | outputExtension = ".lst", 31 | psnOpts = NULL, 32 | clean = 1, 33 | working.dir = NULL) { 34 | 35 | if (!is.null(working.dir)) { 36 | psnOpts <- c(list(directory = working.dir), 37 | psnOpts) 38 | } 39 | 40 | if (clean != 1) { 41 | psnOpts <- c(list(clean = clean), 42 | psnOpts) 43 | } 44 | 45 | psnOpts <- c(list(to=to), 46 | psnOpts) 47 | 48 | psnOpts <- c(list(mod_ext = modelExtension), 49 | psnOpts) 50 | 51 | if (is.null(command)) { 52 | if (is.null(installPath)) stop("Please specify an installPath for PsN") 53 | if (is.null(version)) stop("Please specify a version of PsN") 54 | } 55 | 56 | psnOptsText <- ifelse(!is.null(psnOpts), 57 | validate_PsN_options(tool = tool, 58 | installPath = installPath, 59 | version = version, 60 | psnOpts = psnOpts), 61 | "") 62 | 63 | baseCommand <- ifelse(is.null(command), 64 | defineExecutable(tool = "runrecord", 65 | installPath = installPath, 66 | version = version), 67 | defineExecutable(command = command)) 68 | 69 | command <- paste(baseCommand, " ", 70 | psnOptsText) 71 | 72 | cat(paste(command, "\n")) 73 | execute(command = command) 74 | 75 | runRecord <- read.table("AAruninfo.txt", sep = ";", row.names = NULL, skip = 5, 76 | header = F, stringsAsFactors = F, as.is = T) 77 | 78 | names(runRecord) <- scan("AAruninfo.txt", sep = ";", what = "character", skip = 4, 79 | nlines = 1) 80 | 81 | runRecord$Run <- seq(1, to) 82 | runRecord <- runRecord[, -ncol(runRecord)] 83 | return(runRecord) 84 | } 85 | -------------------------------------------------------------------------------- /tests/compare_importNmMod.R: -------------------------------------------------------------------------------- 1 | # library(rspeaksnonmem) 2 | # library(RNMImport) 3 | library(testthat) 4 | devtools::load_all(pkg=".") 5 | devtools::load_all(pkg = "C:\\Users\\smith_mk\\Documents\\Working documents\\RNMImport") 6 | 7 | context("write NM control stream") 8 | 9 | #' Check conversion of NONMEM example files 10 | #' ---------------- 11 | files <- list.files(file.path("c:","nm72","examples"),pattern = ".ctl",full.names = T) 12 | #' RNMImport does not support PRIOR or BAYES estimation (yet), so select only the "sde" examples 13 | files1 <- files[grep("^sd",basename(files))] 14 | #' Example sde9.ctl has single comment for both SIGMA parameters. TODO: Fix 15 | files1 <- files1[-grep("^sde9", basename(files1))] 16 | 17 | #' Gather example files 18 | #' ---------------- 19 | #' Taking testdata examples from RNMImport, metrumrg, rspeaksnonmem. 20 | 21 | files2 <- list.files(file.path(system.file("unittests", package="RNMImport"),"testdata"), 22 | pattern = "\\.ctl|\\.mod|\\.con", 23 | full.names = T, recursive=T) 24 | 25 | # multiprob1 example doesn't work due to $MSFI 26 | files2 <- files2[-grep("multiprob1", basename(files2))] 27 | #files2 <- files2[-grep("subprob1.mod", basename(files2))] 28 | files2 <- files2[-grep("TestRun", dirname(files2))] 29 | 30 | files3 <- list.files(file.path(system.file("example", package="metrumrg"),"project"), 31 | pattern = "\\.ctl|\\.mod|\\.con", 32 | full.names = T, recursive=T) 33 | 34 | # 1005 & 1006 have issues in RNMImport around naming of parameters based on comments 35 | files3 <- files3[-grep("1005",basename(files3))] 36 | files3 <- files3[-grep("1006",basename(files3))] 37 | 38 | files4 <- list.files("C:\\Users\\smith_mk\\Documents\\Working documents\\rspeaksnonmem\\inst\\exdata", 39 | pattern = "\\.ctl|\\.mod|\\.con", 40 | full.names = T, recursive=T) 41 | 42 | #' Taking examples from DDMoRe SEE 43 | files5 <- list.files("C:\\SEE\\MDL_IDE\\workspace\\UseCasesDemo\\", 44 | pattern="\\.ctl", full.names=T, recursive=T) 45 | files5 <- files5[!duplicated(basename(files5))] 46 | 47 | input <- c(files1,files2, files3,files4) 48 | 49 | sink("test_original_written.txt") 50 | 51 | for (i in 1:length(input)){ 52 | file <-input[i] 53 | fileTxt <- paste("\n", i, "File:", file,"") 54 | cat(fileTxt, sep="\n") 55 | ref <- RNMImport::importNmMod(file) 56 | try(writeNMControlStream(templateModel=ref$Raw, 57 | parsedControl = ref$problemContents, 58 | outputFile = "temp", 59 | outFileExtension = "ctl")) 60 | test <- RNMImport::importNmMod("temp.ctl") 61 | probPass <- NULL 62 | for (j in 1:length(ref$problemContents)){ 63 | probName <- paste("Problem:",ref$problemContents[[j]]$Problem) 64 | cat(probName,sep="\n") 65 | sectionPass <- NULL 66 | sectionTestTxt <- NULL 67 | for (k in 1:length(ref$problemContents[[j]])){ 68 | sectionPass[k] <- identical(ref$problemContents[[j]][k], test$problemContents[[j]][k]) 69 | sectionTestTxt[k] <- paste("\t",names(ref$problemContents[[j]][k]),":", 70 | ifelse(sectionPass[k],"PASS","FAIL")) 71 | cat(sectionTestTxt[k], sep="\n") 72 | if (!sectionPass[k]){ 73 | cat("\nref:") 74 | print(ref$problemContents[[j]][k]) 75 | cat("\ntest:") 76 | print(test$problemContents[[j]][k]) 77 | } 78 | } 79 | probPass[j] <- all(sectionPass) 80 | } 81 | testPass <- all(probPass) 82 | testPassTxt <- paste("All sections identical:",ifelse(testPass,"PASS","FAIL")) 83 | cat(testPassTxt, sep="\n") 84 | } 85 | sink() -------------------------------------------------------------------------------- /tests/originals/1006.ctl: -------------------------------------------------------------------------------- 1 | $PROB 1006 like 1005 with tweaked initial estimates 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV SUBJ HOUR HEIGHT WT SEX AGE DOSE FED 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) * THETA(6)**SEX * (WT/70)**THETA(7) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4) 10 | V3=THETA(5) 11 | S2=V2 12 | 13 | $ERROR 14 | Y=F*(1+ERR(1)) + ERR(2) 15 | IPRE=F 16 | ; 17 | $THETA 18 | ; 19 | (0,11.6,50) 20 | (0,9.58,100) 21 | (0,0.235,5) 22 | (0,11.7,50) 23 | (0,105,1000) 24 | (0,0.8,2) 25 | (0,0.659,3) 26 | $OMEGA BLOCK(3) 27 | .1 28 | .01 .1 29 | .01 .01 .1 30 | 31 | ;interindividual variability on clearance 32 | ;interindividual clearance-volume covariance 33 | ;interindividual variability on central volume 34 | ;interindividual clearance-Ka covariance 35 | ;interindividual volume-Ka covariance 36 | ;interindividual variability on Ka 37 | 38 | $SIGMA 0.1 0.1 39 | 40 | ;proportional error 41 | ;additive error 42 | 43 | $ESTIMATION MAXEVAL=9999 PRINT=5 NOABORT METHOD=1 INTER MSFO=./1006.msf 44 | $COV PRINT=E 45 | $TABLE NOPRINT FILE=./1006.tab ONEHEADER ID AMT TIME EVID PRED IPRE CWRES 46 | NPRED 47 | CPRED 48 | CPREDI 49 | EPRED 50 | RES 51 | NRES 52 | NWRES 53 | CRES 54 | RESI 55 | WRESI 56 | CRESI 57 | CWRESI 58 | CIWRES 59 | CIWRESI 60 | ERES 61 | EWRES 62 | ECWRES 63 | $TABLE NOPRINT FILE=./1006par.tab ONEHEADER ID TIME CL Q V2 V3 KA ETA1 ETA2 ETA3 64 | 65 | ;apparent oral clearance 66 | ;central volume of distribution 67 | ;absorption rate constant 68 | ;intercompartmental clearance 69 | ;peripheral volume of distribution 70 | ;male effect on clearance 71 | ;weight effect on clearance 72 | ;interindividual variability of clearance 73 | ;interindividual clearance-volume covariance 74 | ;interindividual variability of central volume 75 | ;interindividual clearance-Ka covariance 76 | ;interindividual volume-Ka covariance 77 | ;interindividual variability of Ka 78 | ;proportional error 79 | ;additive error 80 | ; 81 | -------------------------------------------------------------------------------- /tests/Read_and_write_from_NM_examples.R: -------------------------------------------------------------------------------- 1 | #' ---------------- 2 | #' title: "Reading NMTRAN control streams using RNMImport and writing with rspeaksnonmem" 3 | #' author: "Mike Smith " 4 | #' date: "`r Sys.Date()`" 5 | #' ---------------- 6 | #' Load packages 7 | #' ---------------- 8 | devtools::load_all(pkg=".") 9 | devtools::load_all(pkg = "C:\\Users\\smith_mk\\Documents\\Working documents\\RNMImport") 10 | 11 | #' Check conversion of NONMEM example files 12 | #' ---------------- 13 | files <- list.files(file.path("c:","nm72","examples"),pattern = ".ctl",full.names = T) 14 | #' RNMImport does not support PRIOR or BAYES estimation (yet), so select only the "sde" examples 15 | files1 <- files[grep("^sd",basename(files))] 16 | 17 | #' Gather example files 18 | #' ---------------- 19 | #' Taking testdata examples from RNMImport, metrumrg, rspeaksnonmem. 20 | 21 | files2 <- list.files(file.path(system.file("unittests", package="RNMImport"),"testdata"), 22 | pattern = "\\.ctl|\\.mod|\\.con", 23 | full.names = T, recursive=T) 24 | 25 | # multiprob1 example doesn't work due to $MSFI 26 | files2 <- files2[-grep("multiprob1", basename(files2))] 27 | #files2 <- files2[-grep("subprob1.mod", basename(files2))] 28 | files2 <- files2[-grep("TestRun", dirname(files2))] 29 | 30 | files3 <- list.files(file.path(system.file("example", package="metrumrg"),"project"), 31 | pattern = "\\.ctl|\\.mod|\\.con", 32 | full.names = T, recursive=T) 33 | 34 | # 1005 & 1006 have issues in RNMImport around naming of parameters based on comments 35 | files3 <- files3[-grep("1005",basename(files3))] 36 | files3 <- files3[-grep("1006",basename(files3))] 37 | 38 | files4 <- list.files("C:\\Users\\smith_mk\\Documents\\Working documents\\rspeaksnonmem\\inst\\exdata", 39 | pattern = "\\.ctl|\\.mod|\\.con", 40 | full.names = T, recursive=T) 41 | 42 | #' Taking examples from DDMoRe SEE 43 | files5 <- list.files("C:\\SEE\\MDL_IDE\\workspace\\UseCasesDemo\\", 44 | pattern="\\.ctl", full.names=T, recursive=T) 45 | files5 <- files5[!duplicated(basename(files5))] 46 | 47 | #' Copy files into a single directory 48 | setwd(system.file("tests", package="rspeaksnonmem")) 49 | 50 | #' Original files go in /originals folder 51 | originals <- file.path(getwd(),"originals") 52 | dir.create(originals) 53 | 54 | #' control streams written by rspeaksnonmem go in the /written directory 55 | written <- file.path(getwd(),"written") 56 | dir.create(written) 57 | 58 | lapply(files1, function(x)file.copy(from=x, to=originals)) 59 | lapply(files2, function(x)file.copy(from=x, to=originals)) 60 | lapply(files3, function(x)file.copy(from=x, to=originals)) 61 | lapply(files4, function(x)file.copy(from=x, to=originals)) 62 | 63 | input <- c(files1,files2, files3,files4) 64 | 65 | #' Clean out any previously written files 66 | unlink(list.files(path=file.path("written"))) 67 | 68 | #' Read and write 69 | #' -------------------- 70 | #' The aim of this step is to test the writeNmControlStream function from rspeaksnonmem. 71 | #' If the resulting written NMTRAN control streams match content with the original then 72 | #' the writeNmControlStream function is working as expected. Note though that because of 73 | #' the flexibility in writing NMTRAN, the two files may not match EXACTLY. This is to be 74 | #' expected. We could perform a check that the models are equivalent formally by running 75 | #' the model with the original data and comparing OFV, or simulating new data first then 76 | #' performing estimation and comparing OFV. 77 | #' 78 | #' For now we need to check the output manually to assess whether the original and written 79 | #' files are comparable. 80 | #' 81 | inFiles <- lapply(input, function(x){ 82 | cat(x,sep="\n") 83 | foo <- RNMImport::importNmMod(x) 84 | try(writeNMControlStream(templateModel=foo$Raw, 85 | parsedControl = foo$problemContents, 86 | outputFile = file.path(written,tools::file_path_sans_ext(basename(x))), 87 | outFileExtension = tools::file_ext(x))) 88 | }) 89 | 90 | -------------------------------------------------------------------------------- /R/validate_PsN_options.R: -------------------------------------------------------------------------------- 1 | #' Checks valid options for PsN commands 2 | #' 3 | #' @param command PsN command. 4 | #' @param tool PsN tool. 5 | #' @param installPath Installation path for Perl / PsN 6 | #' @param version Version of PsN 7 | #' @param psnOpts List of additional PsN command line options 8 | #' (format: optionName = value or optiontName=TRUE/FALSE ) 9 | #' @details Either specify an explicit command to run at the system prompt 10 | #' or specify a combination of tool, installPath and version. 11 | #' @return character string of valid PsN arguments 12 | #' @examples 13 | #' validate_PsN_options(command='execute', 14 | #' psnOpts = list(picky=TRUE, retries=3, 15 | #' tweak_inits=TRUE)) 16 | #' @export 17 | 18 | validate_PsN_options <- function(command = NULL, 19 | tool = NULL, 20 | installPath = NULL, 21 | version = NULL, 22 | psnOpts = NULL) { 23 | 24 | require(dplyr, quietly = TRUE) 25 | require(stringr, quietly = TRUE) 26 | 27 | if(is.null(tool) && is.null(command)) stop("One of tool or command must be specified") 28 | 29 | # If using tool then specify installPath and version 30 | if (is.null(command) && !is.null(tool)){ 31 | if (is.null(installPath)) stop("If using tool, please specify an installPath") 32 | if (is.null(version)) stop("If using tool, please specify a version") 33 | } 34 | 35 | psnOptionCommand <- ifelse( is.null(command), 36 | defineExecutable(tool = "psn_options", 37 | version = version, 38 | installPath = installPath), 39 | defineExecutable(command = file.path( 40 | dirname( 41 | stringr::word(command,1) 42 | ),"psn_options") 43 | ) 44 | ) 45 | 46 | psnCommon <- system(command = paste(psnOptionCommand,"-h"), intern = T) 47 | psnCommon <- parse_PsN_options(psnCommon) 48 | 49 | command <- ifelse(is.null(command), 50 | paste( 51 | defineExecutable(tool = tool, 52 | version = version, 53 | installPath = installPath), 54 | "-h" 55 | ), 56 | paste(command, "-h ") 57 | ) 58 | psnOptions <- system(command, intern = TRUE) 59 | psnOptions <- parse_PsN_options(psnOptions) 60 | 61 | psnOptions <- dplyr::union(psnOptions, psnCommon) 62 | 63 | ## Check psnOpts names 64 | matchedNames <- sapply(names(psnOpts),function(x)pmatch(x,psnOptions$name)) 65 | validName <- !is.na(matchedNames) 66 | if (!all(validName)) 67 | warning(paste(names(psnOpts[!validName]), 68 | "is not a valid PsN argument for", 69 | tool, 70 | "\n", 71 | collapse = "\n")) 72 | if (!any(validName)) return("") 73 | 74 | psnOpts <- psnOpts[validName] 75 | names(psnOpts) <- psnOptions$name[matchedNames[validName]] 76 | 77 | quotedStrings <- sapply(psnOpts, is.character) 78 | psnOpts[quotedStrings] <- shQuote(psnOpts[quotedStrings]) 79 | psnOptType <- psnOptions$type[matchedNames[validName]] 80 | checkOptType <- psnOptType 81 | checkOptType[psnOptType==""] <- "is.logical" 82 | checkArg <- paste(checkOptType, "(",psnOpts,")",sep="") 83 | validArg <- sapply(checkArg, function(x) { 84 | eval(parse(text = x)) 85 | }) 86 | if (!all(validArg)) 87 | warning(paste(psnOpts[!validArg], 88 | "is not a valid value for the option", 89 | names(psnOpts[!validArg]),"\n")) 90 | 91 | checked <- psnOpts[validArg] 92 | 93 | if ( any(psnOptions$mandatory) ) 94 | if (!(psnOptions$name[psnOptions$mandatory] %in% names(psnOpts) ) ) 95 | stop(paste("Mandatory option",psnOptions$name[psnOptions$mandatory], 96 | "is not present in the provided option list","\n")) 97 | 98 | if (length(checked)>0) { 99 | optList <- list(name = names(checked), 100 | value = as.character(checked), 101 | type = psnOptType[validArg]) 102 | 103 | list_to_PsNArgs(optList) 104 | } else return("") 105 | } 106 | -------------------------------------------------------------------------------- /tests/originals/1005.ctl: -------------------------------------------------------------------------------- 1 | $PROB 1005 phase1 2 CMT like 1004 but diff. initial on V3 2 | $INPUT C ID TIME SEQ=DROP EVID AMT DV SUBJ HOUR HEIGHT WT SEX AGE DOSE FED 3 | $DATA ../../data/derived/phase1.csv IGNORE=C 4 | $SUBROUTINE ADVAN4 TRANS4 5 | $PK 6 | CL=THETA(1)*EXP(ETA(1)) * THETA(6)**SEX * (WT/70)**THETA(7) 7 | V2 =THETA(2)*EXP(ETA(2)) 8 | KA=THETA(3)*EXP(ETA(3)) 9 | Q =THETA(4) 10 | V3=THETA(5) 11 | S2=V2 12 | 13 | $ERROR 14 | Y=F*(1+ERR(1)) + ERR(2) 15 | IPRE=F 16 | ; 17 | $THETA 18 | (0,10,50) ;CL clearance 19 | (0,10,100) ;V central volume 20 | (0,0.2, 5) ;KA absorption rate constant 21 | (0,10,50) ;Q intercompartmental clearance 22 | (0,100,1000) ;V3 peripheral volume 23 | (0,1,2) ;SEX male effect on clearance 24 | (0,0.75,3) ;WT on CL weight effect on clearance 25 | 26 | $OMEGA BLOCK(3) 27 | .1 28 | .01 .1 29 | .01 .01 .1 30 | 31 | ;interindividual variability on clearance 32 | ;interindividual clearance-volume covariance 33 | ;interindividual variability on central volume 34 | ;interindividual clearance-Ka covariance 35 | ;interindividual volume-Ka covariance 36 | ;interindividual variability on Ka 37 | 38 | $SIGMA 0.1 0.1 39 | 40 | ;proportional error 41 | ;additive error 42 | 43 | $ESTIMATION MAXEVAL=9999 PRINT=5 NOABORT METHOD=1 INTER MSFO=./1005.msf 44 | $COV PRINT=E 45 | $TABLE NOPRINT FILE=./1005.tab ONEHEADER ID AMT TIME EVID PRED IPRE CWRES 46 | $TABLE NOPRINT FILE=./1005par.tab ONEHEADER ID TIME CL Q V2 V3 KA ETA1 ETA2 ETA3 47 | 48 | ;apparent oral clearance 49 | ;central volume of distribution 50 | ;absorption rate constant 51 | ;intercompartmental clearance 52 | ;peripheral volume of distribution 53 | ;male effect on clearance 54 | ;weight effect on clearance 55 | ;interindividual variability of clearance 56 | ;interindividual clearance-volume covariance 57 | ;interindividual variability of central volume 58 | ;interindividual clearance-Ka covariance 59 | ;interindividual volume-Ka covariance 60 | ;interindividual variability of Ka 61 | ;proportional error 62 | ;additive error 63 | ; 64 | -------------------------------------------------------------------------------- /R/runModel.R: -------------------------------------------------------------------------------- 1 | #' Runs a complete workflow for a given Model Object 2 | #' 3 | #' @param modelFile NONMEM control stream file name (without extension) 4 | #' @param modelExtension NONMEM control stream file extension. Defaults to '.mod' 5 | #' @param addargs Additional PsN command line arguments (text string) 6 | #' @param working.dir Working directory containing control stream and where 7 | #' output files should be stored 8 | #' @param cleanup Whether to clean up additional NONMEM files and folders 9 | #' following estimation. Defaults to TRUE. 10 | #' @return NONMEM estimation output files 11 | #' @examples 12 | #' execute_PsN(modelFile='warfarin_PK_CONC_MKS', modelExtension='.ctl', 13 | #' working.dir='./data') 14 | #' 15 | #' 16 | runModel <- function(MOGobj, cleanup = T, diagnostics = T, VPC = F, 17 | bootstrap = F, runno = NULL, outFormat = NULL, 18 | templateModel = NULL, nsamp = 100, working.dir = NULL) { 19 | 20 | working.dir <- ifelse(is.null(working.dir), getwd(), working.dir) 21 | 22 | #' Initialise output list 23 | output <- as.list(NULL) 24 | 25 | #' Find the run number from the Tables statements sdtab etc. 26 | if (!length(runno) > 0) 27 | runno <- as.numeric(gsub("[a-z]", "", MOGobj$Table[1, "File"])) 28 | 29 | #' Create the run directory 30 | #' Copy the dataset into the run directory 31 | #' Change working directory to the run directory 32 | runpath <- file.path(getwd(), paste("Run", runno, sep = "")) 33 | dir.create(runpath) 34 | file.copy(MOGobj$Data[, "File"], file.path(runpath)) 35 | 36 | #' Using 'Run>' convention for temporary Run files 37 | ctlFilename <- paste("Run", runno, sep = "") 38 | fileNameRoot <- gsub("\\..*", "", ctlFilename) 39 | 40 | #' Writing out the new control stream 41 | writeControlText(templateModel = templateModel, parsedControl = MOGobj, modelFile = file.path(getwd(), 42 | ctlFilename)) 43 | 44 | #' estimate the model using PsN 45 | #' ------------------------- 46 | execute_PsN(modelFile = ctlFilename, 47 | psnOpts = list(retries = 3, tweak_inits = TRUE)) 48 | 49 | # #' Use RNMImport to read the output files 50 | outNM <- RNMImport::importNm(paste(ctlFilename, ".mod", sep = "")) 51 | output$RNMImport <- outNM 52 | #' Model diagnostics 53 | #' ------------------------- 54 | #' Here Xpose reads the NONMEM output from the run and creates an Xpose database object. 55 | 56 | #' If using png or PDF output then set up the filenaming convention 57 | #' Will be Run<>GOF<>.png or .pdf 58 | if (length(outFormat) > 0) { 59 | if (outFormat == "png") 60 | png(file = paste("Run", runno, "GOF", "%d.png", sep = "")) 61 | if (outFormat == "pdf") 62 | pdf(file = paste("Run", runno, "GOF", "%d.pdf", sep = "")) 63 | } 64 | basicGOF_Xpose() 65 | 66 | #' VPC simulation-based diagnostics using PsN 67 | #' ------------------------- 68 | #' `VPC_PsN` is a wrapper to PsN's VPC function and simply passes the appropriate argument through to PsN. 69 | #' Additional arguments for VPC using PsN can be passed as part of the `addargs` string. 70 | 71 | if (VPC) { 72 | VPC_PsN(modelFile = ctlFilename, seed = 123, ..., addargs = paste("--lst_file=", 73 | paste(fileNameRoot, ".lst", sep = ""), " --bin_by_count=0 --bin_array=0.125,0.375,0.75,1.25,1.75,2.5,4.5,7.5,10.5,18,30,42,60,84,108,125 --dir=VPCdir", 74 | sep = "")) 75 | cleanup(path = "VPCdir", remove.folders = T) 76 | 77 | #' Plotting the VPC using the xpose.VPC function in xpose. 78 | #' Call to xpose function xpose.VPC. 79 | if (length(outFormat) > 0) { 80 | if (outFormat == "png") 81 | png(file = paste("Run", runno, "VPC", "%d.png", sep = "")) 82 | if (outFormat == "pdf") 83 | pdf(file = paste("Run", runno, "VPC", "%d.pdf", sep = "")) 84 | } 85 | xpose.VPC(vpc.info = "./VPCdir/vpc_results.csv", vpctab = "./VPCdir/vpctab") 86 | } 87 | 88 | #' Bootstrap of the original model using PsN 89 | #' ------------------------- 90 | #' Similarly to `VPC_PsN` here we can use the bootstrap functionality in PsN directly. 91 | if (bootstrap) { 92 | bootstrap_PsN(modelFile = ctlFilename, seed = 123, addarg = "--dir=BSdir", 93 | ...) 94 | cleanup(path = "BSdir", remove.folders = T) 95 | 96 | #' Summarise bootstrap output i.e. pick out relevant numbers from raw_results...csv file. 97 | output$bootstrap <- bs.summary(fileName = "./BSdir/bootstrap_results.csv") 98 | } 99 | return(output) 100 | if (length(outFormat) > 0) 101 | graphics.off() 102 | } 103 | -------------------------------------------------------------------------------- /vignettes/Introduction_to_rspeaksnonmem.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Introduction to rspeaksnonmem" 3 | author: "Mike K Smith (Mike.K.Smith@Pfizer.com)" 4 | date: "`r Sys.Date()`" 5 | #output: rmarkdown::html_vignette 6 | output: html_notebook 7 | --- 8 | 9 | ```{r setup,echo=FALSE,results='hide',message=FALSE, warning=FALSE} 10 | devtools::load_all(pkg = ".") 11 | file.copy(from = file.path(system.file("exdata", package = "rspeaksnonmem"), 12 | "warfarin_conc_pca.csv"), 13 | to = getwd(), overwrite = T ) 14 | file.copy(from = file.path(system.file("exdata", package = "rspeaksnonmem"), 15 | "warfarin.ctl"), 16 | to = getwd(), overwrite = T ) 17 | file.rename(from = "warfarin.ctl", "run0.ctl") 18 | ``` 19 | 20 | In this notebook we will look at running NONMEM and PsN from R using the R 21 | package `rspeaksnonmem`. 22 | 23 | ### Overview 24 | 25 | This demo will show the following steps: 26 | 27 | - Running NONMEM and PsN 28 | - Integrating results into a Notebook. 29 | 30 | ### Step 1: Running NONMEM 31 | First, let's run a model and knit the results back into this notebook. Note 32 | that in the `command` argument to the function we specify the complete path to the 33 | NONMEM executable .bat file. This allows you to be very precise about which 34 | version of NONMEM you use. If the `clean` argument is non-zero it cleans up the 35 | working directory deleting all of the temporary NONMEM files, leaving only the 36 | output. 37 | 38 | ```{r RunNONMEM} 39 | estimate_NM(command = "c:/nm72/run/nmfe72.bat", 40 | modelFile = "run0.ctl", 41 | clean = 1) 42 | ``` 43 | 44 | ### Step 2: Summarise estimation: 45 | We can now use PsN command `sumo` to summarise the output. Note that here we 46 | are not using the `command` argument, but instead we specify the installation 47 | directory for Perl / PsN and which PsN version we are using. `rspeaksnonmem` 48 | will then create a command based on the directory, `sumo` and version information. 49 | 50 | ```{r callSumo} 51 | sumo_PsN(installPath = "c:/strawberry/perl", 52 | version = "4.7.0", 53 | lstFile = "run0.lst") 54 | ``` 55 | ### Step 3: Model Diagnostics 56 | Next, we might want to produce some model diagnostics using the R package 57 | `xpose4`. To do this, we need to create an Xpose database object and then 58 | create the diagnostic plots. Xpose needs the run number in order to pick up 59 | the $TABLE file outputs from NONMEM. 60 | 61 | ```{r setupXposeDiagnostics, warning=FALSE, message=FALSE} 62 | runno <- as.numeric(gsub("[a-z]", "", list.files(pattern = "^sdtab")[1])) 63 | 64 | ## ----createXpdb---------------------------------------------------------- 65 | xpdb <- xpose4::xpose.data(runno, quiet = T) 66 | # save(base.xpdb, file='Xpose database.RData') 67 | ``` 68 | 69 | #### DV vs PRED / IPRED 70 | ```{r dv.vs.pred.ipred, warning=FALSE, message=FALSE} 71 | print(xpose4::dv.vs.pred.ipred(xpdb)) 72 | ``` 73 | #### PRED vs IDV 74 | ```{r pred.vs.idv, warning=FALSE, message=FALSE} 75 | print(xpose4::pred.vs.idv(xpdb)) 76 | ``` 77 | 78 | #### PRED vs IDV 79 | ```{r ipred.vs.idv, warning=FALSE, message=FALSE} 80 | print(xpose4::ipred.vs.idv(xpdb)) 81 | ``` 82 | #### WRES vs IDV 83 | ```{r wres.vs.idv, warning=FALSE, message=FALSE} 84 | print(xpose4::wres.vs.idv(xpdb)) 85 | ``` 86 | #### WRES vs PRED 87 | ```{r wres.vs.pred, warning=FALSE, message=FALSE} 88 | print(xpose4::wres.vs.pred(xpdb)) 89 | ``` 90 | 91 | #### EBEs histogram 92 | ```{r ranpar.hist, warning=FALSE, message=FALSE} 93 | print(xpose4::ranpar.hist(xpdb)) 94 | ``` 95 | 96 | #### Individual Plots 97 | ```{r ind.plots, warning=FALSE, message=FALSE} 98 | print(xpose4::ind.plots(xpdb, layout = c(4, 4))) 99 | ``` 100 | 101 | ### Step 4: VPC diagnostisc 102 | We may also want to investigate simulation-based diagnostics using the PsN 103 | routine VPC. In the call to `VPC_PsN` we have specified the required arguments 104 | for VPC (samples, seed) but you can also pass additional arguments to the VPC 105 | routine by passing a name-value list to the argument `psnOpts`. `rspeaksnonmem` 106 | will check these arguments against the options for VPC and let you know if any 107 | are mis-specified. Here the argument `min_points_per_bin` is not a valid option 108 | for VPC. (The correct option is `min_points_**in**_bin`.) 109 | 110 | ```{r VPC_PsN} 111 | VPC_PsN( modelFile='run0.ctl', 112 | installPath = "c:/strawberry/perl", 113 | version = "4.7.0", 114 | working.dir='Run1_VPC', 115 | samples=100, seed='54321', 116 | psnOpts=list(lst='run0.lst', 117 | auto_bin = '5', 118 | min_points_per_bin = '2')) 119 | ``` 120 | 121 | and then use the Xpose function xpose_vpc to plot the result: 122 | ```{r plot_VPC} 123 | vpcdir <- "Run1_VPC" 124 | 125 | vpctab <- file.path(vpcdir,"vpctab") 126 | vpcinfo <- file.path(vpcdir,"vpc_results.csv") 127 | 128 | xpose4::xpose.VPC(vpc.info=vpcinfo, vpctab=vpctab) 129 | ``` -------------------------------------------------------------------------------- /R/utils.R: -------------------------------------------------------------------------------- 1 | #' utility functions used within the package 2 | #' 3 | #' 4 | win <- function() { 5 | .Platform$OS.type == "windows" 6 | } 7 | 8 | # A version of Sys.which that might work better in Windows. From 9 | # http://stackoverflow.com/questions/34030087/how-to-find-correct-executable-with-sys-which-on-windows 10 | Sys.which2 <- function(cmd) { 11 | stopifnot(length(cmd) == 1) 12 | if (.Platform$OS.type == "windows") { 13 | suppressWarnings({ 14 | pathname <- shell(sprintf("where %s 2> NUL", cmd), intern = TRUE)[1] 15 | }) 16 | if (!is.na(pathname)) 17 | return(setNames(pathname, cmd)) 18 | } 19 | Sys.which(cmd) 20 | } 21 | 22 | ## Convert key-value pairs to PsN argument list 23 | list_to_PsNArgs <- function(x) { 24 | x1 <- paste(x$name, x$value, sep = "=") 25 | x2 <- gsub("=TRUE", "", x1) 26 | x3 <- gsub("=FALSE","", x2) 27 | x3[x$type == "is.logical" & x$value == "FALSE"] <- 28 | paste("no-", x$name[x$type == "is.logical" & x$value == FALSE], sep = "") 29 | x4 <- x3[!(x$type == "" & x$value == FALSE)] 30 | x5 <- paste("-",x4,sep="") 31 | paste0(x5, collapse = " ") 32 | } 33 | 34 | ## Parse PsN command options list 35 | parse_PsN_options <- function(x){ 36 | psnArgs <- stringr::str_trim(x) 37 | 38 | firstArg <- grep("^\\[ -h", psnArgs) + 1 39 | lastArg <- grep("^Options enclosed", psnArgs) - 2 40 | 41 | psnArgs <- psnArgs[firstArg:lastArg] 42 | optional <- regexpr ("^\\[", psnArgs)>0 43 | mandatory <- regexpr("^--", psnArgs)>0 44 | psnArgs <- gsub("\\[", "", psnArgs) 45 | psnArgs <- gsub("\\]", "", psnArgs) 46 | psnArgs <- gsub("--", "", psnArgs) 47 | psnArgs <- gsub(" ", "", psnArgs) 48 | 49 | ## Check types 50 | psnArgs <- gsub("\\'string\\'", "is.character", psnArgs) ## character 51 | psnArgs <- gsub("\\'integer\\'", "is.wholenumber", psnArgs) ## wholenumber / integer 52 | psnArgs <- gsub("\\'number\\'", "is.double", psnArgs) ## double precision 53 | psnArgs <- gsub("!", "=is.logical", psnArgs) ## logical / boolean 54 | 55 | argName <- gsub("=.*", "", psnArgs) 56 | argType <- gsub(".*=", "", psnArgs) 57 | 58 | knownTypes <- c("is.character","is.wholenumber","is.double","is.logical") 59 | isKnown <- stringr::word(psnArgs,2,sep="=") %in% knownTypes 60 | argType[!isKnown] <- "!is.null" ## If complex type then ensure non-missing. 61 | ## Need to refactor this though to check PsN Options where >1 type is possible. 62 | 63 | names(argType) <- argName 64 | argType[argType == argName] <- "" 65 | 66 | psnArgs <- data.frame(name = argName, 67 | type = argType, 68 | optional = optional, 69 | mandatory = mandatory, 70 | stringsAsFactors=F) 71 | return(psnArgs) 72 | } 73 | 74 | ## -- from metrumrg runCommand.R 75 | execute <- function(command,minimized = FALSE, invisible = TRUE) { 76 | args <- list(command = command) 77 | if (win()) 78 | args <- c(args, list(minimized = minimized, invisible = invisible)) 79 | # cat(command, file=file.path(rdir,glue(run,'.cat')),sep='\n',append=TRUE) 80 | result <- tryCatch(do.call(system, args), error = function(e) warning(e$message, 81 | call. = FALSE, immediate. = TRUE)) 82 | # if (is.integer(result)) result <- paste('Run',run,'has exit code',result) 83 | # cat(result,file=file.path(rdir,glue(run,'.cat')),sep='\n',append=TRUE) 84 | return(result) #visible 85 | } 86 | 87 | #' ---cleanup: function to remove NONMEM cruft. 88 | #' Based on Andy Hooker's cleanup.R function https://github.com/andrewhooker/MBAOD/blob/master/R/cleanup.R 89 | cleanup <- function(working.dir = NULL, pattern = NULL, remove.folders = F, ...) { 90 | 91 | working.dir <- ifelse(is.null(working.dir), getwd(), working.dir) 92 | 93 | print("- Cleaning up..") 94 | 95 | # remove old files before new run 96 | files <- c("xml", "_L", "_R", "INTER", "LINK", "nul", "nmprd4p.mod", "FCON", 97 | ".exe", "FDATA", "FMSG", "fort.6", "FREPORT", "FSIZES", "FSTREAM", "FSUBS", 98 | "fsubs.f90", "fsubs.o", "FSUBS.MU.F90", "GFCOMPILE.BAT", "linkc", "nmfe72", 99 | "set", "newline", "gfortran", "prsizes", "trash", "compile", "matlab", "garbage.out") 100 | if (length(pattern) > 0) 101 | files <- c(files, pattern) 102 | 103 | foo <- sapply(files, function(x) unlink(file.path(working.dir, dir(pattern = x)))) 104 | unlink(file.path(working.dir, "temp_dir"), recursive = T) 105 | 106 | # remove PsN folders 107 | if (remove.folders) { 108 | all <- list.files(all.files = F, full.names = T) 109 | alldirs <- all[file.info(all)$isdir] 110 | matchdirs <- alldirs 111 | if (length(pattern) > 0) 112 | matchdirs <- alldirs[grep(pattern, alldirs)] 113 | unlink(matchdirs, recursive = T, force = T) 114 | } 115 | } 116 | 117 | is.wholenumber <- function(x, tol = .Machine$double.eps^0.5) abs(x - round(x)) < 118 | tol 119 | 120 | check.executable <- function(x){ 121 | tools::file_ext(x) %in% c("bat","exe","pl") 122 | } -------------------------------------------------------------------------------- /R/extractNMObjects.R: -------------------------------------------------------------------------------- 1 | ## ---getNMBlocks: identifies the various blocks of a NONMEM control stream 2 | getNMBlocks <- function(RNMImportObject) { 3 | Raw <- RNMImportObject$Raw 4 | blocks <- grep("\\$", Raw) 5 | nextBlock <- c(blocks[-1], length(Raw)) 6 | ## Drop commented out lines blocks<-blocks[-grep('[;]',blocks)] Get first 'word' 7 | ## to determine order 8 | blocks2 <- sub(" +.*", "", Raw[blocks]) 9 | blocks3 <- sub("$", "", blocks2, fixed = T) 10 | data.frame(Blocks = blocks2, Search = blocks3, firstRow = blocks, nextBlockRow = nextBlock) 11 | } 12 | 13 | ## ---getNMDataObjects: Reads the $DATA and $INPUT records and parses them 14 | getNMDataObjects <- function(RNMImportObject, problemNo = 1) { 15 | Raw <- RNMImportObject$Raw 16 | Parsed <- RNMImportObject$problemContents[[problemNo]] 17 | 18 | blockInfo <- getNMBlocks(RNMImportObject) 19 | ## What rows correspond to each parameter type 20 | rowsData <- data.frame(blockInfo[grep("DAT", as.character(blockInfo$Search)), 21 | c("firstRow", "nextBlockRow")], row.names = NULL) 22 | rowsInput <- data.frame(blockInfo[grep("INP", as.character(blockInfo$Search)), 23 | c("firstRow", "nextBlockRow")], row.names = NULL) 24 | 25 | ## Extract DATA rows 26 | rawDataRows <- NULL 27 | if (length(grep("DAT", as.character(blockInfo$Search))) > 0) { 28 | rawDataRows <- apply(rowsData, 1, function(x) Raw[x[1]:(x[2] - 1)]) 29 | } 30 | 31 | ## Extract INPUT rows 32 | rawInputRows <- NULL 33 | if (length(grep("OME", as.character(blockInfo$Search))) > 0) { 34 | rawInputRows <- apply(rowsInput, 1, function(x) Raw[x[1]:(x[2] - 1)]) 35 | } 36 | 37 | RAW <- unlist(c(rawInputRows, rawDataRows)) 38 | if (length(grep("^\\;", RAW)) > 0) { 39 | RAW <- RAW[-grep("^\\;", RAW)] 40 | } 41 | 42 | list(RAW = RAW, INPUT = Parsed$Input, DATA = Parsed$Data) 43 | } 44 | 45 | ## ---getNMParameterObjects: Reads the $THETA, $OMEGA, $SIGMA records and parses 46 | ## them 47 | getNMParameterObjects <- function(RNMImportObject, problemNo = 1) { 48 | Raw <- RNMImportObject$Raw 49 | Parsed <- RNMImportObject$problemContents[[problemNo]] 50 | 51 | blockInfo <- getNMBlocks(RNMImportObject) 52 | 53 | ## What rows correspond to each parameter type 54 | rowsTheta <- data.frame(blockInfo[grep("THE", as.character(blockInfo$Search)), 55 | c("firstRow", "nextBlockRow")], row.names = NULL) 56 | rowsOmega <- data.frame(blockInfo[grep("OME", as.character(blockInfo$Search)), 57 | c("firstRow", "nextBlockRow")], row.names = NULL) 58 | rowsSigma <- data.frame(blockInfo[grep("SIG", as.character(blockInfo$Search)), 59 | c("firstRow", "nextBlockRow")], row.names = NULL) 60 | 61 | ## Extract THETA rows (if there are any) 62 | rawThetaRows <- NULL 63 | if (length(grep("THE", as.character(blockInfo$Search))) > 0) { 64 | rawThetaRows <- apply(rowsTheta, 1, function(x) Raw[x[1]:(x[2] - 1)]) 65 | } 66 | 67 | ## Extract OMEGA rows (if there are any) 68 | rawOmegaRows <- NULL 69 | if (length(grep("OME", as.character(blockInfo$Search))) > 0) { 70 | rawOmegaRows <- apply(rowsOmega, 1, function(x) Raw[x[1]:(x[2] - 1)]) 71 | } 72 | 73 | ## Extract SIGMA rows (if there are any) 74 | rawSigmaRows <- NULL 75 | if (length(grep("SIG", as.character(blockInfo$Search))) > 0) { 76 | rawSigmaRows <- apply(rowsSigma, 1, function(x) Raw[x[1]:(x[2] - 1)]) 77 | } 78 | 79 | RAW <- unlist(c(rawThetaRows, rawOmegaRows, rawSigmaRows)) 80 | if (length(grep("^\\;", RAW)) > 0) { 81 | RAW <- RAW[-grep("^\\;", RAW)] 82 | } 83 | 84 | list(RAW = RAW, THETA = Parsed$Theta, OMEGA = Parsed$Omega, SIGMA = Parsed$Sigma) 85 | } 86 | 87 | ## ---getNMTaskProperties: Reads the $EST, $COV, $TAB records and parses them 88 | getNMTaskPropertiesObjects <- function(RNMImportObject, problemNo = 1) { 89 | Raw <- RNMImportObject$Raw 90 | Parsed <- RNMImportObject$problemContents[[problemNo]] 91 | 92 | blockInfo <- getNMBlocks(RNMImportObject) 93 | 94 | ## What rows correspond to each parameter type 95 | rowsEST <- data.frame(blockInfo[grep("EST", as.character(blockInfo$Search)), 96 | c("firstRow", "nextBlockRow")], row.names = NULL) 97 | rowsTAB <- data.frame(blockInfo[grep("TAB", as.character(blockInfo$Search)), 98 | c("firstRow", "nextBlockRow")], row.names = NULL) 99 | rowsCOV <- data.frame(blockInfo[grep("COV", as.character(blockInfo$Search)), 100 | c("firstRow", "nextBlockRow")], row.names = NULL) 101 | 102 | ## Extract EST rows (if there are any) 103 | rawEstRows <- NULL 104 | if (length(grep("EST", as.character(blockInfo$Search))) > 0) { 105 | rawEstRows <- apply(rowsEST, 1, function(x) Raw[x[1]:if (x[2] > x[1]) 106 | (x[2] - 1) else (x[2])]) 107 | } 108 | 109 | ## Extract TAB rows (if there are any) 110 | rawTabRows <- NULL 111 | if (length(grep("TAB", as.character(blockInfo$Search))) > 0) { 112 | rawTabRows <- apply(rowsTAB, 1, function(x) Raw[x[1]:if (x[2] > x[1]) 113 | (x[2] - 1) else (x[2])]) 114 | } 115 | 116 | ## Extract COV rows (if there are any) 117 | rawCovRows <- NULL 118 | if (length(grep("COV", as.character(blockInfo$Search))) > 0) { 119 | rawCovRows <- apply(rowsCOV, 1, function(x) Raw[x[1]:if (x[2] > x[1]) 120 | (x[2] - 1) else (x[2])]) 121 | } 122 | 123 | RAW <- unlist(c(rawEstRows, rawTabRows, rawCovRows)) 124 | 125 | if (length(grep("^\\;", RAW)) > 0) { 126 | RAW <- RAW[-grep("^\\;", RAW)] 127 | } 128 | 129 | list(RAW = RAW, ESTIMATES = Parsed$Estimates, COV = Parsed$Cov, TABLES = Parsed$Tables) 130 | } 131 | -------------------------------------------------------------------------------- /vignettes/using_rspeaksnonmem_to_run_NONMEM_and_PsN.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Using rspeaksnonmem to run NONMEM & PsN" 3 | author: "Mike K Smith (Mike.K.Smith@Pfizer.com)" 4 | date: "`r Sys.Date()`" 5 | # output: rmarkdown::html_vignette 6 | # vignette: > 7 | # %\VignetteIndexEntry{Vignette Title} 8 | # %\VignetteEngine{knitr::rmarkdown} 9 | # %\VignetteEncoding{UTF-8} 10 | output: html_notebook 11 | --- 12 | 13 | ```{r setKnitrOptions, echo=FALSE,} 14 | library(knitr) 15 | opts_chunk$set(fig.width=6, fig.height=6) 16 | ``` 17 | `rspeaksnonmem` is designed to allow the user to craft workflows based on a 18 | given NONMEM model. 19 | 20 | `rspeaksnonmem` allows the user to run NONMEM models from R either directly 21 | running the nmfe.bat or by 22 | calling [Perl speaks NONMEM](http://psn.sourceforge.net) (PsN) functions like 23 | "execute". Other PsN functions can be run from R - VPC (Visual Predictive Check), 24 | bootstrap, SSE (Stochastic Simulation and Estimation). 25 | 26 | This allows the user to define sequences of pharmacometrics workflow tasks via 27 | R within a single R script. This increases traceability and reproducibility of 28 | workflow. 29 | 30 | ```{r setup,echo = FALSE, results = 'hide', message = FALSE, warning = FALSE} 31 | devtools::load_all(pkg=".") 32 | devtools::load_all(pkg = "C:\\Users\\smith_mk\\Documents\\Working documents\\RNMImport") 33 | 34 | getwd() 35 | 36 | file.copy(from = file.path(system.file("inst/exdata/", package="rspeaksnonmem"), 37 | "warfarin_conc_pca.csv"), 38 | to = getwd(), overwrite = T ) 39 | file.copy(from = file.path(system.file("inst/exdata", package="rspeaksnonmem"), 40 | "warfarin.ctl"), 41 | to = getwd(), overwrite = T ) 42 | 43 | ``` 44 | 45 | ### Running NONMEM 46 | `estimate_NM` runs NONMEM for a given model file. Note 47 | that in the `command` argument to the function we specify the complete path to the 48 | NONMEM executable .bat file. This allows you to be very precise about which 49 | version of NONMEM you use. If the `clean` argument is non-zero it cleans up the 50 | working directory deleting all of the temporary NONMEM files, leaving only the 51 | output. 52 | 53 | ```{r NONMEM , message = FALSE, warning = FALSE} 54 | estimate_NM(modelFile = "warfarin.ctl", 55 | command = "c:/nm72/run/nmfe72.bat", 56 | clean = 1) 57 | ``` 58 | 59 | ### Running PsN 60 | We can now use PsN command `sumo` to summarise the output. Note that here we 61 | are not using the `command` argument, but instead we specify the installation 62 | directory for Perl / PsN and which PsN version we are using. `rspeaksnonmem` 63 | will then create a command based on the directory, `sumo` and version information. 64 | 65 | ```{r callSumo} 66 | sumo_PsN(installPath = "c:/strawberry/perl", 67 | version = "4.6.0", 68 | lstFile = "warfarin.lst") 69 | ``` 70 | 71 | ### Different ways of specifying the command to be run 72 | The `defineExecutable` function used by `estimate_NM` and PsN calling 73 | functions can search for user-specified command to find valid executables at 74 | the system prompt. If you supply the command with no file path with 75 | searchCommand=T then the function uses `Sys.which` or `Sys.which2` (depending 76 | on OS) to search the system PATH or shortcut definitions for executables. 77 | 78 | ```{r defineExecutable_with_command } 79 | defineExecutable(command = "R", searchCommand = T) 80 | ``` 81 | 82 | If you specify the `tool` and the `installPath`, then `defineExecutables` looks 83 | within the `installPath` directory for executables that match the tool name. 84 | 85 | ```{r defineExecutable2} 86 | defineExecutable(tool = "nonmem", installPath = "c:/nm72", searchCommand = T) 87 | ``` 88 | 89 | Note that for PsN there could are a few ways of invoking the routine. 90 | ```{r defineExecutable3} 91 | defineExecutable(tool = "vpc", 92 | installPath = "c:/strawberry/perl", 93 | searchCommand = T) 94 | ``` 95 | 96 | In the `rspeaksnonmem` calls to PsN routines we explicitly tie the Perl script 97 | to the "parent" Perl executable. We use the version number Perl script so that 98 | it's clear to anyone looking at the command which version of the Perl script 99 | has been used and the Perl executable associated with it. 100 | 101 | ```{r defineExecutable4} 102 | defineExecutable(tool = "vpc", 103 | installPath = "c:/strawberry/perl", 104 | version = "4.7.0") 105 | ``` 106 | 107 | ### Validating PsN option lists 108 | `rspeaksnonmem` has functionality to check that the name-value pairs specified 109 | in the psnOpts arguments of the PsN calling functions are appropriately named 110 | and have valid argument types for use with PsN. We do this by checking against 111 | the routines' `-h` help files. 112 | 113 | ```{r} 114 | psnOpts <- list(picky = "yes", ## retries option should be numeric 115 | auto_bin = 4, ## auto_bin is not a valid option for execute 116 | dir = getwd()) 117 | 118 | validate_PsN_options(tool = "execute", 119 | installPath = "c:/strawberry/perl", 120 | version = "4.6.0", 121 | psnOpts = psnOpts) 122 | ``` 123 | 124 | ### Calling PsN 125 | `rspeaksnonmem` has PsN call functions for the following routines: 126 | 127 | - `execute` 128 | - `sumo` 129 | - `vpc` 130 | - `bootstrap` 131 | - `sse` 132 | - `runrecord` 133 | 134 | ### Other PsN functionality 135 | Although functions have been provided as wrappers to the PsN functions, it is 136 | easy to extend these to any other PsN function using the function callPsN. 137 | 138 | ``` 139 | linearize-4.7.0 warfarin.ctl -dir=linearize 140 | ``` 141 | 142 | ```{r other_PsN, echo = FALSE} 143 | callPsN(tool = "linearize", 144 | installPath = "c:/strawberry/perl", 145 | version = "4.7.0", 146 | file = "warfarin.ctl") 147 | ``` 148 | -------------------------------------------------------------------------------- /R/defineExecutable.R: -------------------------------------------------------------------------------- 1 | #' Finds the appropriate command line for execution 2 | #' 3 | #' @param tool Name of tool e.g. NONMEM, VPC, bootstrap, SSE etc. 4 | #' @param command Command which will be executed at a shell prompt 5 | #' e.g. execute-3.5.4 or nmfe72.bat. 6 | #' Use this instead of tool + installInfo to specify precisely what command to 7 | #' run at the shell prompt. 8 | #' @param installPath Path to the installation of NONMEM or PsN 9 | #' @param searchCommand (Boolean) Whether to search for .bat or .exe files 10 | #' matching the command. 11 | #' @return path to the executable (.bat file on Windows or command on other 12 | #' platforms) 13 | #' @details defineExecutable can help the user find the correct command line for 14 | #' use with `system( )`. 15 | #' rspeaksnonmem contains a named list called installedSoftware that includes 16 | #' installation path and command line for commonly used software (NONMEM, 17 | #' PsN commands). 18 | #' 19 | #' The user can specify the command line explicitly in each function 20 | #' e.g. `execute_PsN(command='c:/perl516/bin/execute.bat',...)` 21 | #' but defineExecutable provides an automated means to construct that command 22 | #' line. 23 | #' @note * Using the 'command' option instead of specifying 'tool' and 24 | #' 'installInfo' will perform a check 25 | #' of whether the command is valid using the R function Sys.which. 26 | #' * Using the searchCommand option may return more than one executable. It is 27 | #' recommended to run defineExecutable with searchCommand = TRUE to determine 28 | #' which executable is suitable for use 29 | #' BEFORE using this option in estimate_NM or PsN execution functions. 30 | #' @examples 31 | #' defineExecutable(tool='NONMEM', installInfo=installedSoftware) 32 | #' defineExecutable(command='execute', searchCommand=F) 33 | #' defineExecutable(installPath='c:/nm72/', command='nmfe72', searchCommand=T) 34 | #' do.call(system,args=list(command=defineExecutable(command='execute-3.5.4'))) 35 | #' @export 36 | 37 | defineExecutable <- function(tool = NULL, 38 | version = NULL, 39 | command = NULL, 40 | installPath = NULL, 41 | searchCommand = FALSE, ...) { 42 | 43 | if(is.null(tool) && is.null(command)) stop("One of tool or command must be specified") 44 | 45 | ## If the user wants to search for possible executables then one of command 46 | ## or tool + installPath must be given. 47 | if (searchCommand){ 48 | # If the user supplies the command with no file path with searchCommand=T 49 | # then use Sys.which or Sys.which2 (depending on OS) to search PATH for 50 | # executables. 51 | if(!is.null(command) && dirname(command)==".") { 52 | command <- ifelse(win(), Sys.which2(command), Sys.which(command)) 53 | } 54 | # If the user supplies command with full file path then search within the 55 | # file path for the command. 56 | if(!is.null(command) && dirname(command)!=".") { 57 | allMatches <- dir(dirname(command),basename(command),recursive = T,full.names = T) 58 | isValidExecutable <- check.executable(allMatches) 59 | command <- allMatches[isValidExecutable] 60 | } 61 | # If the user does not supply a command, but supplies tool + installPath 62 | # then search within the installPath for matching executables. 63 | if(is.null(command) && !is.null(tool) && !is.null(installPath)) { 64 | allMatches <- dir(installPath, tool, recursive = T, full.names=T) 65 | isValidExecutable <- check.executable(allMatches) 66 | command <- allMatches[isValidExecutable] 67 | } 68 | if (length(command)==0) stop("No matches found for the provided command or tool") 69 | } else { 70 | ## If the user provides the command and is NOT using searchCommand then 71 | ## we assume that they have given a valid command including the full file path 72 | ## to the executable OR they have a shortcut defined via the PATH variables. 73 | if (!is.null(command)) command <- command 74 | 75 | ## if the user has specified a tool they must also specify the installPath 76 | if (is.null(command) && !is.null(tool)){ 77 | if (is.null(installPath)) stop("If using tool, please specify an installPath") 78 | if (is.null(version)) stop("If using tool, please specify a version") 79 | 80 | # Combine installPath, tool and version to infer likely command. 81 | # IF NONMEM then paste installPath, "run","nmfe" version without "." and ".bat" 82 | if (casefold(tool, upper = T) == "NONMEM"){ 83 | if (is.null(version)){ 84 | stop("Require a version number for NONMEM to create nmfe executable") 85 | } else { 86 | command <- file.path(installPath, 87 | "run", 88 | paste("nmfe", 89 | gsub("\\.","",version), 90 | ".bat", 91 | sep="") 92 | ) 93 | } 94 | } else { 95 | # If the user specifies a version number then assume that they want to 96 | # call the version identified perl script within installPath/bin. 97 | # We make the assumption that they will also want to use the perl version 98 | # within the installPath/bin. 99 | # Using the versioned .bat file would make assumptions about Perl being 100 | # on the PATH and that this version matches the version to be used with 101 | # the perl script. 102 | if(!is.null(version)){ 103 | command <- paste( 104 | file.path(installPath, 105 | "bin", 106 | "perl"), 107 | file.path(installPath, 108 | "bin", 109 | paste(tool, 110 | "-", 111 | version, 112 | ".pl", 113 | sep="") 114 | ) 115 | ) 116 | } else { 117 | # If PsN and no version given then we assume the user will want to call 118 | # the .bat scripts within the Perl installation. 119 | command <- file.path(installPath, 120 | "bin", 121 | paste(tool, 122 | ".bat", 123 | sep="") 124 | ) 125 | } 126 | } 127 | } 128 | } 129 | return(command) 130 | } 131 | -------------------------------------------------------------------------------- /inst/exdata/THEO.DAT: -------------------------------------------------------------------------------- 1 | 1 79.6 4.02 0 . 1 2 | 1 79.6 . 0 0.74 0 3 | 1 79.6 . 0.25 2.84 0 4 | 1 79.6 . 0.57 6.57 0 5 | 1 79.6 . 1.12 10.5 0 6 | 1 79.6 . 2.02 9.66 0 7 | 1 79.6 . 3.82 8.58 0 8 | 1 79.6 . 5.1 8.36 0 9 | 1 79.6 . 7.03 7.47 0 10 | 1 79.6 . 9.05 6.89 0 11 | 1 79.6 . 12.12 5.94 0 12 | 1 79.6 . 24.37 3.28 0 13 | 2 72.4 4.4 0 . 1 14 | 2 72.4 . 0 0 0 15 | 2 72.4 . 0.27 1.72 0 16 | 2 72.4 . 0.52 7.91 0 17 | 2 72.4 . 1 8.31 0 18 | 2 72.4 . 1.92 8.33 0 19 | 2 72.4 . 3.5 6.85 0 20 | 2 72.4 . 5.02 6.08 0 21 | 2 72.4 . 7.03 5.4 0 22 | 2 72.4 . 9 4.55 0 23 | 2 72.4 . 12 3.01 0 24 | 2 72.4 . 24.3 0.9 0 25 | 3 70.5 4.53 0 . 1 26 | 3 70.5 . 0 0 0 27 | 3 70.5 . 0.27 4.4 0 28 | 3 70.5 . 0.58 6.9 0 29 | 3 70.5 . 1.02 8.2 0 30 | 3 70.5 . 2.02 7.8 0 31 | 3 70.5 . 3.62 7.5 0 32 | 3 70.5 . 5.08 6.2 0 33 | 3 70.5 . 7.07 5.3 0 34 | 3 70.5 . 9 4.9 0 35 | 3 70.5 . 12.15 3.7 0 36 | 3 70.5 . 24.17 1.05 0 37 | 4 72.7 4.4 0 . 1 38 | 4 72.7 . 0 0 0 39 | 4 72.7 . 0.35 1.89 0 40 | 4 72.7 . 0.6 4.6 0 41 | 4 72.7 . 1.07 8.6 0 42 | 4 72.7 . 2.13 8.38 0 43 | 4 72.7 . 3.5 7.54 0 44 | 4 72.7 . 5.02 6.88 0 45 | 4 72.7 . 7.02 5.78 0 46 | 4 72.7 . 9.02 5.33 0 47 | 4 72.7 . 11.98 4.19 0 48 | 4 72.7 . 24.65 1.15 0 49 | 5 54.6 5.86 0 . 1 50 | 5 54.6 . 0 0 0 51 | 5 54.6 . 0.3 2.02 0 52 | 5 54.6 . 0.52 5.63 0 53 | 5 54.6 . 1 11.4 0 54 | 5 54.6 . 2.02 9.33 0 55 | 5 54.6 . 3.5 8.74 0 56 | 5 54.6 . 5.02 7.56 0 57 | 5 54.6 . 7.02 7.09 0 58 | 5 54.6 . 9.1 5.9 0 59 | 5 54.6 . 12 4.37 0 60 | 5 54.6 . 24.35 1.57 0 61 | 6 80 4 0 . 1 62 | 6 80 . 0 0 0 63 | 6 80 . 0.27 1.29 0 64 | 6 80 . 0.58 3.08 0 65 | 6 80 . 1.15 6.44 0 66 | 6 80 . 2.03 6.32 0 67 | 6 80 . 3.57 5.53 0 68 | 6 80 . 5 4.94 0 69 | 6 80 . 7 4.02 0 70 | 6 80 . 9.22 3.46 0 71 | 6 80 . 12.1 2.78 0 72 | 6 80 . 23.85 0.92 0 73 | 7 64.6 4.95 0 . 1 74 | 7 64.6 . 0 0.15 0 75 | 7 64.6 . 0.25 0.85 0 76 | 7 64.6 . 0.5 2.35 0 77 | 7 64.6 . 1.02 5.02 0 78 | 7 64.6 . 2.02 6.58 0 79 | 7 64.6 . 3.48 7.09 0 80 | 7 64.6 . 5 6.66 0 81 | 7 64.6 . 6.98 5.25 0 82 | 7 64.6 . 9 4.39 0 83 | 7 64.6 . 12.05 3.53 0 84 | 7 64.6 . 24.22 1.15 0 85 | 8 70.5 4.53 0 . 1 86 | 8 70.5 . 0 0 0 87 | 8 70.5 . 0.25 3.05 0 88 | 8 70.5 . 0.52 3.05 0 89 | 8 70.5 . 0.98 7.31 0 90 | 8 70.5 . 2.02 7.56 0 91 | 8 70.5 . 3.53 6.59 0 92 | 8 70.5 . 5.05 5.88 0 93 | 8 70.5 . 7.15 4.73 0 94 | 8 70.5 . 9.07 4.57 0 95 | 8 70.5 . 12.1 3 0 96 | 8 70.5 . 24.12 1.25 0 97 | 9 86.4 3.1 0 . 1 98 | 9 86.4 . 0 0 0 99 | 9 86.4 . 0.3 7.37 0 100 | 9 86.4 . 0.63 9.03 0 101 | 9 86.4 . 1.05 7.14 0 102 | 9 86.4 . 2.02 6.33 0 103 | 9 86.4 . 3.53 5.66 0 104 | 9 86.4 . 5.02 5.67 0 105 | 9 86.4 . 7.17 4.24 0 106 | 9 86.4 . 8.8 4.11 0 107 | 9 86.4 . 11.6 3.16 0 108 | 9 86.4 . 24.43 1.12 0 109 | 10 58.2 5.5 0 . 1 110 | 10 58.2 . 0 0.24 0 111 | 10 58.2 . 0.37 2.89 0 112 | 10 58.2 . 0.77 5.22 0 113 | 10 58.2 . 1.02 6.41 0 114 | 10 58.2 . 2.05 7.83 0 115 | 10 58.2 . 3.55 10.21 0 116 | 10 58.2 . 5.05 9.18 0 117 | 10 58.2 . 7.08 8.02 0 118 | 10 58.2 . 9.38 7.14 0 119 | 10 58.2 . 12.1 5.68 0 120 | 10 58.2 . 23.7 2.42 0 121 | 11 65 4.92 0 . 1 122 | 11 65 . 0 0 0 123 | 11 65 . 0.25 4.86 0 124 | 11 65 . 0.5 7.24 0 125 | 11 65 . 0.98 8 0 126 | 11 65 . 1.98 6.81 0 127 | 11 65 . 3.6 5.87 0 128 | 11 65 . 5.02 5.22 0 129 | 11 65 . 7.03 4.45 0 130 | 11 65 . 9.03 3.62 0 131 | 11 65 . 12.12 2.69 0 132 | 11 65 . 24.08 0.86 0 133 | 12 60.5 5.3 0 . 1 134 | 12 60.5 . 0 0 0 135 | 12 60.5 . 0.25 1.25 0 136 | 12 60.5 . 0.5 3.96 0 137 | 12 60.5 . 1 7.82 0 138 | 12 60.5 . 2 9.72 0 139 | 12 60.5 . 3.52 9.75 0 140 | 12 60.5 . 5.07 8.57 0 141 | 12 60.5 . 7.07 6.59 0 142 | 12 60.5 . 9.03 6.11 0 143 | 12 60.5 . 12.05 4.57 0 144 | 12 60.5 . 24.15 1.17 0 145 | -------------------------------------------------------------------------------- /vignettes/using_rspeaksnonmem_to_modify_NONMEM_control_streams.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Using rspeaksnonmem to modify NONMEM control streams" 3 | author: "Mike K Smith (Mike.K.Smith@Pfizer.com)" 4 | date: "`r Sys.Date()`" 5 | # output: rmarkdown::html_vignette 6 | # vignette: > 7 | # %\VignetteIndexEntry{Vignette Title} 8 | # %\VignetteEngine{knitr::rmarkdown} 9 | # %\VignetteEncoding{UTF-8} 10 | output: html_notebook 11 | --- 12 | `rspeaksnonmem` is designed to allow the user to craft workflows based on a 13 | given NONMEM model. 14 | 15 | For more information on how to use `rspeaksnonmem` to run NONMEM and PsN please 16 | review the vignette "Introduction to `rspeaksnonmem`". 17 | 18 | After importing and parsing a control stream to an R object using the 19 | `RNMImport` package, `rspeaksnonmem` allows the user to easily change initial 20 | estimates, change data attributes or change task properties (estimation or 21 | simulation settings) without having to change the model. This saves a lot of 22 | textual searching by the user. The resulting data, parameter, 23 | model and task information is then written back out to file using an existing 24 | (possibly the original) model as a template. This ensures that the written 25 | NONMEM control stream mirrors as closely as possible the structure of the 26 | original file. 27 | 28 | ## Installation 29 | 30 | ### Dependencies 31 | 32 | `rspeaksnonmem` relies on the package [`RNMImport`](https://github.com/MikeKSmith/RNMImport) 33 | function `importNmMod` which reads and parses the NONMEM control stream. 34 | `rspeaksnonmem` then works with the data, parameter values, and task information 35 | separately from the model. 36 | 37 | Install RNMIMport from Github using the `devtools` package. `rspeaksnonmem` 38 | requires the version of RNMImport on MikeKSmith's Github repository which 39 | includes handling of OMEGA and SIGMA blocks and identifying which elements are 40 | fixed for these parameters. 41 | 42 | ```{r install_RNMImport, eval = FALSE} 43 | #devtools::install_git("MikeKSmith/RNMImport") 44 | ``` 45 | 46 | ### Install rspeaksnonmem 47 | Eventually, `rspeaksnonmem` will be released to CRAN, but while still in 48 | development `rspeaksnonmem` can most easily be installed from GitHub using the 49 | `devtools` package: 50 | 51 | ```{r install_rspeaksnonmem, include=F} 52 | #devtools::install_github("MikeKSmith/rspeaksnonmem") 53 | ``` 54 | 55 | 56 | ```{r,echo=FALSE,results='hide',message=FALSE} 57 | devtools::load_all(pkg = ".") 58 | devtools::load_all(pkg = "C:\\Users\\smith_mk\\Documents\\Working documents\\RNMImport") 59 | ``` 60 | 61 | Load the `rspeaksnonmem` package 62 | ```{r, include=FALSE, echo=FALSE} 63 | #library(rspeaksnonmem) 64 | ``` 65 | 66 | Copy an example dataset and model to a directory of your choice 67 | 68 | ```{r,results='hide',echo=T} 69 | getwd() 70 | 71 | file.copy(from = file.path(system.file("exdata", package="rspeaksnonmem"),"warfarin_conc_pca.csv"), 72 | to = getwd(), overwrite=T ) 73 | file.copy(from = file.path(system.file("exdata", package="rspeaksnonmem"),"warfarin.ctl"), 74 | to = getwd(), overwrite=T ) 75 | ``` 76 | 77 | The initial model within the workflow should act as a "template" for 78 | modifications. The best practice is to use a model where all possible parameters 79 | are defined (including OMEGAs and covariances / correlations) but where it is 80 | possible to fix parameters to zero or some null value. We can then run and test 81 | a wide variety of models simply by updating the $THETA, $OMEGA and $SIGMA 82 | parameters to allow estimation. 83 | 84 | ## Read the control stream using RNMImport 85 | First, we need to read the NONMEM control stream into R using the importNmMod 86 | function of RNMImport. 87 | ```{r readControlStream} 88 | warfModel <- importNmMod("warfarin.ctl") 89 | class(warfModel) 90 | names(warfModel) 91 | ``` 92 | 93 | This creates a list of R objects containing the Raw NONMEM control stream as a 94 | vector of characters: 95 | ```{r viewRawNM} 96 | warfBaseRaw <- warfModel$Raw 97 | cat(warfModel$Raw, sep="\n") 98 | ``` 99 | 100 | It also creates a parsed list of control statements in the controlFile slot: 101 | ```{r viewParsedNM} 102 | warfTemplateModel <- warfModel$problemContents[[1]] 103 | warfModel$problemContents[[1]] 104 | ``` 105 | 106 | Using `rspeaksnonmem` the user can then update elements of the model using this 107 | parsed set of commands. `rspeaksnonmem` provides some additional functions to 108 | extract certain elements of the parsed control stream. 109 | 110 | 111 | "Object" | `rspeaksnonmem` Function | NMTRAN blocks 112 | ---------|---------------------------|----------------------------- 113 | Data | getNMDataObjects | `$DATA`, `$INPUT` 114 | Parameter| getNMParameterObjects | `$THETA`, `$OMEGA`, `$SIGMA` 115 | Task | getNMTaskPropertiesObjects| `$EST`,`$COV`, `$TAB` 116 | Model | getNMModelObjects | everything else 117 | 118 | 119 | For example: `getNMParameterObjects` returns the `$THETA`, `$OMEGA` and `$SIGMA` 120 | records. Since the `THETA` parameters are represented as a data frame, we can 121 | easily update the initial values, lower or upper bounds, fix or estimate (unfix) 122 | `THETA` parameters. With each object returned by the various `getNM<...>` 123 | functions we get not only the parsed objects but the raw control stream as well. 124 | 125 | NOTE: Generally speaking, `rspeaksnonmem` is set up to allow the user to quickly 126 | and easily update Data, Parameter or Task items, while leaving the Model 127 | unchanged. 128 | 129 | The `rspeaksnonmem` function `getNMDataObjects` returns the RAW `$DATA` and `$INPUT` 130 | lines from the NONMEM control stream and the associated parsed objects. 131 | 132 | ```{r getNMData} 133 | getNMDataObjects(warfModel) 134 | ``` 135 | 136 | Similarly, `getNMParameterObjects` returns the $THETA, $OMEGA and $SIGMA records. 137 | ```{r getNMParameterObjects} 138 | getNMParameterObjects(warfModel) 139 | ``` 140 | 141 | Finally, `getNMTasProperties` returns the $EST, $COV and $TABLES records. 142 | ```{r getNMTaskPropertiesObjects} 143 | getNMTaskPropertiesObjects(warfModel) 144 | ``` 145 | 146 | Together the Data, Parameters, Model and Task information forms a "Modelling 147 | Object Group" or MOG which is used for a specific estimation task. 148 | We can update the MOG using the `rspeaksnonmem` function `updateModel`. 149 | 150 | ```{r updateMOG} 151 | newTheta <- warfTemplateModel$Theta 152 | newTheta["POP_TLAG",] <- list(Lower=0, Est=0.75, Upper=1.5, FIX=FALSE, comments="POP_TLAG") 153 | newWarfModel <- updateModel(parsedObject = warfTemplateModel, theta=newTheta) 154 | newWarfModel 155 | ``` 156 | 157 | Note how the THETA settings for POP_TLAG have been updated, but all other 158 | elements are unchanged. 159 | 160 | It is also possible to change the initial estimates 161 | while retaining the specified lower and upper bounds: 162 | 163 | ```{r} 164 | newTheta2 <- warfTemplateModel$Theta 165 | newInits <- c(0.25, 10, 4, 0.25, 0, 0.1) 166 | newTheta2[,"Est"] <- newInits 167 | newTheta2 168 | ``` 169 | 170 | We can finally write out the updated control stream using the function 171 | `writeNMControlStream`. This function uses an existing NONMEM control stream 172 | (or raw records) as a template for writing the updated, parsed statements. This 173 | ensures that the order of statements corresponds between the original and 174 | updated files, which allows easier checking of changes. 175 | 176 | ```{r writeNMControlStream} 177 | writeNMControlStream(templateModel = warfModel$Raw, 178 | parsedControl = list(newWarfModel), 179 | outputFile = "warfarin2", 180 | outFileExtension = "ctl") 181 | cat(readLines("warfarin2.ctl", warn = F), sep="\n") 182 | ``` 183 | 184 | -------------------------------------------------------------------------------- /vignettes/Setting up workflow using rspeaksnonmem.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Introduction to rspeaksnonmem" 3 | author: "Mike K Smith (Mike.K.Smith@Pfizer.com)" 4 | date: "`r Sys.Date()`" 5 | # output: rmarkdown::html_vignette 6 | # vignette: > 7 | # %\VignetteIndexEntry{Vignette Title} 8 | # %\VignetteEngine{knitr::rmarkdown} 9 | # %\VignetteEncoding{UTF-8} 10 | output: html_notebook 11 | --- 12 | 13 | ```{r setup, include=FALSE} 14 | knitr::opts_chunk$set(fig.width=6, fig.height=6) 15 | ``` 16 | 17 | ## What does `rspeaksnonmem` do? 18 | 19 | `rspeaksnonmem` is designed to allow the user to craft workflows based on a 20 | given NONMEM model. It is not intended to replace Perl speaks Nonmem (PsN) - 21 | in fact `rspeaksnonmem` can call and use PsN functionality from an R script. 22 | In fact `rspeaksnonmem` could equally be called "rspeaksPsN". `rspeaksnonmem` 23 | helps the user by allow them to write complex workflows using NONMEM, PsN and R. 24 | For example performing data checkout (exploratory analysis), using a "template" 25 | model as a starting point for model refinement, specifying and running a 26 | sequence of tasks for every model, collating results across models for model 27 | comparison. 28 | 29 | After importing and parsing a control stream to an R object using the `RNMImport` 30 | package, `rspeaksnonmem` allows the user to easily change initial estimates, 31 | change data attributes or change task properties (estimation or simulation 32 | settings) without having to change the model. This saves a lot of textual 33 | searching by the user. 34 | 35 | To best use `rspeaksnonmem` it is useful to think of the NMTRAN expression of 36 | the model as a combination of: 37 | * Data specification 38 | * Parameter specification 39 | * Model specification (structural, covariate and stochastic components) 40 | * Task specification 41 | 42 | With `rspeaksnonmem` it is easy to alter data, parameter and task information, 43 | but altering the model specification has knock-on effects across many other 44 | aspects. We recommend that the user sets up the model in such a way that it is 45 | easy to change the model simply by fixing or estimating certain parameters i.e. 46 | fixing population parameters and/or altering the OMEGA and SIGMA parameter 47 | specification. 48 | 49 | Using a template model and a user-specified workflow function e.g. a function 50 | combining `execute_PsN` + `sumo_PsN` + `basic_GOF` the user could specify a 51 | number of combinations of THETA, OMEGA and SIGMA that would test a range of 52 | plausible models, run these models and then compare the output (OFV / AIC and 53 | model diagnostics) to find the best model fit. This is suggested not as a way of 54 | finding the best ***final*** model, but the best ***base*** model for further 55 | refinement. There is no substitute for the knowledge and skill of an analyst in 56 | building and assessing models. We refer the reader to Schmidt and Radivojevic 57 | (2014), JPKPD (). 58 | 59 | ## Installation 60 | 61 | ### Dependencies 62 | 63 | `rspeaksnonmem` relies on the package [`RNMImport`](https://github.com/MikeKSmith/RNMImport) 64 | function `importNmMod` which reads and parses the NONMEM control stream. 65 | `rspeaksnonmem` then works with the data, parameter values, and task information 66 | separately from the model. 67 | 68 | Before installation of `rspeaksnonmem`, the package `RNMImport` needs to be 69 | installed. 70 | 71 | Install RNMIMport from Github using the `devtools` package. `rspeaksnonmem` 72 | requires the version of RNMImport on MikeKSmith's Github repository which 73 | includes handling of OMEGA and SIGMA blocks and identifying which elements are 74 | fixed for these parameters. 75 | 76 | ```{r install_dependencies, include=F} 77 | #devtools::install_github("MikeKSmith/RNMImport") 78 | ``` 79 | 80 | ### Install rspeaksnonmem 81 | Eventually, `rspeaksnonmem` will be released to CRAN, but while still in 82 | development `rspeaksnonmem` can most easily be installed from GitHub using the 83 | `devtools` package: 84 | 85 | ```{r install_rspeaksnonmem, include=F} 86 | #devtools::install_github("MikeKSmith/rspeaksnonmem") 87 | ``` 88 | 89 | Alternatively, if the source files are available locally, you can load the 90 | functions directly. 91 | 92 | ```{r,echo=FALSE,results='hide',message=FALSE} 93 | devtools::load_all(pkg = ".") 94 | devtools::load_all(pkg = "C:\\Users\\smith_mk\\Documents\\Working documents\\RNMImport") 95 | ``` 96 | 97 | ```{r, include=FALSE, echo=FALSE} 98 | #library(rspeaksnonmem) 99 | ``` 100 | 101 | Copy an example dataset and model to a directory of your choice 102 | 103 | ```{r,results='hide',echo=T} 104 | getwd() 105 | 106 | file.copy(from = file.path(system.file("exdata", package = "rspeaksnonmem"), 107 | "warfarin_conc_pca.csv"), 108 | to = getwd(), overwrite = T ) 109 | file.copy(from = file.path(system.file("exdata", package = "rspeaksnonmem"), 110 | "warfarin_bootstrap50.dta"), 111 | to = getwd(), overwrite = T ) 112 | file.copy(from = file.path(system.file("exdata", package = "rspeaksnonmem"), 113 | "warfarin.ctl"), 114 | to = getwd(), overwrite = T ) 115 | ``` 116 | 117 | The initial model within the workflow should act as a "template" for 118 | modifications. The best practice is to use a model where all possible parameters 119 | are defined (including OMEGAs and covariances / correlations) but where it is 120 | possible to fix parameters to zero or some null value. We can then run and test 121 | a wide variety of models simply by updating the $THETA, $OMEGA and $SIGMA 122 | parameters to allow estimation. 123 | 124 | ## Read the control stream using RNMImport 125 | First, we need to read the NONMEM control stream into R using the `importNmMod` 126 | function of RNMImport. 127 | 128 | ```{r readControlStream} 129 | warfModel <- importNmMod("warfarin.ctl") 130 | class(warfModel) 131 | names(warfModel) 132 | ``` 133 | This function reads NONMEM control streams and parses the code. The initial R 134 | object contains the raw code as a vector of character strings, any comments 135 | from the NONMEM code (anything after ";" in the NMTRAN), the name of the control 136 | file in `controlFile` and the parsed code within the list `problemContents`. 137 | RNMImport allows for cases where there is more than one NONMEM `$PROBLEM` 138 | statement within the code. 139 | 140 | We can select the parsed control stream as the basis for modification. Here we 141 | take the first / only `$PROBLEM` statement content. 142 | 143 | ```{r viewParsedNM} 144 | warfTemplateModel <- warfModel$problemContents[[1]] 145 | str(warfTemplateModel) 146 | ``` 147 | 148 | Now with the parsed content, it is much easier to change elements within the 149 | NONMEM control stream since we're only manipulating text strings. But since the 150 | code has been parsed it's more transparent to a third party exactly what is being 151 | changed. 152 | 153 | First let's change the dataset. Here I've sampled 50 subjects from the original 154 | warfarin dataset (warfarin.csv) into a dataset called "warfarin_bootstrap50.dta". 155 | Since the names and uses of the data columns is unchanged, we do not need to 156 | change anything in the `$INPUT statement` of NMTRAN. So we create a new object 157 | called `newData` containing the original code, then update the file name. 158 | 159 | ```{r updateDataset} 160 | newData <- warfModel$problemContents[[1]]$Data 161 | newData[,"File"] <- "warfarin_bootstrap50.dta" 162 | ``` 163 | 164 | In a similar way, we can then update any element of the model using this 165 | parsed set of commands. `rspeaksnonmem` provides some additional functions to 166 | extract certain elements of the parsed control stream. 167 | 168 | "Object" | `rspeaksnonmem` Function | NMTRAN blocks 169 | ---------|---------------------------|----------------------------- 170 | Data | getNMDataObjects | `$DATA`, `$INPUT` 171 | Parameter| getNMParameterObjects | `$THETA`, `$OMEGA`, `$SIGMA` 172 | Task | getNMTaskPropertiesObjects| `$EST`,`$COV`, `$TAB` 173 | Model | getNMModelObjects | everything else 174 | 175 | 176 | For example: `getNMParameterObjects` returns the $THETA, $OMEGA and $SIGMA 177 | records. Since the `$THETA` parameters are represented as a data frame, we can 178 | easily update the initial values, lower or upper bounds, fix or estimate (unfix) 179 | `THETA` parameters. With each object returned by the various `getNM<...>` 180 | functions we get not only the parsed objects but the raw control stream as well. 181 | 182 | ```{r getNMParameterObjects} 183 | params <- getNMParameterObjects(warfModel) 184 | str(params) 185 | ``` 186 | 187 | Together the Data, Parameters, Model and Task "objects" form a 188 | "Modelling Object Group" or MOG which is used for a specific estimation task. 189 | 190 | In our example, the template model has POP_TLAG fixed to zero. To "unfix" this, 191 | we need to provide lower, initial (Est) and upper bounds for POP_TLAG. Note that 192 | params$THETA has named rows using the comments after each THETA line in the 193 | NMTRAN control stream. 194 | 195 | We can create multiple "objects" corresponding to different models that we wish 196 | to explore. So below we create an object called thetaNoLag where the `$THETA` 197 | for the LAG term is fixed to zero. We also create an object called "thetaLag" 198 | where we set `FIX = FALSE` and give a reasonable initial value for the Lag. 199 | 200 | ```{r specifyTHETAs} 201 | FIX_POP_TLAG <- list(Lower = 0, Est = 0, Upper = 0, FIX = TRUE, comments = "POP_TLAG") 202 | EST_POP_TLAG <- list(Lower = 0, Est = 0.75, Upper = 1.5, FIX = FALSE, comments = "POP_TLAG") 203 | 204 | thetaNoLag <- warfTemplateModel$Theta 205 | thetaNoLag["POP_TLAG",] <- FIX_POP_TLAG 206 | 207 | thetaLag <- warfTemplateModel$Theta 208 | thetaLag["POP_TLAG",] <- EST_POP_TLAG 209 | ``` 210 | 211 | The template model has a combined proportional and additive residual error 212 | structure. This has been parameterised as 213 | `W = THETA(5)+THETA(6)*CONC` in the NMTRAN code. W then multiplies a standard 214 | Normal variate to give the residual error: 215 | `W * SIGMA` where SIGMA ~ N(0,1). 216 | 217 | To be able to estimate different residual error models, we can then simply 218 | fix one or other component of the residual error model. Fixing `THETA(5)` to 219 | zero will estimate with only proportional error, while fixing `THETA(6)` to zero 220 | will estimate with only additive error. Estimating both provides the combined 221 | additive and proportional residual error. 222 | 223 | Similarly to the above, we can then create a new object which estimates 224 | `THETA(5)` which we will give the name "RUV_ADD" for Residual Unexplained 225 | Variability ADDitive component. 226 | 227 | ```{r specifyRUV} 228 | ruvPropOnly <- list(Est = 0, FIX = TRUE, comments = "RUV_ADD") 229 | ``` 230 | 231 | Again, in a similar way we can update the between subject `OMEGA` parameter 232 | specification to examine a variety of models - where Clearance (CL) and Volume 233 | of Distribution (V) are independent / uncorrelated, or where they are correlated. 234 | We can also easily fix or estimate between subject variability on parameters such 235 | as KA by specifying initial values and ensuring `FIX = FALSE`. 236 | 237 | The template model specifies an OMEGA block (covariance) between ETA_CL and ETA_V. 238 | ```{r specifyOMEGAs} 239 | CLVBlock_noTLAG <- params$OMEGA 240 | diagPPV_noTLAG <- list(data.frame(values=c(0.1,0.1,0.1), 241 | FIX=c(F,F,F), 242 | comments=c("; PPV_CL", "; PPV_V", "; PPV_KA")), 243 | list(values = 0, FIX = TRUE)) 244 | ``` 245 | 246 | Bringing all of these different components together, we can examine the fit of 247 | a number of basic models, starting only with the template model. We use the 248 | `updateModel` function to update the template model with objects that we have 249 | defined or altered. 250 | 251 | ```{r defineModels} 252 | run1 <- updateModel(warfTemplateModel, 253 | theta = thetaNoLag, 254 | omega = diagPPV_noTLAG, 255 | data = newData, 256 | runno = 1) ## First model 257 | 258 | run2 <- updateModel(warfTemplateModel, 259 | theta = thetaLag, 260 | omega = diagPPV_noTLAG , 261 | data = newData, 262 | runno = 2) ## Add POP_TLAG 263 | 264 | run3 <- updateModel(warfTemplateModel, 265 | theta = thetaLag, 266 | omega = CLVBlock_noTLAG, 267 | data = newData, 268 | runno = 3) ## Change to block CL, V 269 | ``` 270 | 271 | `rspeaksnonmem` provides function that enable us to run NONMEM or PsN without 272 | leaving R. By combining these, we can define a sequence of steps that we may 273 | wish to perform in a script, or define a function that combines workflow steps 274 | that we would wish to perform **on each model**. 275 | 276 | ```{r defineWorkflow, warning = FALSE, message = FALSE} 277 | myPopPKWorkflow <- function(model){ 278 | controlFile <- paste(deparse(substitute(model)),".ctl",sep = "") 279 | lstFile <- paste(deparse(substitute(model)),".lst",sep = "") 280 | 281 | workingDir <- deparse(substitute(model)) 282 | 283 | writeNMControlStream(templateModel = warfModel$Raw, 284 | parsedControl = model, 285 | outputFile = controlFile) 286 | 287 | execute_PsN(installPath = "c:/strawberry/perl", 288 | version = "4.7.0", 289 | modelFile = controlFile, 290 | lstFile = lstFile, 291 | clean = 1, 292 | working.dir = workingDir) 293 | 294 | sumo_PsN(tool = "sumo-3.5.4", 295 | installPath = "c:/strawberry/perl", 296 | version = "4.7.0", 297 | lstFile = lstFile) 298 | 299 | runno <- as.numeric(gsub("[a-z]", "", deparse(substitute(model)))) 300 | 301 | ## ----createXpdb---------------------------------------------------------- 302 | xpdb <- xpose4::xpose.data(runno = runno, quiet = T) 303 | # save(base.xpdb, file='Xpose database.RData') 304 | 305 | ## ----xposeGOF------------------------------------------------------------ 306 | print(xpose4::dv.vs.pred.ipred(xpdb)) 307 | print(xpose4::pred.vs.idv(xpdb)) 308 | print(xpose4::ipred.vs.idv(xpdb)) 309 | print(xpose4::wres.vs.idv(xpdb)) 310 | print(xpose4::wres.vs.pred(xpdb)) 311 | print(xpose4::ranpar.hist(xpdb)) 312 | print(xpose4::ind.plots(xpdb, layout = c(4, 4))) 313 | } 314 | ``` 315 | 316 | We can then run the workflow for each model in turn or "apply" the function 317 | across a list of models to be evaluated. 318 | 319 | ```{r runModel1} 320 | myPopPKWorkflow(run1) 321 | myPopPKWorkflow(run2) 322 | myPopPKWorkflow(run3) 323 | ``` 324 | 325 | 326 | -------------------------------------------------------------------------------- /inst/exdata/warfarin_conc_pca.csv: -------------------------------------------------------------------------------- 1 | #ID,time,wt,age,sex,amt,dvid,dv,mdv 2 | 1,0,66.7,50,1,100,0,.,1 3 | 1,0,66.7,50,1,.,2,.,1 4 | 1,0.5,66.7,50,1,.,1,0,0 5 | 1,1,66.7,50,1,.,1,1.9,0 6 | 1,2,66.7,50,1,.,1,3.3,0 7 | 1,3,66.7,50,1,.,1,6.6,0 8 | 1,6,66.7,50,1,.,1,9.1,0 9 | 1,9,66.7,50,1,.,1,10.8,0 10 | 1,12,66.7,50,1,.,1,8.6,0 11 | 1,24,66.7,50,1,.,1,5.6,0 12 | 1,24,66.7,50,1,.,2,44,0 13 | 1,36,66.7,50,1,.,1,4,0 14 | 1,36,66.7,50,1,.,2,27,0 15 | 1,48,66.7,50,1,.,1,2.7,0 16 | 1,48,66.7,50,1,.,2,28,0 17 | 1,72,66.7,50,1,.,1,0.8,0 18 | 1,72,66.7,50,1,.,2,31,0 19 | 1,96,66.7,50,1,.,1,.,1 20 | 1,96,66.7,50,1,.,2,60,0 21 | 1,120,66.7,50,1,.,1,.,1 22 | 1,120,66.7,50,1,.,2,65,0 23 | 1,144,66.7,50,1,.,2,71,0 24 | 2,0,66.7,50,1,100,0,.,1 25 | 2,0,66.7,50,1,.,2,100,0 26 | 2,24,66.7,50,1,.,1,9.2,0 27 | 2,24,66.7,50,1,.,2,49,0 28 | 2,36,66.7,50,1,.,1,8.5,0 29 | 2,36,66.7,50,1,.,2,32,0 30 | 2,48,66.7,50,1,.,1,6.4,0 31 | 2,48,66.7,50,1,.,2,26,0 32 | 2,72,66.7,50,1,.,1,4.8,0 33 | 2,72,66.7,50,1,.,2,22,0 34 | 2,96,66.7,50,1,.,1,3.1,0 35 | 2,96,66.7,50,1,.,2,28,0 36 | 2,120,66.7,50,1,.,1,2.5,0 37 | 2,120,66.7,50,1,.,2,33,0 38 | 3,0,66.7,31,1,100,0,.,1 39 | 3,0,66.7,31,1,.,2,100,0 40 | 3,0.5,66.7,31,1,.,1,0,0 41 | 3,2,66.7,31,1,.,1,8.4,0 42 | 3,3,66.7,31,1,.,1,9.7,0 43 | 3,6,66.7,31,1,.,1,9.8,0 44 | 3,12,66.7,31,1,.,1,11,0 45 | 3,24,66.7,31,1,.,1,8.3,0 46 | 3,24,66.7,31,1,.,2,46,0 47 | 3,36,66.7,31,1,.,1,7.7,0 48 | 3,36,66.7,31,1,.,2,22,0 49 | 3,48,66.7,31,1,.,1,6.3,0 50 | 3,48,66.7,31,1,.,2,19,0 51 | 3,72,66.7,31,1,.,1,4.1,0 52 | 3,72,66.7,31,1,.,2,20,0 53 | 3,96,66.7,31,1,.,1,3,0 54 | 3,96,66.7,31,1,.,2,42,0 55 | 3,120,66.7,31,1,.,1,1.4,0 56 | 3,120,66.7,31,1,.,2,49,0 57 | 3,144,66.7,31,1,.,2,54,0 58 | 4,0,80,40,1,120,0,.,1 59 | 4,0,80,40,1,.,2,100,0 60 | 4,3,80,40,1,.,1,12,0 61 | 4,6,80,40,1,.,1,13.2,0 62 | 4,9,80,40,1,.,1,14.4,0 63 | 4,24,80,40,1,.,1,9.6,0 64 | 4,24,80,40,1,.,2,30,0 65 | 4,36,80,40,1,.,1,8.2,0 66 | 4,36,80,40,1,.,2,24,0 67 | 4,48,80,40,1,.,1,7.8,0 68 | 4,48,80,40,1,.,2,13,0 69 | 4,72,80,40,1,.,1,5.8,0 70 | 4,72,80,40,1,.,2,9,0 71 | 4,96,80,40,1,.,1,4.3,0 72 | 4,96,80,40,1,.,2,9,0 73 | 4,120,80,40,1,.,1,3,0 74 | 4,120,80,40,1,.,2,11,0 75 | 4,144,80,40,1,.,2,12,0 76 | 5,0,40,46,0,60,0,.,1 77 | 5,0,40,46,0,.,2,82,0 78 | 5,3,40,46,0,.,1,11.1,0 79 | 5,6,40,46,0,.,1,11.9,0 80 | 5,9,40,46,0,.,1,9.8,0 81 | 5,12,40,46,0,.,1,11,0 82 | 5,24,40,46,0,.,1,8.5,0 83 | 5,24,40,46,0,.,2,43,0 84 | 5,36,40,46,0,.,1,7.6,0 85 | 5,36,40,46,0,.,2,25,0 86 | 5,48,40,46,0,.,1,5.4,0 87 | 5,48,40,46,0,.,2,18,0 88 | 5,72,40,46,0,.,1,4.5,0 89 | 5,72,40,46,0,.,2,17,0 90 | 5,96,40,46,0,.,1,3.3,0 91 | 5,96,40,46,0,.,2,23,0 92 | 5,120,40,46,0,.,1,2.3,0 93 | 5,120,40,46,0,.,2,29,0 94 | 5,144,40,46,0,.,2,41,0 95 | 6,0,75.3,43,1,113,0,.,1 96 | 6,0,75.3,43,1,.,2,100,0 97 | 6,6,75.3,43,1,.,1,8.6,0 98 | 6,12,75.3,43,1,.,1,8.6,0 99 | 6,24,75.3,43,1,.,1,7,0 100 | 6,24,75.3,43,1,.,2,34,0 101 | 6,36,75.3,43,1,.,1,5.7,0 102 | 6,36,75.3,43,1,.,2,23,0 103 | 6,48,75.3,43,1,.,1,4.7,0 104 | 6,48,75.3,43,1,.,2,20,0 105 | 6,72,75.3,43,1,.,1,3.3,0 106 | 6,72,75.3,43,1,.,2,16,0 107 | 6,96,75.3,43,1,.,1,2.3,0 108 | 6,96,75.3,43,1,.,2,17,0 109 | 6,120,75.3,43,1,.,1,1.7,0 110 | 6,120,75.3,43,1,.,2,18,0 111 | 6,144,75.3,43,1,.,2,25,0 112 | 7,0,60,36,0,90,0,.,1 113 | 7,3,60,36,0,.,1,13.4,0 114 | 7,6,60,36,0,.,1,12.4,0 115 | 7,9,60,36,0,.,1,12.7,0 116 | 7,12,60,36,0,.,1,8.8,0 117 | 7,24,60,36,0,.,1,6.1,0 118 | 7,24,60,36,0,.,2,36,0 119 | 7,36,60,36,0,.,1,3.5,0 120 | 7,36,60,36,0,.,2,33,0 121 | 7,48,60,36,0,.,1,1.8,0 122 | 7,48,60,36,0,.,2,28,0 123 | 7,72,60,36,0,.,1,1.5,0 124 | 7,72,60,36,0,.,2,52,0 125 | 7,96,60,36,0,.,1,1,0 126 | 7,96,60,36,0,.,2,80,0 127 | 7,120,60,36,0,.,1,.,1 128 | 7,120,60,36,0,.,2,90,0 129 | 7,144,60,36,0,.,2,100,0 130 | 8,0,90,41,1,135,0,.,1 131 | 8,0,90,41,1,.,2,88,0 132 | 8,2,90,41,1,.,1,17.6,0 133 | 8,3,90,41,1,.,1,17.3,0 134 | 8,6,90,41,1,.,1,15,0 135 | 8,9,90,41,1,.,1,15,0 136 | 8,12,90,41,1,.,1,12.4,0 137 | 8,24,90,41,1,.,1,7.9,0 138 | 8,24,90,41,1,.,2,35,0 139 | 8,36,90,41,1,.,1,7.9,0 140 | 8,36,90,41,1,.,2,20,0 141 | 8,48,90,41,1,.,1,5.1,0 142 | 8,48,90,41,1,.,2,12,0 143 | 8,72,90,41,1,.,1,3.6,0 144 | 8,72,90,41,1,.,2,16,0 145 | 8,96,90,41,1,.,1,2.4,0 146 | 8,96,90,41,1,.,2,23,0 147 | 8,120,90,41,1,.,1,2,0 148 | 8,120,90,41,1,.,2,36,0 149 | 8,144,90,41,1,.,2,48,0 150 | 9,0,50,27,0,75,0,.,1 151 | 9,0,50,27,0,.,2,92,0 152 | 9,0.5,50,27,0,.,1,0,0 153 | 9,1,50,27,0,.,1,1,0 154 | 9,2,50,27,0,.,1,4.6,0 155 | 9,3,50,27,0,.,1,12.7,0 156 | 9,3,50,27,0,.,1,8,0 157 | 9,6,50,27,0,.,1,12.7,0 158 | 9,6,50,27,0,.,1,11.5,0 159 | 9,9,50,27,0,.,1,12.9,0 160 | 9,9,50,27,0,.,1,11.4,0 161 | 9,12,50,27,0,.,1,11.4,0 162 | 9,12,50,27,0,.,1,11,0 163 | 9,24,50,27,0,.,1,9.1,0 164 | 9,24,50,27,0,.,2,33,0 165 | 9,36,50,27,0,.,1,8.2,0 166 | 9,36,50,27,0,.,2,22,0 167 | 9,48,50,27,0,.,1,5.9,0 168 | 9,48,50,27,0,.,2,16,0 169 | 9,72,50,27,0,.,1,3.6,0 170 | 9,72,50,27,0,.,2,18,0 171 | 9,96,50,27,0,.,1,1.7,0 172 | 9,96,50,27,0,.,2,32,0 173 | 9,120,50,27,0,.,1,1.1,0 174 | 9,120,50,27,0,.,2,30,0 175 | 9,144,50,27,0,.,2,45,0 176 | 10,0,70,28,1,105,0,.,1 177 | 10,0,70,28,1,.,2,90,0 178 | 10,24,70,28,1,.,1,8.6,0 179 | 10,24,70,28,1,.,2,39,0 180 | 10,36,70,28,1,.,1,8,0 181 | 10,36,70,28,1,.,2,22,0 182 | 10,48,70,28,1,.,1,6,0 183 | 10,48,70,28,1,.,2,17,0 184 | 10,72,70,28,1,.,1,4.4,0 185 | 10,72,70,28,1,.,2,17,0 186 | 10,96,70,28,1,.,1,3.6,0 187 | 10,96,70,28,1,.,2,22,0 188 | 10,120,70,28,1,.,1,2.8,0 189 | 10,120,70,28,1,.,2,25,0 190 | 10,144,70,28,1,.,2,33,0 191 | 12,0,82,31,1,123,0,.,1 192 | 12,0,82,31,1,.,2,100,0 193 | 12,1.5,82,31,1,.,1,11.4,0 194 | 12,3,82,31,1,.,1,15.4,0 195 | 12,6,82,31,1,.,1,17.5,0 196 | 12,12,82,31,1,.,1,14,0 197 | 12,24,82,31,1,.,1,9,0 198 | 12,24,82,31,1,.,2,37,0 199 | 12,36,82,31,1,.,1,8.9,0 200 | 12,36,82,31,1,.,2,24,0 201 | 12,48,82,31,1,.,1,6.6,0 202 | 12,48,82,31,1,.,2,14,0 203 | 12,72,82,31,1,.,1,4.2,0 204 | 12,72,82,31,1,.,2,11,0 205 | 12,96,82,31,1,.,1,3.6,0 206 | 12,96,82,31,1,.,2,14,0 207 | 12,120,82,31,1,.,1,2.6,0 208 | 12,120,82,31,1,.,2,23,0 209 | 12,144,82,31,1,.,2,33,0 210 | 13,0,75.3,32,1,113,0,.,1 211 | 13,0,75.3,32,1,.,2,85,0 212 | 13,1.5,75.3,32,1,.,1,0.6,0 213 | 13,6,75.3,32,1,.,1,13.8,0 214 | 13,9,75.3,32,1,.,1,15,0 215 | 13,24,75.3,32,1,.,1,10.5,0 216 | 13,24,75.3,32,1,.,2,25,0 217 | 13,36,75.3,32,1,.,1,9.1,0 218 | 13,36,75.3,32,1,.,2,15,0 219 | 13,48,75.3,32,1,.,1,6.6,0 220 | 13,48,75.3,32,1,.,2,11,0 221 | 13,72,75.3,32,1,.,1,4.9,0 222 | 13,72,75.3,32,1,.,2,.,1 223 | 13,96,75.3,32,1,.,1,2.4,0 224 | 13,96,75.3,32,1,.,2,.,1 225 | 13,120,75.3,32,1,.,1,1.9,0 226 | 13,120,75.3,32,1,.,2,.,1 227 | 13,144,75.3,32,1,.,2,.,1 228 | 14,0,75.3,63,1,113,0,.,1 229 | 14,0,75.3,63,1,.,2,88,0 230 | 14,0.5,75.3,63,1,.,1,.,1 231 | 14,1.5,75.3,63,1,.,1,3.6,0 232 | 14,2,75.3,63,1,.,1,.,1 233 | 14,3,75.3,63,1,.,1,12.9,0 234 | 14,6,75.3,63,1,.,1,12.9,0 235 | 14,9,75.3,63,1,.,1,10.2,0 236 | 14,24,75.3,63,1,.,1,6.4,0 237 | 14,24,75.3,63,1,.,2,41,0 238 | 14,36,75.3,63,1,.,1,6.9,0 239 | 14,36,75.3,63,1,.,2,23,0 240 | 14,48,75.3,63,1,.,1,4.5,0 241 | 14,48,75.3,63,1,.,2,16,0 242 | 14,72,75.3,63,1,.,1,3.2,0 243 | 14,72,75.3,63,1,.,2,14,0 244 | 14,96,75.3,63,1,.,1,2.4,0 245 | 14,96,75.3,63,1,.,2,18,0 246 | 14,120,75.3,63,1,.,1,1.3,0 247 | 14,120,75.3,63,1,.,2,22,0 248 | 14,144,75.3,63,1,.,2,35,0 249 | 15,0,50,36,0,75,0,.,1 250 | 15,0,50,36,0,.,2,85,0 251 | 15,0.5,50,36,0,.,1,0,0 252 | 15,1,50,36,0,.,1,2.7,0 253 | 15,2,50,36,0,.,1,11.6,0 254 | 15,3,50,36,0,.,1,11.6,0 255 | 15,6,50,36,0,.,1,11.3,0 256 | 15,9,50,36,0,.,1,9.7,0 257 | 15,24,50,36,0,.,1,6.5,0 258 | 15,24,50,36,0,.,2,32,0 259 | 15,36,50,36,0,.,1,5.2,0 260 | 15,36,50,36,0,.,2,22,0 261 | 15,48,50,36,0,.,1,3.6,0 262 | 15,48,50,36,0,.,2,21,0 263 | 15,72,50,36,0,.,1,2.4,0 264 | 15,72,50,36,0,.,2,28,0 265 | 15,96,50,36,0,.,1,0.9,0 266 | 15,96,50,36,0,.,2,38,0 267 | 15,120,50,36,0,.,1,.,1 268 | 15,120,50,36,0,.,2,46,0 269 | 15,144,50,36,0,.,2,65,0 270 | 16,0,56.7,27,0,85,0,.,1 271 | 16,0,56.7,27,0,.,2,100,0 272 | 16,1,56.7,27,0,.,1,6.6,0 273 | 16,3,56.7,27,0,.,1,11.9,0 274 | 16,6,56.7,27,0,.,1,11.7,0 275 | 16,9,56.7,27,0,.,1,12.2,0 276 | 16,24,56.7,27,0,.,1,8.1,0 277 | 16,24,56.7,27,0,.,2,43,0 278 | 16,36,56.7,27,0,.,1,7.4,0 279 | 16,36,56.7,27,0,.,2,26,0 280 | 16,48,56.7,27,0,.,1,6.8,0 281 | 16,48,56.7,27,0,.,2,15,0 282 | 16,72,56.7,27,0,.,1,5.3,0 283 | 16,72,56.7,27,0,.,2,13,0 284 | 16,96,56.7,27,0,.,1,3,0 285 | 16,96,56.7,27,0,.,2,21,0 286 | 16,120,56.7,27,0,.,1,2,0 287 | 16,120,56.7,27,0,.,2,28,0 288 | 16,144,56.7,27,0,.,2,39,0 289 | 17,0,58,22,1,87,0,.,1 290 | 17,0,58,22,1,.,2,100,0 291 | 17,24,58,22,1,.,1,10.4,0 292 | 17,24,58,22,1,.,2,42,0 293 | 17,36,58,22,1,.,1,8.9,0 294 | 17,36,58,22,1,.,2,32,0 295 | 17,48,58,22,1,.,1,7,0 296 | 17,48,58,22,1,.,2,26,0 297 | 17,72,58,22,1,.,1,4.4,0 298 | 17,72,58,22,1,.,2,31,0 299 | 17,96,58,22,1,.,1,3.2,0 300 | 17,96,58,22,1,.,2,33,0 301 | 17,120,58,22,1,.,1,2.4,0 302 | 17,120,58,22,1,.,2,54,0 303 | 18,0,78,28,1,117,0,.,1 304 | 18,0,78,28,1,.,2,100,0 305 | 18,24,78,28,1,.,1,7.6,0 306 | 18,24,78,28,1,.,2,35,0 307 | 18,36,78,28,1,.,1,6.4,0 308 | 18,36,78,28,1,.,2,23,0 309 | 18,48,78,28,1,.,1,6,0 310 | 18,48,78,28,1,.,2,17,0 311 | 18,72,78,28,1,.,1,4,0 312 | 18,72,78,28,1,.,2,18,0 313 | 18,96,78,28,1,.,1,3.1,0 314 | 18,96,78,28,1,.,2,18,0 315 | 18,120,78,28,1,.,1,2,0 316 | 18,120,78,28,1,.,2,21,0 317 | 19,0,74.7,31,1,112,0,.,1 318 | 19,0,74.7,31,1,.,2,100,0 319 | 19,24,74.7,31,1,.,1,7.6,0 320 | 19,24,74.7,31,1,.,2,32,0 321 | 19,36,74.7,31,1,.,1,6.6,0 322 | 19,36,74.7,31,1,.,2,20,0 323 | 19,48,74.7,31,1,.,1,5.4,0 324 | 19,48,74.7,31,1,.,2,18,0 325 | 19,72,74.7,31,1,.,1,3.4,0 326 | 19,72,74.7,31,1,.,2,18,0 327 | 19,96,74.7,31,1,.,1,1.2,0 328 | 19,96,74.7,31,1,.,2,19,0 329 | 19,120,74.7,31,1,.,1,0.9,0 330 | 19,120,74.7,31,1,.,2,29,0 331 | 20,0,63.7,22,1,95.5,0,.,1 332 | 20,0,63.7,22,1,.,2,100,0 333 | 20,24,63.7,22,1,.,1,6.6,0 334 | 20,24,63.7,22,1,.,2,33,0 335 | 20,36,63.7,22,1,.,1,5.3,0 336 | 20,36,63.7,22,1,.,2,28,0 337 | 20,48,63.7,22,1,.,1,3.6,0 338 | 20,48,63.7,22,1,.,2,18,0 339 | 20,72,63.7,22,1,.,1,2.7,0 340 | 20,72,63.7,22,1,.,2,18,0 341 | 20,96,63.7,22,1,.,1,1.4,0 342 | 20,96,63.7,22,1,.,2,17,0 343 | 20,120,63.7,22,1,.,1,1.1,0 344 | 20,120,63.7,22,1,.,2,26,0 345 | 21,0,59,22,1,88.5,0,.,1 346 | 21,0,59,22,1,.,2,100,0 347 | 21,24,59,22,1,.,1,9.6,0 348 | 21,24,59,22,1,.,2,41,0 349 | 21,36,59,22,1,.,1,8,0 350 | 21,36,59,22,1,.,2,30,0 351 | 21,48,59,22,1,.,1,6.6,0 352 | 21,48,59,22,1,.,2,22,0 353 | 21,72,59,22,1,.,1,5.6,0 354 | 21,72,59,22,1,.,2,23,0 355 | 21,96,59,22,1,.,1,3.5,0 356 | 21,96,59,22,1,.,2,23,0 357 | 21,120,59,22,1,.,1,2.3,0 358 | 21,120,59,22,1,.,2,35,0 359 | 22,0,62,27,1,93,0,.,1 360 | 22,0,62,27,1,.,2,100,0 361 | 22,24,62,27,1,.,1,7.3,0 362 | 22,24,62,27,1,.,2,46,0 363 | 22,36,62,27,1,.,1,6.1,0 364 | 22,36,62,27,1,.,2,27,0 365 | 22,48,62,27,1,.,1,4.3,0 366 | 22,48,62,27,1,.,2,22,0 367 | 22,72,62,27,1,.,1,3.2,0 368 | 22,72,62,27,1,.,2,36,0 369 | 22,96,62,27,1,.,1,2.3,0 370 | 22,96,62,27,1,.,2,40,0 371 | 22,120,62,27,1,.,1,1.9,0 372 | 22,120,62,27,1,.,2,44,0 373 | 23,0,58,22,1,87,0,.,1 374 | 23,0,58,22,1,.,2,100,0 375 | 23,24,58,22,1,.,1,8.9,0 376 | 23,24,58,22,1,.,2,35,0 377 | 23,36,58,22,1,.,1,8.4,0 378 | 23,36,58,22,1,.,2,27,0 379 | 23,48,58,22,1,.,1,8,0 380 | 23,48,58,22,1,.,2,23,0 381 | 23,72,58,22,1,.,1,4.4,0 382 | 23,72,58,22,1,.,2,27,0 383 | 23,96,58,22,1,.,1,3.2,0 384 | 23,96,58,22,1,.,2,43,0 385 | 23,120,58,22,1,.,1,1.7,0 386 | 23,120,58,22,1,.,2,43,0 387 | 24,0,73.3,22,1,110,0,.,1 388 | 24,0,73.3,22,1,.,2,100,0 389 | 24,24,73.3,22,1,.,1,9.8,0 390 | 24,24,73.3,22,1,.,2,34,0 391 | 24,36,73.3,22,1,.,1,8.4,0 392 | 24,36,73.3,22,1,.,2,24,0 393 | 24,48,73.3,22,1,.,1,6.6,0 394 | 24,48,73.3,22,1,.,2,15,0 395 | 24,72,73.3,22,1,.,1,4.8,0 396 | 24,72,73.3,22,1,.,2,15,0 397 | 24,96,73.3,22,1,.,1,3.2,0 398 | 24,96,73.3,22,1,.,2,19,0 399 | 24,120,73.3,22,1,.,1,2.4,0 400 | 24,120,73.3,22,1,.,2,19,0 401 | 25,0,76.7,35,1,115,0,.,1 402 | 25,0,76.7,35,1,.,2,88,0 403 | 25,24,76.7,35,1,.,1,8.2,0 404 | 25,24,76.7,35,1,.,2,37,0 405 | 25,36,76.7,35,1,.,1,7.5,0 406 | 25,36,76.7,35,1,.,2,20,0 407 | 25,48,76.7,35,1,.,1,6.8,0 408 | 25,48,76.7,35,1,.,2,20,0 409 | 25,72,76.7,35,1,.,1,5.5,0 410 | 25,72,76.7,35,1,.,2,26,0 411 | 25,96,76.7,35,1,.,1,4.5,0 412 | 25,96,76.7,35,1,.,2,28,0 413 | 25,120,76.7,35,1,.,1,3.7,0 414 | 25,120,76.7,35,1,.,2,50,0 415 | 26,0,74.7,23,1,112,0,.,1 416 | 26,0,74.7,23,1,.,2,100,0 417 | 26,24,74.7,23,1,.,1,11,0 418 | 26,24,74.7,23,1,.,2,32,0 419 | 26,36,74.7,23,1,.,1,10,0 420 | 26,36,74.7,23,1,.,2,20,0 421 | 26,48,74.7,23,1,.,1,8.2,0 422 | 26,48,74.7,23,1,.,2,17,0 423 | 26,72,74.7,23,1,.,1,6,0 424 | 26,72,74.7,23,1,.,2,19,0 425 | 26,96,74.7,23,1,.,1,3.7,0 426 | 26,96,74.7,23,1,.,2,21,0 427 | 26,120,74.7,23,1,.,1,2.6,0 428 | 26,120,74.7,23,1,.,2,30,0 429 | 27,0,80,23,1,120,0,.,1 430 | 27,0,80,23,1,.,2,100,0 431 | 27,24,80,23,1,.,1,10,0 432 | 27,24,80,23,1,.,2,41,0 433 | 27,36,80,23,1,.,1,9,0 434 | 27,36,80,23,1,.,2,28,0 435 | 27,48,80,23,1,.,1,7.3,0 436 | 27,48,80,23,1,.,2,19,0 437 | 27,72,80,23,1,.,1,5.2,0 438 | 27,72,80,23,1,.,2,17,0 439 | 27,96,80,23,1,.,1,3.7,0 440 | 27,96,80,23,1,.,2,17,0 441 | 27,120,80,23,1,.,1,2.7,0 442 | 27,120,80,23,1,.,2,24,0 443 | 28,0,80,22,1,120,0,.,1 444 | 28,0,80,22,1,.,2,100,0 445 | 28,24,80,22,1,.,1,11.8,0 446 | 28,24,80,22,1,.,2,32,0 447 | 28,36,80,22,1,.,1,9.2,0 448 | 28,36,80,22,1,.,2,21,0 449 | 28,48,80,22,1,.,1,7.7,0 450 | 28,48,80,22,1,.,2,19,0 451 | 28,72,80,22,1,.,1,4.9,0 452 | 28,72,80,22,1,.,2,22,0 453 | 28,96,80,22,1,.,1,3.4,0 454 | 28,96,80,22,1,.,2,33,0 455 | 28,120,80,22,1,.,1,2.7,0 456 | 28,120,80,22,1,.,2,46,0 457 | 29,0,80,22,1,120,0,.,1 458 | 29,0,80,22,1,.,2,100,0 459 | 29,24,80,22,1,.,1,10.1,0 460 | 29,24,80,22,1,.,2,39,0 461 | 29,36,80,22,1,.,1,8,0 462 | 29,36,80,22,1,.,2,25,0 463 | 29,48,80,22,1,.,1,6,0 464 | 29,48,80,22,1,.,2,16,0 465 | 29,72,80,22,1,.,1,4.9,0 466 | 29,72,80,22,1,.,2,14,0 467 | 29,96,80,22,1,.,1,3.4,0 468 | 29,96,80,22,1,.,2,15,0 469 | 29,120,80,22,1,.,1,2,0 470 | 29,120,80,22,1,.,2,20,0 471 | 30,0,102,22,1,153,0,.,1 472 | 30,0,102,22,1,.,2,86,0 473 | 30,24,102,22,1,.,1,8.3,0 474 | 30,24,102,22,1,.,2,35,0 475 | 30,36,102,22,1,.,1,7,0 476 | 30,36,102,22,1,.,2,21,0 477 | 30,48,102,22,1,.,1,5.6,0 478 | 30,48,102,22,1,.,2,18,0 479 | 30,72,102,22,1,.,1,4.1,0 480 | 30,72,102,22,1,.,2,20,0 481 | 30,96,102,22,1,.,1,3.1,0 482 | 30,96,102,22,1,.,2,29,0 483 | 30,120,102,22,1,.,1,2.2,0 484 | 30,120,102,22,1,.,2,41,0 485 | 31,0,70,23,1,105,0,.,1 486 | 31,0,70,23,1,.,2,100,0 487 | 31,24,70,23,1,.,1,9.9,0 488 | 31,24,70,23,1,.,2,45,0 489 | 31,36,70,23,1,.,1,7.5,0 490 | 31,36,70,23,1,.,2,24,0 491 | 31,48,70,23,1,.,1,6.5,0 492 | 31,48,70,23,1,.,2,23,0 493 | 31,72,70,23,1,.,1,4.1,0 494 | 31,72,70,23,1,.,2,26,0 495 | 31,96,70,23,1,.,1,2.9,0 496 | 31,96,70,23,1,.,2,28,0 497 | 31,120,70,23,1,.,1,2.3,0 498 | 31,120,70,23,1,.,2,39,0 499 | 32,0,83.3,24,1,125,0,.,1 500 | 32,0,83.3,24,1,.,2,100,0 501 | 32,24,83.3,24,1,.,1,9.5,0 502 | 32,24,83.3,24,1,.,2,45,0 503 | 32,36,83.3,24,1,.,1,7.8,0 504 | 32,36,83.3,24,1,.,2,30,0 505 | 32,48,83.3,24,1,.,1,6.4,0 506 | 32,48,83.3,24,1,.,2,24,0 507 | 32,72,83.3,24,1,.,1,4.5,0 508 | 32,72,83.3,24,1,.,2,22,0 509 | 32,96,83.3,24,1,.,1,3.4,0 510 | 32,96,83.3,24,1,.,2,28,0 511 | 32,120,83.3,24,1,.,1,2.5,0 512 | 32,120,83.3,24,1,.,2,42,0 513 | 33,0,62,21,1,93,0,.,1 514 | 33,0,62,21,1,.,2,100,0 515 | 33,24,62,21,1,.,1,8.9,0 516 | 33,24,62,21,1,.,2,36,0 517 | 33,36,62,21,1,.,1,7.7,0 518 | 33,36,62,21,1,.,2,27,0 519 | 33,48,62,21,1,.,1,6.9,0 520 | 33,48,62,21,1,.,2,24,0 521 | 33,72,62,21,1,.,1,4.4,0 522 | 33,72,62,21,1,.,2,23,0 523 | 33,96,62,21,1,.,1,3.5,0 524 | 33,96,62,21,1,.,2,20,0 525 | 33,120,62,21,1,.,1,2.5,0 526 | 33,120,62,21,1,.,2,22,0 527 | --------------------------------------------------------------------------------