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
68 stars 24 forks source link

summary output request #38

Closed KaoriIto214 closed 8 years ago

KaoriIto214 commented 8 years ago

Hi Bill, Could you add 'N' (number of subjects) per group or period, as a default output from the summary.PKNCAresults? Also, is it posible to use "-" instead of "," for 'range' outputs, such as Tmax? "." camma causes problems when I export the output to csv file. For example, I would like to see N for each TREATXT, and Tmax will be [1.00-6.00] etc. below.

start end TREATXT DOSE auclast cmax tmax half.life aucinf

0 Inf 15 mg Fed 15 1200 [19.5] 187 [23.4] 2.00 [1.00, 6.00] 12.2 [2.65] 1220 [19.2]

0 Inf 15 mg Fasted 15 1310 [20.6] 271 [24.4] 1.00 [1.00, 3.00] 12.3 [3.28] 1330 [20.5]

billdenney commented 8 years ago

I'm working on a feature enhancement for N right now.

For saving with a comma separating the range, I'm surprised that it's causing an issue. How are you saving your .csv file?

Saving with write.csv uses something very close to RFC 4180 (https://tools.ietf.org/html/rfc4180) which puts quotes around text with commas. This code

write.csv(data.frame(tmax="2.00 [1.00, 6.00]"), file="c:/temp/test.csv", row.names = FALSE)

gives these file contents

"tmax"
"2.00 [1.00, 6.00]"
KaoriIto214 commented 8 years ago

Hi Bill, Thank you for such a quick reply. For the “,”, I need to use quote=F in write.csv, because I use the table output directly in LaTex (reporting). If I use quote=F, then it recognize “,” in the data and the data pushed to the next column (as csv format,…comma delimiter). If I don’t use quote=F, then the output in the report looks like this, I see the quote around everything.

billdenney commented 8 years ago

I see a way that I can make the requested feature of being able to select the formatting of the summary consistent with the rest of the package, but it will take some time to implement. As a work around, can you try this:

as.data.frame(lapply(X=mysummary, FUN=function(x) gsub(", ", "-", x)))

That will convert all comma-spaces in the summary (named mysummary) to dashes.

KaoriIto214 commented 8 years ago

Thank you very much. Kaori

KaoriIto214 commented 8 years ago

Hi Bill, This is not a bug, but I am struggling to understand how to use PKNCA for MD study. For example, I have a dataset like below (showing only one subject):

 SUBJID TRTCD  PKATPD DOSE PKPTMS PKPTM PKCNCN VISIT VISITU

47 10011003 B 0.000 6 0 0HR 0.000 -7 DAY 48 10011003 B 1.000 6 1 1HR 6.640 -7 DAY 49 10011003 B 2.000 6 2 2HR 27.000 -7 DAY 50 10011003 B 3.983 6 4 4HR 31.000 -7 DAY 51 10011003 B 5.617 6 6 6HR 29.400 -7 DAY 52 10011003 B 8.083 6 8 8HR 26.800 -7 DAY 53 10011003 B 22.833 6 24 24HR 13.800 -7 DAY 54 10011003 B 67.550 6 72 72HR 1.610 -7 DAY 37 10011003 B 0.950 6 0 0HR 0.530 2 DAY 41 10011003 B 95.950 6 0 0HR 0.818 2 DAY 39 10011003 B 123.133 6 0 0HR 0.372 2 DAY 43 10011003 B NA NA 0 0HR NA 2 DAY 45 10011003 B NA NA 0 0HR NA 2 DAY 28 10011003 B 0.000 6 0 0HR 11.600 12 DAY 29 10011003 B 1.017 6 1 1HR 30.300 12 DAY 30 10011003 B 2.000 6 2 2HR 60.900 12 DAY 31 10011003 B 4.167 6 4 4HR 41.200 12 DAY 32 10011003 B 6.000 6 6 6HR 33.500 12 DAY 33 10011003 B 8.083 6 8 8HR 27.600 12 DAY 34 10011003 B 22.833 6 24 24HR 15.100 12 DAY 35 10011003 B 95.167 6 0 0HR 0.635 16 DAY 40 10011003 B 0.033 6 0 0HR 14.600 26 DAY 36 10011003 B 26.933 6 0 0HR 12.200 26 DAY 42 10011003 B 27.000 6 0 0HR 15.800 26 DAY 38 10011003 B 30.000 6 0 0HR 15.600 26 DAY 44 10011003 B NA NA 0 0HR NA 26 DAY 46 10011003 B NA NA 0 0HR NA 26 DAY

Could you guide me how to use PKNCA for calculating major parameters for Day -7 (this is equivalent with SD) and Day 12 afterward (MD)? Or is there any reference I can follow? Kaori

billdenney commented 8 years ago

Hi Kaori,

I think that the theophylline example (https://cran.r-project.org/web/packages/PKNCA/vignettes/Example-theophylline.html) is probably the best starting point.

In addition to that, I made an example from your data with the attached files below. The most important part in there is selecting the intervals (see the line starting with "my.intervals").

Kaori.txt Kaori.R.txt

Let me know if this is unclear or if you have any other questions.

Thanks,

Bill

KaoriIto214 commented 8 years ago

Hi Bill, thank you for the example code. I slightly modified the code as below, to accommodate multiple subjects and calculate other parameters. How can I address those warning messages (can I accept as it is because I don’t have any additional data to support to calculate half-life)? aucinf.obs are not calculated either…. I think NA in the dataset doesn’t matter here (I tested without NA (subset the dataset removing NA before using PKNCAconc function) and got the same output, but different warning message “In FUN(X[[i]], ...) : No data for interval”)

my.conc <- PKNCAconc(d, PKCNCN~NTAFD|TREATXT + SUBJID) my.dose <- PKNCAdose(d.dose, DOSE~NTAFD|TREATXT + SUBJID)

my.intervals <- data.frame(start=c(-192, -192, 264), end=c(-120, -168, 288), auclast=TRUE, #AUCinf(SD), AUC24(SD), AUC24(MD) cmax=c(TRUE, FALSE, TRUE), tmax=c(TRUE, FALSE, TRUE), half.life=c(TRUE, FALSE, FALSE), aucinf.obs=c(TRUE, FALSE, FALSE))

my.data <- PKNCAdata(my.conc, my.dose, intervals=my.intervals) my.results <- pk.nca(my.data)

Warning messages: 1: In pk.calc.half.life(conc = c(0, 0.527, 0.592, 51.5, 51.8, 53, 20.8, : Too few points for half-life calculation (min.hl.points=3 with only 2 points) 2: In check.conc.time(conc, time) : All concentration data is missing 3: In check.conc.time(conc = conc) : All concentration data is missing 4: In check.conc.time(conc, time) : All concentration data is missing 5: In check.conc.time(conc, time) : All concentration data is missing 6: In check.conc.time(conc = conc) : All concentration data is missing 7: In check.conc.time(conc, time) : All concentration data is missing 8: In check.conc.time(conc, time) : All concentration data is missing 9: In check.conc.time(conc = conc) : All concentration data is missing 10: In check.conc.time(conc, time) : All concentration data is missing

summary(my.results) start end TREATXT auclast cmax tmax half.life aucinf.obs 1 -192 -120 PF 04691502 and irinotecan 778 [50.3] 50.3 [43.5] 2.00 [1.00, 8.00] 12.7 [2.43] . 13 -192 -168 PF 04691502 and irinotecan 584 [42.9] . . . . 14 264 288 PF 04691502 and irinotecan 638 [76.5] 55.9 [59.9] 2.00 [1.00, 6.00] . . 17 -192 -120 PF 04691502 and PD-0325901 556 [35.8] 42.0 [30.6] 1.00 [1.00, 6.00] 10.2 [1.65] . 29 -192 -168 PF 04691502 and PD-0325901 475 [21.9] . . . . 30 264 288 PF 04691502 and PD-0325901 498 [39.9] 46.5 [42.4] 2.00 [0.000, 2.00] . . Warning messages: 1: In summary.PKNCAresults(my.results) : No results to summarize for aucinf.obs in result row 1 2: In summary.PKNCAresults(my.results) : No results to summarize for aucinf.obs in result row 4

Kaori

billdenney commented 8 years ago

The warnings are just there to tell you more about your data. They indicate that for each interval, there is some issue.

The warning "All concentration data is missing" may happen in two ways. The first way it can happen is more straight-forward: all the data are NA. The second way it can happen is if you specify an interval that doesn't apply for a subject. I'm guessing that the second is the case here. If you request intervals that are not specific to a subject or to a treatment (as I did in the code example I attached above), they may not apply to all subjects.

I'm guessing that in your study not all subjects in the dataset have either a day -7 or a day 12 sampling interval (specifically, I'm guessing that 9 subjects don't have one of those days).

The part that is more unusual to me is the warning related to the summary. That warning suggests that aucinf.obs was never calculated. Can you send me the full dataset and script you're using? My email address should be visible on my main GitHub page: https://github.com/billdenney