billdenney / pknca

An R package is designed to perform all noncompartmental analysis (NCA) calculations for pharmacokinetic (PK) data.
http://billdenney.github.io/pknca/
GNU Affero General Public License v3.0
67 stars 24 forks source link

Error: Argument 1 must have names -> CANNOT generate any parameter output #154

Closed ameliacossart closed 3 years ago

ameliacossart commented 3 years ago

Hi, I am trying to run an analysis for a dataset containing 33 patients. I have 12hour concentration-time profiles (for a total of six drugs), and each patient is dosed at time zero (12-hourly dosing).

I’d like to generate findings for: AUC0-12 AUC0-inf Tmax Cmax Cmin Ctrough Lambda.Z R2 Adjusted R2 CL/Fss Vz/Fss Half-life

I followed your tutorials and set up the first drug data using a ‘concentration’ and ‘dose’ dataset. And because there is so many parameters I then sub-divided the data into two datasets: ‘Eld’ and ‘YA’. So now there is four datasets “conc Eld” and “dose Eld”; “conc YA” and “dose YA”.

Using the attached code I was originally able to compute results for the ‘Eld’ datasets. However, when I substituted the YA datasets, I received the below error. I cleared my environment and tried running the original ‘Eld’ dataset again and now I repeatedly see this error (below) – no results will generate now whatsoever.

Error: Argument 1 must have names In addition: Warning message: In parallel::mclapply(X = splitdata[mask_has_interval], FUN = pk.nca.intervals, : all scheduled cores encountered errors in user code

Here is my code:

# Load the package
library(PKNCA)
library(knitr)
library(ggplot2)
library(tidyverse)
library(readxl)
# Set the business rule options with the PKNCA.options() function
# Calculating parameters
# Load your concentration-time data
myrawconcdata <- read_excel("Documents/PhD/PK study/Analysis/PKNCA/conc YA.xlsx")

# Load your dose data
myrawdosedata <- read_excel("Documents/PhD/PK study/Analysis/PKNCA/dose YA.xlsx")
# Put your concentration data into a PKNCAconc object
myconc <- PKNCAconc(data=myrawconcdata,
                    formula = conc~time| subject)

# Put your dose data into a PKNCAdose object
mydose <- PKNCAdose(data=myrawdosedata,
                    formula = dose ~ time| subject,
                    dose.time=0,
                    duration=12,
                    na.strings=c("", "NA"))
##if use formula = dose ~ .| time + subject <- will run

##calculating Ctorugh Cmin and Cmax
myintervals <- data.frame(start=0,
                          end=12,
                          cmin=TRUE,
                          cmax=TRUE,
                          ctrough=TRUE
) 
mydata <- PKNCAdata(myconc, mydose, intervals=myintervals) 
knitr::kable(mydata$intervals)
my.results.automatic <- pk.nca(mydata)
knitr::kable(head(my.results.automatic$result))
knitr::kable(summary(my.results.automatic))
my.results.automatic[["result"]]
knitr::kable(summary(mydata))

##calculating Tmax and AUC
myintervals1 <- data.frame(start=0, end=12, tmax=TRUE, auclast=TRUE, aucinf.obs=TRUE) 
mydata1 <- PKNCAdata(myconc, mydose, intervals=myintervals1) 
knitr::kable(mydata1$intervals)
my.results.automatic1 <- pk.nca(mydata1)
knitr::kable(head(my.results.automatic1$result))
knitr::kable(summary(my.results.automatic1))
my.results.automatic1[["result"]]

I'm not sure what to do. Any help is much appreciated (including how to reproduce the output for 6 drugs). Thank you in advance :)

conc Eld.xlsx conc YA.xlsx dose Eld.xlsx dose YA.xlsx

billdenney commented 3 years ago

@ameliacossart , The issue appears to be that your conc column in your concentration data is a character vector where concentrations that are below the limit of quantification are set to ".". Changing the "." to zero and then setting those concentration measurements to numeric fixed the issue:

library(PKNCA)
library(knitr)
library(ggplot2)
library(tidyverse)
library(readxl)
# Set the business rule options with the PKNCA.options() function
# Calculating parameters
# Load your concentration-time data
myrawconcdata <- read_excel("conc.YA.xlsx")

# Load your dose data
myrawdosedata <- read_excel("dose.YA.xlsx")

# NOTE: the "conc" column is a character vector and not numeric
head(myrawconcdata)
#> # A tibble: 6 x 3
#>   subject  time conc 
#>     <dbl> <dbl> <chr>
#> 1      16  0    6.6  
#> 2      16  0.25 7    
#> 3      16  0.5  6.8  
#> 4      16  0.75 6.3  
#> 5      16  1    6.2  
#> 6      16  1.25 6.8
head(sort(unique(myrawconcdata$conc)))
#> [1] "."                  "10"                 "10.1"              
#> [4] "10.199999999999999" "10.3"               "10.4"
# NOTE: Concentrations that are BLQ appear to be set to ".".  Set them to 0 and
# make the column numeric.
concdata <-
  myrawconcdata %>%
  mutate(
    conc=
      as.numeric(case_when(
        conc == "."~"0",
        TRUE~conc
      ))
  )

# Put your concentration data into a PKNCAconc object
myconc <- PKNCAconc(data=concdata,
                    formula = conc~time| subject)

# Put your dose data into a PKNCAdose object
mydose <- PKNCAdose(data=myrawdosedata,
                    formula = dose ~ time| subject,
                    dose.time=0,
                    duration=12,
                    na.strings=c("", "NA"))
##if use formula = dose ~ .| time + subject <- will run

##calculating Ctorugh Cmin and Cmax
myintervals <- data.frame(start=0,
                          end=12,
                          cmin=TRUE,
                          cmax=TRUE,
                          ctrough=TRUE
) 
mydata <- PKNCAdata(myconc, mydose, intervals=myintervals) 
knitr::kable(mydata$intervals)
start end auclast aucall aumclast aumcall aucint.last aucint.last.dose aucint.all aucint.all.dose auclast.dn aucall.dn aumclast.dn aumcall.dn cmax cmin tmax tlast tfirst clast.obs cl.last cl.all f mrt.last mrt.iv.last vss.last vss.iv.last cav ctrough ptr tlag deg.fluc swing ceoi ae clr.last clr.obs clr.pred fe time_above half.life r.squared adj.r.squared lambda.z lambda.z.time.first lambda.z.n.points clast.pred span.ratio cmax.dn cmin.dn clast.obs.dn clast.pred.dn cav.dn ctrough.dn thalf.eff.last thalf.eff.iv.last kel.last kel.iv.last aucinf.obs aucinf.pred aumcinf.obs aumcinf.pred aucint.inf.obs aucint.inf.obs.dose aucint.inf.pred aucint.inf.pred.dose aucinf.obs.dn aucinf.pred.dn aumcinf.obs.dn aumcinf.pred.dn aucpext.obs aucpext.pred cl.obs cl.pred mrt.obs mrt.pred mrt.iv.obs mrt.iv.pred mrt.md.obs mrt.md.pred vz.obs vz.pred vss.obs vss.pred vss.iv.obs vss.iv.pred vss.md.obs vss.md.pred vd.obs vd.pred thalf.eff.obs thalf.eff.pred thalf.eff.iv.obs thalf.eff.iv.pred kel.obs kel.pred kel.iv.obs kel.iv.pred
0 12 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
my.results.automatic <- pk.nca(mydata)
knitr::kable(head(my.results.automatic$result))
start end subject PPTESTCD PPORRES exclude
0 12 16 cmax 11.2 NA
0 12 16 cmin 6.2 NA
0 12 16 ctrough 7.1 NA
0 12 17 cmax 9.5 NA
0 12 17 cmin 6.6 NA
0 12 17 ctrough 7.1 NA
knitr::kable(summary(my.results.automatic))
start end N cmax cmin ctrough
0 12 18 16.4 [44.2] 7.09 [18.3] 7.37 [17.4]
my.results.automatic[["result"]]
#>    start end subject PPTESTCD PPORRES exclude
#> 1      0  12      16     cmax    11.2    <NA>
#> 2      0  12      16     cmin     6.2    <NA>
#> 3      0  12      16  ctrough     7.1    <NA>
#> 4      0  12      17     cmax     9.5    <NA>
#> 5      0  12      17     cmin     6.6    <NA>
#> 6      0  12      17  ctrough     7.1    <NA>
#> 7      0  12      18     cmax    11.2    <NA>
#> 8      0  12      18     cmin     6.0    <NA>
#> 9      0  12      18  ctrough     6.0    <NA>
#> 10     0  12      19     cmax    13.1    <NA>
#> 11     0  12      19     cmin     0.0    <NA>
#> 12     0  12      19  ctrough     5.8    <NA>
#> 13     0  12      20     cmax     9.0    <NA>
#> 14     0  12      20     cmin     5.7    <NA>
#> 15     0  12      20  ctrough     5.7    <NA>
#> 16     0  12      21     cmax    24.8    <NA>
#> 17     0  12      21     cmin     7.8    <NA>
#> 18     0  12      21  ctrough     8.0    <NA>
#> 19     0  12      22     cmax    18.9    <NA>
#> 20     0  12      22     cmin     8.0    <NA>
#> 21     0  12      22  ctrough     8.7    <NA>
#> 22     0  12      23     cmax    20.0    <NA>
#> 23     0  12      23     cmin     8.3    <NA>
#> 24     0  12      23  ctrough     8.3    <NA>
#> 25     0  12      24     cmax    16.4    <NA>
#> 26     0  12      24     cmin     6.6    <NA>
#> 27     0  12      24  ctrough     8.0    <NA>
#> 28     0  12      25     cmax    12.1    <NA>
#> 29     0  12      25     cmin     4.9    <NA>
#> 30     0  12      25  ctrough     5.4    <NA>
#> 31     0  12      26     cmax    17.5    <NA>
#> 32     0  12      26     cmin     7.4    <NA>
#> 33     0  12      26  ctrough     7.4    <NA>
#> 34     0  12      27     cmax    14.9    <NA>
#> 35     0  12      27     cmin     0.0    <NA>
#> 36     0  12      27  ctrough     7.1    <NA>
#> 37     0  12      28     cmax    13.8    <NA>
#> 38     0  12      28     cmin     9.4    <NA>
#> 39     0  12      28  ctrough     9.4    <NA>
#> 40     0  12      29     cmax    38.9    <NA>
#> 41     0  12      29     cmin     9.1    <NA>
#> 42     0  12      29  ctrough     9.9    <NA>
#> 43     0  12      30     cmax    24.0    <NA>
#> 44     0  12      30     cmin     6.6    <NA>
#> 45     0  12      30  ctrough     6.6    <NA>
#> 46     0  12      31     cmax    21.8    <NA>
#> 47     0  12      31     cmin     0.0    <NA>
#> 48     0  12      31  ctrough     7.9    <NA>
#> 49     0  12      32     cmax    11.3    <NA>
#> 50     0  12      32     cmin     7.1    <NA>
#> 51     0  12      32  ctrough     7.6    <NA>
#> 52     0  12      33     cmax    34.7    <NA>
#> 53     0  12      33     cmin     8.3    <NA>
#> 54     0  12      33  ctrough     8.6    <NA>
knitr::kable(summary(mydata))
#> Formula for concentration:
#>  conc ~ time | subject
#> With 18 subjects defined in the 'subject' column.
#> Nominal time column is not specified.
#> 
#> Group summary:
#>  Group Name Count
#>     subject    18
#> 
#> First 6 rows of concentration data:
#>  subject time conc exclude volume duration
#>       16 0.00  6.6    <NA>     NA        0
#>       16 0.25  7.0    <NA>     NA        0
#>       16 0.50  6.8    <NA>     NA        0
#>       16 0.75  6.3    <NA>     NA        0
#>       16 1.00  6.2    <NA>     NA        0
#>       16 1.25  6.8    <NA>     NA        0
#> Formula for dosing:
#>  dose ~ time | subject
#> Nominal time column is not specified.
#> 
#> Number unique entries in each group:
#>  subject
#>       18
#> 
#> With 1 rows of AUC specifications.
#> No options are set differently than default.

|| || || ||

##calculating Tmax and AUC
myintervals1 <- data.frame(start=0, end=12, tmax=TRUE, auclast=TRUE, aucinf.obs=TRUE) 
mydata1 <- PKNCAdata(myconc, mydose, intervals=myintervals1) 
knitr::kable(mydata1$intervals)
start end auclast aucall aumclast aumcall aucint.last aucint.last.dose aucint.all aucint.all.dose auclast.dn aucall.dn aumclast.dn aumcall.dn cmax cmin tmax tlast tfirst clast.obs cl.last cl.all f mrt.last mrt.iv.last vss.last vss.iv.last cav ctrough ptr tlag deg.fluc swing ceoi ae clr.last clr.obs clr.pred fe time_above half.life r.squared adj.r.squared lambda.z lambda.z.time.first lambda.z.n.points clast.pred span.ratio cmax.dn cmin.dn clast.obs.dn clast.pred.dn cav.dn ctrough.dn thalf.eff.last thalf.eff.iv.last kel.last kel.iv.last aucinf.obs aucinf.pred aumcinf.obs aumcinf.pred aucint.inf.obs aucint.inf.obs.dose aucint.inf.pred aucint.inf.pred.dose aucinf.obs.dn aucinf.pred.dn aumcinf.obs.dn aumcinf.pred.dn aucpext.obs aucpext.pred cl.obs cl.pred mrt.obs mrt.pred mrt.iv.obs mrt.iv.pred mrt.md.obs mrt.md.pred vz.obs vz.pred vss.obs vss.pred vss.iv.obs vss.iv.pred vss.md.obs vss.md.pred vd.obs vd.pred thalf.eff.obs thalf.eff.pred thalf.eff.iv.obs thalf.eff.iv.pred kel.obs kel.pred kel.iv.obs kel.iv.pred
0 12 TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
my.results.automatic1 <- pk.nca(mydata1)
#> Warning in pk.calc.half.life(conc = c(7.1, 7.9, 7.9, 7.3, 8.4, 10, 10.2, : Too
#> few points for half-life calculation (min.hl.points=3 with only 2 points)
knitr::kable(head(my.results.automatic1$result))
start end subject PPTESTCD PPORRES exclude
0 12 16 auclast 100.5647495 NA
0 12 16 tmax 4.0000000 NA
0 12 16 tlast 12.0000000 NA
0 12 16 clast.obs 7.1000000 NA
0 12 16 lambda.z 0.0357762 NA
0 12 16 r.squared 0.9572716 NA
knitr::kable(summary(my.results.automatic1))
start end N auclast tmax aucinf.obs
0 12 18 124 [24.7] 2.00 [1.00, 6.00] 254 [27.9]
my.results.automatic1[["result"]]
#>     start end subject            PPTESTCD      PPORRES
#> 1       0  12      16             auclast 100.56474953
#> 2       0  12      16                tmax   4.00000000
#> 3       0  12      16               tlast  12.00000000
#> 4       0  12      16           clast.obs   7.10000000
#> 5       0  12      16            lambda.z   0.03577616
#> 6       0  12      16           r.squared   0.95727161
#> 7       0  12      16       adj.r.squared   0.91454321
#> 8       0  12      16 lambda.z.time.first   6.00000000
#> 9       0  12      16   lambda.z.n.points   3.00000000
#> 10      0  12      16          clast.pred   7.00765495
#> 11      0  12      16           half.life  19.37455706
#> 12      0  12      16          span.ratio   0.30968450
#> 13      0  12      16          aucinf.obs 299.02094903
#> 14      0  12      17             auclast  97.77529409
#> 15      0  12      17                tmax   3.00000000
#> 16      0  12      17               tlast  12.00000000
#> 17      0  12      17           clast.obs   7.10000000
#> 18      0  12      17            lambda.z   0.03752729
#> 19      0  12      17           r.squared   0.96401233
#> 20      0  12      17       adj.r.squared   0.94601850
#> 21      0  12      17 lambda.z.time.first   4.00000000
#> 22      0  12      17   lambda.z.n.points   4.00000000
#> 23      0  12      17          clast.pred   6.94423745
#> 24      0  12      17           half.life  18.47048290
#> 25      0  12      17          span.ratio   0.43312349
#> 26      0  12      17          aucinf.obs 286.97094011
#> 27      0  12      18             auclast 104.03585253
#> 28      0  12      18                tmax   2.00000000
#> 29      0  12      18               tlast  12.00000000
#> 30      0  12      18           clast.obs   6.00000000
#> 31      0  12      18            lambda.z   0.07482504
#> 32      0  12      18           r.squared   0.99470754
#> 33      0  12      18       adj.r.squared   0.98941509
#> 34      0  12      18 lambda.z.time.first   6.00000000
#> 35      0  12      18   lambda.z.n.points   3.00000000
#> 36      0  12      18          clast.pred   5.94354680
#> 37      0  12      18           half.life   9.26357288
#> 38      0  12      18          span.ratio   0.64769826
#> 39      0  12      18          aucinf.obs 184.22291647
#> 40      0  12      19             auclast  95.28874555
#> 41      0  12      19                tmax   1.50000000
#> 42      0  12      19               tlast  12.00000000
#> 43      0  12      19           clast.obs   5.80000000
#> 44      0  12      19            lambda.z   0.06005445
#> 45      0  12      19           r.squared   0.96998192
#> 46      0  12      19       adj.r.squared   0.96247740
#> 47      0  12      19 lambda.z.time.first   2.00000000
#> 48      0  12      19   lambda.z.n.points   6.00000000
#> 49      0  12      19          clast.pred   5.59354091
#> 50      0  12      19           half.life  11.54197776
#> 51      0  12      19          span.ratio   0.86640264
#> 52      0  12      19          aucinf.obs 191.86775915
#> 53      0  12      20             auclast  88.93615615
#> 54      0  12      20                tmax   4.00000000
#> 55      0  12      20               tlast  12.00000000
#> 56      0  12      20           clast.obs   5.70000000
#> 57      0  12      20            lambda.z   0.05227626
#> 58      0  12      20           r.squared   0.99968621
#> 59      0  12      20       adj.r.squared   0.99937241
#> 60      0  12      20 lambda.z.time.first   6.00000000
#> 61      0  12      20   lambda.z.n.points   3.00000000
#> 62      0  12      20          clast.pred   5.70915123
#> 63      0  12      20           half.life  13.25931088
#> 64      0  12      20          span.ratio   0.45251220
#> 65      0  12      20          aucinf.obs 197.97226587
#> 66      0  12      21             auclast 147.29420293
#> 67      0  12      21                tmax   1.25000000
#> 68      0  12      21               tlast  12.00000000
#> 69      0  12      21           clast.obs   8.00000000
#> 70      0  12      21            lambda.z   0.10673170
#> 71      0  12      21           r.squared   0.88141312
#> 72      0  12      21       adj.r.squared   0.85769574
#> 73      0  12      21 lambda.z.time.first   1.50000000
#> 74      0  12      21   lambda.z.n.points   7.00000000
#> 75      0  12      21          clast.pred   6.71432657
#> 76      0  12      21           half.life   6.49429509
#> 77      0  12      21          span.ratio   1.61680365
#> 78      0  12      21          aucinf.obs 222.24850152
#> 79      0  12      22             auclast 147.06646442
#> 80      0  12      22                tmax   3.00000000
#> 81      0  12      22               tlast  12.00000000
#> 82      0  12      22           clast.obs   8.70000000
#> 83      0  12      22            lambda.z   0.06435369
#> 84      0  12      22           r.squared   0.98309567
#> 85      0  12      22       adj.r.squared   0.96619133
#> 86      0  12      22 lambda.z.time.first   6.00000000
#> 87      0  12      22   lambda.z.n.points   3.00000000
#> 88      0  12      22          clast.pred   8.57376364
#> 89      0  12      22           half.life  10.77090018
#> 90      0  12      22          span.ratio   0.55705650
#> 91      0  12      22          aucinf.obs 282.25684560
#> 92      0  12      23             auclast 143.35841786
#> 93      0  12      23                tmax   3.00000000
#> 94      0  12      23               tlast  12.00000000
#> 95      0  12      23           clast.obs   8.30000000
#> 96      0  12      23            lambda.z   0.06004715
#> 97      0  12      23           r.squared   0.99960681
#> 98      0  12      23       adj.r.squared   0.99921362
#> 99      0  12      23 lambda.z.time.first   6.00000000
#> 100     0  12      23   lambda.z.n.points   3.00000000
#> 101     0  12      23          clast.pred   8.31713818
#> 102     0  12      23           half.life  11.54338231
#> 103     0  12      23          span.ratio   0.51977833
#> 104     0  12      23          aucinf.obs 281.58313524
#> 105     0  12      24             auclast 119.87261721
#> 106     0  12      24                tmax   1.50000000
#> 107     0  12      24               tlast  12.00000000
#> 108     0  12      24           clast.obs   8.00000000
#> 109     0  12      24            lambda.z   0.03211406
#> 110     0  12      24           r.squared   0.99445483
#> 111     0  12      24       adj.r.squared   0.98890966
#> 112     0  12      24 lambda.z.time.first   6.00000000
#> 113     0  12      24   lambda.z.n.points   3.00000000
#> 114     0  12      24          clast.pred   7.96684041
#> 115     0  12      24           half.life  21.58391803
#> 116     0  12      24          span.ratio   0.27798475
#> 117     0  12      24          aucinf.obs 368.98470928
#> 118     0  12      25             auclast  88.00696027
#> 119     0  12      25                tmax   1.25000000
#> 120     0  12      25               tlast  12.00000000
#> 121     0  12      25           clast.obs   5.40000000
#> 122     0  12      25            lambda.z   0.08220690
#> 123     0  12      25           r.squared   0.89428052
#> 124     0  12      25       adj.r.squared   0.87313662
#> 125     0  12      25 lambda.z.time.first   1.50000000
#> 126     0  12      25   lambda.z.n.points   7.00000000
#> 127     0  12      25          clast.pred   4.65393114
#> 128     0  12      25           half.life   8.43173988
#> 129     0  12      25          span.ratio   1.24529458
#> 130     0  12      25          aucinf.obs 153.69487858
#> 131     0  12      26             auclast 127.79696706
#> 132     0  12      26                tmax   3.00000000
#> 133     0  12      26               tlast  12.00000000
#> 134     0  12      26           clast.obs   7.40000000
#> 135     0  12      26            lambda.z   0.04850913
#> 136     0  12      26           r.squared   0.96182404
#> 137     0  12      26       adj.r.squared   0.92364809
#> 138     0  12      26 lambda.z.time.first   6.00000000
#> 139     0  12      26   lambda.z.n.points   3.00000000
#> 140     0  12      26          clast.pred   7.52491163
#> 141     0  12      26           half.life  14.28900571
#> 142     0  12      26          span.ratio   0.41990325
#> 143     0  12      26          aucinf.obs 280.34558186
#> 144     0  12      27             auclast 121.67613388
#> 145     0  12      27                tmax   3.00000000
#> 146     0  12      27               tlast  12.00000000
#> 147     0  12      27           clast.obs   7.10000000
#> 148     0  12      27            lambda.z   0.05421092
#> 149     0  12      27           r.squared   0.99279139
#> 150     0  12      27       adj.r.squared   0.98918709
#> 151     0  12      27 lambda.z.time.first   4.00000000
#> 152     0  12      27   lambda.z.n.points   4.00000000
#> 153     0  12      27          clast.pred   7.07235571
#> 154     0  12      27           half.life  12.78611675
#> 155     0  12      27          span.ratio   0.62567863
#> 156     0  12      27          aucinf.obs 252.64605124
#> 157     0  12      28             auclast 135.14796689
#> 158     0  12      28                tmax   1.50000000
#> 159     0  12      28               tlast  12.00000000
#> 160     0  12      28           clast.obs   9.40000000
#> 161     0  12      28            lambda.z   0.03328438
#> 162     0  12      28           r.squared   0.89735382
#> 163     0  12      28       adj.r.squared   0.87169227
#> 164     0  12      28 lambda.z.time.first   2.00000000
#> 165     0  12      28   lambda.z.n.points   6.00000000
#> 166     0  12      28          clast.pred   9.34712897
#> 167     0  12      28           half.life  20.82500136
#> 168     0  12      28          span.ratio   0.48019205
#> 169     0  12      28          aucinf.obs 417.56275307
#> 170     0  12      29             auclast 217.94408247
#> 171     0  12      29                tmax   2.00000000
#> 172     0  12      29               tlast  12.00000000
#> 173     0  12      29           clast.obs   9.90000000
#> 174     0  12      29            lambda.z   0.06588546
#> 175     0  12      29           r.squared   0.99976179
#> 176     0  12      29       adj.r.squared   0.99952358
#> 177     0  12      29 lambda.z.time.first   6.00000000
#> 178     0  12      29   lambda.z.n.points   3.00000000
#> 179     0  12      29          clast.pred   9.88257658
#> 180     0  12      29           half.life  10.52048846
#> 181     0  12      29          span.ratio   0.57031572
#> 182     0  12      29          aucinf.obs 368.20486209
#> 183     0  12      30             auclast 123.72351505
#> 184     0  12      30                tmax   1.50000000
#> 185     0  12      30               tlast  12.00000000
#> 186     0  12      30           clast.obs   6.60000000
#> 187     0  12      30            lambda.z   0.08927337
#> 188     0  12      30           r.squared   0.82799027
#> 189     0  12      30       adj.r.squared   0.77065370
#> 190     0  12      30 lambda.z.time.first   3.00000000
#> 191     0  12      30   lambda.z.n.points   5.00000000
#> 192     0  12      30          clast.pred   5.78443642
#> 193     0  12      30           half.life   7.76432181
#> 194     0  12      30          span.ratio   1.15914825
#> 195     0  12      30          aucinf.obs 197.65373561
#> 196     0  12      31             auclast 143.80358774
#> 197     0  12      31                tmax   1.25000000
#> 198     0  12      31               tlast  12.00000000
#> 199     0  12      31           clast.obs   7.90000000
#> 200     0  12      31            lambda.z   0.10021764
#> 201     0  12      31           r.squared   0.87302499
#> 202     0  12      31       adj.r.squared   0.84762999
#> 203     0  12      31 lambda.z.time.first   1.50000000
#> 204     0  12      31   lambda.z.n.points   7.00000000
#> 205     0  12      31          clast.pred   6.67594858
#> 206     0  12      31           half.life   6.91641858
#> 207     0  12      31          span.ratio   1.51812674
#> 208     0  12      31          aucinf.obs 222.63202175
#> 209     0  12      32             auclast 117.80344522
#> 210     0  12      32                tmax   6.00000000
#> 211     0  12      32               tlast  12.00000000
#> 212     0  12      32           clast.obs   7.60000000
#> 213     0  12      32            lambda.z           NA
#> 214     0  12      32           r.squared           NA
#> 215     0  12      32       adj.r.squared           NA
#> 216     0  12      32 lambda.z.time.first           NA
#> 217     0  12      32   lambda.z.n.points           NA
#> 218     0  12      32          clast.pred           NA
#> 219     0  12      32           half.life           NA
#> 220     0  12      32          span.ratio           NA
#> 221     0  12      32          aucinf.obs           NA
#> 222     0  12      33             auclast 182.48611038
#> 223     0  12      33                tmax   1.00000000
#> 224     0  12      33               tlast  12.00000000
#> 225     0  12      33           clast.obs   8.60000000
#> 226     0  12      33            lambda.z   0.09455914
#> 227     0  12      33           r.squared   0.91541761
#> 228     0  12      33       adj.r.squared   0.88722348
#> 229     0  12      33 lambda.z.time.first   3.00000000
#> 230     0  12      33   lambda.z.n.points   5.00000000
#> 231     0  12      33          clast.pred   7.69090769
#> 232     0  12      33           half.life   7.33030304
#> 233     0  12      33          span.ratio   1.22778007
#> 234     0  12      33          aucinf.obs 273.43448026
#>                                                                           exclude
#> 1                                                                            <NA>
#> 2                                                                            <NA>
#> 3                                                                            <NA>
#> 4                                                                            <NA>
#> 5                                                                            <NA>
#> 6                                                                            <NA>
#> 7                                                                            <NA>
#> 8                                                                            <NA>
#> 9                                                                            <NA>
#> 10                                                                           <NA>
#> 11                                                                           <NA>
#> 12                                                                           <NA>
#> 13                                                                           <NA>
#> 14                                                                           <NA>
#> 15                                                                           <NA>
#> 16                                                                           <NA>
#> 17                                                                           <NA>
#> 18                                                                           <NA>
#> 19                                                                           <NA>
#> 20                                                                           <NA>
#> 21                                                                           <NA>
#> 22                                                                           <NA>
#> 23                                                                           <NA>
#> 24                                                                           <NA>
#> 25                                                                           <NA>
#> 26                                                                           <NA>
#> 27                                                                           <NA>
#> 28                                                                           <NA>
#> 29                                                                           <NA>
#> 30                                                                           <NA>
#> 31                                                                           <NA>
#> 32                                                                           <NA>
#> 33                                                                           <NA>
#> 34                                                                           <NA>
#> 35                                                                           <NA>
#> 36                                                                           <NA>
#> 37                                                                           <NA>
#> 38                                                                           <NA>
#> 39                                                                           <NA>
#> 40                                                                           <NA>
#> 41                                                                           <NA>
#> 42                                                                           <NA>
#> 43                                                                           <NA>
#> 44                                                                           <NA>
#> 45                                                                           <NA>
#> 46                                                                           <NA>
#> 47                                                                           <NA>
#> 48                                                                           <NA>
#> 49                                                                           <NA>
#> 50                                                                           <NA>
#> 51                                                                           <NA>
#> 52                                                                           <NA>
#> 53                                                                           <NA>
#> 54                                                                           <NA>
#> 55                                                                           <NA>
#> 56                                                                           <NA>
#> 57                                                                           <NA>
#> 58                                                                           <NA>
#> 59                                                                           <NA>
#> 60                                                                           <NA>
#> 61                                                                           <NA>
#> 62                                                                           <NA>
#> 63                                                                           <NA>
#> 64                                                                           <NA>
#> 65                                                                           <NA>
#> 66                                                                           <NA>
#> 67                                                                           <NA>
#> 68                                                                           <NA>
#> 69                                                                           <NA>
#> 70                                                                           <NA>
#> 71                                                                           <NA>
#> 72                                                                           <NA>
#> 73                                                                           <NA>
#> 74                                                                           <NA>
#> 75                                                                           <NA>
#> 76                                                                           <NA>
#> 77                                                                           <NA>
#> 78                                                                           <NA>
#> 79                                                                           <NA>
#> 80                                                                           <NA>
#> 81                                                                           <NA>
#> 82                                                                           <NA>
#> 83                                                                           <NA>
#> 84                                                                           <NA>
#> 85                                                                           <NA>
#> 86                                                                           <NA>
#> 87                                                                           <NA>
#> 88                                                                           <NA>
#> 89                                                                           <NA>
#> 90                                                                           <NA>
#> 91                                                                           <NA>
#> 92                                                                           <NA>
#> 93                                                                           <NA>
#> 94                                                                           <NA>
#> 95                                                                           <NA>
#> 96                                                                           <NA>
#> 97                                                                           <NA>
#> 98                                                                           <NA>
#> 99                                                                           <NA>
#> 100                                                                          <NA>
#> 101                                                                          <NA>
#> 102                                                                          <NA>
#> 103                                                                          <NA>
#> 104                                                                          <NA>
#> 105                                                                          <NA>
#> 106                                                                          <NA>
#> 107                                                                          <NA>
#> 108                                                                          <NA>
#> 109                                                                          <NA>
#> 110                                                                          <NA>
#> 111                                                                          <NA>
#> 112                                                                          <NA>
#> 113                                                                          <NA>
#> 114                                                                          <NA>
#> 115                                                                          <NA>
#> 116                                                                          <NA>
#> 117                                                                          <NA>
#> 118                                                                          <NA>
#> 119                                                                          <NA>
#> 120                                                                          <NA>
#> 121                                                                          <NA>
#> 122                                                                          <NA>
#> 123                                                                          <NA>
#> 124                                                                          <NA>
#> 125                                                                          <NA>
#> 126                                                                          <NA>
#> 127                                                                          <NA>
#> 128                                                                          <NA>
#> 129                                                                          <NA>
#> 130                                                                          <NA>
#> 131                                                                          <NA>
#> 132                                                                          <NA>
#> 133                                                                          <NA>
#> 134                                                                          <NA>
#> 135                                                                          <NA>
#> 136                                                                          <NA>
#> 137                                                                          <NA>
#> 138                                                                          <NA>
#> 139                                                                          <NA>
#> 140                                                                          <NA>
#> 141                                                                          <NA>
#> 142                                                                          <NA>
#> 143                                                                          <NA>
#> 144                                                                          <NA>
#> 145                                                                          <NA>
#> 146                                                                          <NA>
#> 147                                                                          <NA>
#> 148                                                                          <NA>
#> 149                                                                          <NA>
#> 150                                                                          <NA>
#> 151                                                                          <NA>
#> 152                                                                          <NA>
#> 153                                                                          <NA>
#> 154                                                                          <NA>
#> 155                                                                          <NA>
#> 156                                                                          <NA>
#> 157                                                                          <NA>
#> 158                                                                          <NA>
#> 159                                                                          <NA>
#> 160                                                                          <NA>
#> 161                                                                          <NA>
#> 162                                                                          <NA>
#> 163                                                                          <NA>
#> 164                                                                          <NA>
#> 165                                                                          <NA>
#> 166                                                                          <NA>
#> 167                                                                          <NA>
#> 168                                                                          <NA>
#> 169                                                                          <NA>
#> 170                                                                          <NA>
#> 171                                                                          <NA>
#> 172                                                                          <NA>
#> 173                                                                          <NA>
#> 174                                                                          <NA>
#> 175                                                                          <NA>
#> 176                                                                          <NA>
#> 177                                                                          <NA>
#> 178                                                                          <NA>
#> 179                                                                          <NA>
#> 180                                                                          <NA>
#> 181                                                                          <NA>
#> 182                                                                          <NA>
#> 183                                                                          <NA>
#> 184                                                                          <NA>
#> 185                                                                          <NA>
#> 186                                                                          <NA>
#> 187                                                                          <NA>
#> 188                                                                          <NA>
#> 189                                                                          <NA>
#> 190                                                                          <NA>
#> 191                                                                          <NA>
#> 192                                                                          <NA>
#> 193                                                                          <NA>
#> 194                                                                          <NA>
#> 195                                                                          <NA>
#> 196                                                                          <NA>
#> 197                                                                          <NA>
#> 198                                                                          <NA>
#> 199                                                                          <NA>
#> 200                                                                          <NA>
#> 201                                                                          <NA>
#> 202                                                                          <NA>
#> 203                                                                          <NA>
#> 204                                                                          <NA>
#> 205                                                                          <NA>
#> 206                                                                          <NA>
#> 207                                                                          <NA>
#> 208                                                                          <NA>
#> 209                                                                          <NA>
#> 210                                                                          <NA>
#> 211                                                                          <NA>
#> 212                                                                          <NA>
#> 213 Too few points for half-life calculation (min.hl.points=3 with only 2 points)
#> 214 Too few points for half-life calculation (min.hl.points=3 with only 2 points)
#> 215 Too few points for half-life calculation (min.hl.points=3 with only 2 points)
#> 216 Too few points for half-life calculation (min.hl.points=3 with only 2 points)
#> 217 Too few points for half-life calculation (min.hl.points=3 with only 2 points)
#> 218 Too few points for half-life calculation (min.hl.points=3 with only 2 points)
#> 219 Too few points for half-life calculation (min.hl.points=3 with only 2 points)
#> 220 Too few points for half-life calculation (min.hl.points=3 with only 2 points)
#> 221 Too few points for half-life calculation (min.hl.points=3 with only 2 points)
#> 222                                                                          <NA>
#> 223                                                                          <NA>
#> 224                                                                          <NA>
#> 225                                                                          <NA>
#> 226                                                                          <NA>
#> 227                                                                          <NA>
#> 228                                                                          <NA>
#> 229                                                                          <NA>
#> 230                                                                          <NA>
#> 231                                                                          <NA>
#> 232                                                                          <NA>
#> 233                                                                          <NA>
#> 234                                                                          <NA>

Created on 2021-08-19 by the reprex package (v2.0.0)

ameliacossart commented 3 years ago

Thank you so very much @billdenney!!! I have tried running the code again, including the changing of conc from character vectors to numeric. However, I now have this error (below) at this line of code:

my.results.automatic <- pk.nca(mydata) Error: Argument 1 must have names In addition: Warning message: In parallel::mclapply(X = splitdata[mask_has_interval], FUN = pk.nca.intervals, : all scheduled cores encountered errors in user code knitr::kable(head(my.results.automatic$result)) Error in head(my.results.automatic$result) : object 'my.results.automatic' not found

I'e again cleared my environment, so I'm not sure why the code works for you and not me?

billdenney commented 3 years ago

It's not clear where that error is coming from. But, I think that one or more of your tidyverse packages may be out of date. Can you please do the following in order:

ameliacossart commented 3 years ago

I'm really not sure why, but this time when I ran the code, there was no error message. Regardless, here is the output attached (run up until the previous error message line of code).

traceback() No traceback available sessionInfo() R version 3.6.1 (2019-07-05) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: macOS 10.16

Matrix products: default LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale: [1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] readxl_1.3.1 forcats_0.4.0 stringr_1.4.0 dplyr_0.8.3 purrr_0.3.3
[6] readr_1.3.1 tidyr_1.0.0 tibble_2.1.3 tidyverse_1.2.1 ggplot2_3.2.1
[11] knitr_1.26 PKNCA_0.9.4

loaded via a namespace (and not attached): [1] Rcpp_1.0.3 highr_0.8 cellranger_1.1.0 pillar_1.4.2
[5] compiler_3.6.1 tools_3.6.1 zeallot_0.1.0 digest_0.6.22
[9] lubridate_1.7.4 jsonlite_1.6 lifecycle_0.1.0 nlme_3.1-140
[13] gtable_0.3.0 lattice_0.20-38 pkgconfig_2.0.3 rlang_0.4.1
[17] cli_1.1.0 rstudioapi_0.10 parallel_3.6.1 haven_2.2.0
[21] xfun_0.11 xml2_1.2.2 httr_1.4.1 withr_2.1.2
[25] hms_0.5.2 generics_0.0.2 vctrs_0.2.0 grid_3.6.1
[29] tidyselect_0.2.5 glue_1.3.1 R6_2.4.1 fansi_0.4.0
[33] modelr_0.1.5 magrittr_1.5 backports_1.1.5 scales_1.0.0
[37] rvest_0.3.5 assertthat_0.2.1 colorspace_1.4-1 utf8_1.1.4
[41] stringi_1.4.3 lazyeval_0.2.2 munsell_0.5.0 broom_0.5.2
[45] crayon_1.3.4

ameliacossart commented 3 years ago

But then when I run the dataset through a second time to confirm the error is no longer apparent., I get the error again (output attached).

my.results.automatic <- pk.nca(mydata) Error: Argument 1 must have names In addition: Warning message: In parallel::mclapply(X = splitdata[mask_has_interval], FUN = pk.nca.intervals, : all scheduled cores encountered errors in user code traceback() 4: stop(list(message = "Argument 1 must have names", call = NULL, cppstack = NULL)) 3: bindrows(x, .id) 2: dplyr::bind_rows(tmp.results) 1: pk.nca(mydata) sessionInfo() R version 3.6.1 (2019-07-05) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: macOS 10.16

Matrix products: default LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale: [1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] readxl_1.3.1 forcats_0.4.0 stringr_1.4.0 dplyr_0.8.3 purrr_0.3.3 readr_1.3.1
[7] tidyr_1.0.0 tibble_2.1.3 tidyverse_1.2.1 ggplot2_3.2.1 knitr_1.26 PKNCA_0.9.4

loaded via a namespace (and not attached): [1] Rcpp_1.0.3 highr_0.8 cellranger_1.1.0 pillar_1.4.2 compiler_3.6.1 tools_3.6.1
[7] zeallot_0.1.0 digest_0.6.22 lubridate_1.7.4 jsonlite_1.6 lifecycle_0.1.0 nlme_3.1-140
[13] gtable_0.3.0 lattice_0.20-38 pkgconfig_2.0.3 rlang_0.4.1 cli_1.1.0 rstudioapi_0.10 [19] parallel_3.6.1 haven_2.2.0 xfun_0.11 xml2_1.2.2 httr_1.4.1 withr_2.1.2
[25] hms_0.5.2 generics_0.0.2 vctrs_0.2.0 grid_3.6.1 tidyselect_0.2.5 glue_1.3.1
[31] R6_2.4.1 fansi_0.4.0 modelr_0.1.5 magrittr_1.5 backports_1.1.5 scales_1.0.0
[37] rvest_0.3.5 assertthat_0.2.1 colorspace_1.4-1 utf8_1.1.4 stringi_1.4.3 lazyeval_0.2.2
[43] munsell_0.5.0 broom_0.5.2 crayon_1.3.4

billdenney commented 3 years ago

Thanks for the follow-up. The version of dplyr you're running is old (version 0.8.3 compared to the current version of 1.0.7). I believe that the error is likely a bug in dplyr. Can you please try updating at least dplyr, and preferably all of your packages and try again? update.packages() will update everything.

(As an aside, you may also want to update R to version 4.1.1. But, that should not change this error.)

ameliacossart commented 3 years ago

Thank you Bill. I have run the update but I'm still getting the same error (I updated all packages as suggested). I will ask IT to update my R version to 4.1.1 and maybe that will fix the error. I'll be in touch either way. Thanks again, Amelia

billdenney commented 3 years ago

The problem is happening here: https://github.com/billdenney/pknca/blob/cfb037753eeb24c1b171bb5a311eabf396bee560/R/pk.calc.all.R#L130

But, I can't reproduce it on my Windows-based or Linux-based systems (edit for completeness: both tests were with R >=4.1 and current dependent package versions). I don't have easy access to a modern Mac. Whatever is the issue is not triggering a problem in the continuous integration on Linux or Mac (I see that you're on a Mac). My guess is that we may identify a Mac-specific bug in dplyr.

ameliacossart commented 3 years ago

Okay, thank you Bill. I will have access to a Windows computer tomorrow so I will see if I can generate output using Windows.

billdenney commented 3 years ago

Over the weekend, I heavily reworked the way that PKNCA splits data for doing calculations and then puts it back together. If you're able to test out the current development version (remotes::install_github("billdenney/pknca")), I would be interested to see if it works on your Mac. (It does pass all of the tests on a current Mac in continuous integration.)

ameliacossart commented 3 years ago

Hi Bill, I so appreciate all your work to try and fix this for me. Thank you

I loaded the development package , and now seem to get this error (on my Mac): myconc <- PKNCAconc(data=myrawconcdata, formula = conc ~ time| subject) Error in check.conc.time(conc = data[[as.character(parsedForm$lhs)]], : Concentration data must be numeric and not a factor

Doesn't make sense to me as you gave me code to change my concentration data to numeric.

I have now tried running the code on a Windows computer and it too has generated a similar error, but a little further down in the code: my.results.automatic <- pk.nca(mydata) Error in check.conc.time (conc = conc) Error with interval subject=16, start=0, end=12: Concentration data must be numeric and not a factor.

Not sure how to proceed.

billdenney commented 3 years ago

@ameliacossart , can you please post your full code? My guess is that you're using rawconcdata rather than concdata when setting up the PKNCAconc() object.

ameliacossart commented 3 years ago

Dear Bill,

Thank you! Yes you are correct. And by changing ‘rawconcdata’ to ‘concdata’ objective, I can now generate output using Windows! Wahoooooo So, I’ve now tried to generate output for another dataset, and have run into further troubles. I simply changed the original concentration and dose values to reflect different drug/conc (and renamed the Excel spreadsheets accordingly), and I get this error with the dose dataset:

Put your dose data into a PKNCAdose object

mydose <- PKNCAdose(data=myrawdosedata,

  • formula = dose ~ time| subject,
  • dose.time=0,
  • duration=12,
  • na.strings=c("", "NA")) Error in PKNCAdose.data.frame(as.data.frame(data), ...) : Some but not all values are missing for the independent variable, please see the help for PKNCAdose for how to specify the formula and confirm that your data has dose times for all doses.

I don’t understand why this is happening, as the dataset is set up entirely the same way, and I’ve changed nothing in the R script. I’ve attached the dose and conc excel spreadsheets for your reference.

Many thanks for all your help, and patience! I’ve learnt so much in such a short space of time with your guidance. Amelia

billdenney commented 3 years ago

@ameliacossart , The underlying error is that there is a NA value in the time column within myrawdosedata. You would need to fix/remove that value and retry. Also, I'm not sure why you have na.strings=c("", "NA") in the call to PKNCAdose().

The attachments didn't come through (I think that you replied by email but to attach, I think that you have to upload directly to GitHub).

ameliacossart commented 3 years ago

Thank you Bill, you are correct. I had removed the blank (NA) in the time column but it must not have saved. I can now generate output using my Mac, so the package update works!!!

Thank you so very much! I'm delighted to be able to get the package working and generate parameters :)

For my learning, sometimes I cannot generate clearance values, is that because there is data missing from either the conc or dose data? Reason given in results sheet: Too few points for half-life calculation (min.hl.points...

I've attached my excel sheets again for everyone's reference/learning in this thread.

Total MPA conc.xlsx MPA dose.xlsx

Thank you again Bill :)

billdenney commented 3 years ago

I'm glad that it helped.

Clearance requires AUC for calculation. If you don't have sufficient data to calculate the half-life, you can't calculate AUCinf. If you can't calculate AUCinf, you can't calculate clearance. That is why clearance is sometimes missing.