# [R] Calculation error

Ben Bolker bolker at ufl.edu
Mon May 3 02:16:28 CEST 2010

```oscar linares <winsaam <at> gmail.com> writes:

>
> Dear Rxperts,
>
> Running the following code:
> =======================================================
> twlo=10; twhi=20; wt=154; vd=0.5; cl=0.046; tau=6; t=3; F=1;
>
> wtkg  <- wt/2.2             # convert lbs to kg
>
>   vd.pt <- wtkg * vd       # compute weight-based vd (L)
>   cl.pt <- wtkg * cl       # compute CL (L/hr)
>   k     <- cl.pt/vd.pt     # compute k (hr^-1)
>
>   cave      <- round((twhi - twlo)/log(twhi/twlo),2)
>   doserate  <- (cl.pt * cave)/F
>
>   # maintenance dose (Dm)
>   total_dose_tau <- round(doserate * tau,0)
>
>   Cmax <- total_dose_tau/vd.pt
>   Cmin <- Cmax * exp(-k * tau)
>
>   AR <- 1/(1 - exp(-k * tau))
>
>   Cmaxss <- Cmax * AR
>   Cminss <- Cmin * AR
>   Cfluctss <- (Cmaxss - Cminss)
>   Ct       <- (Cmaxss * exp(-k * t))
>
>
>   options(digits=2)
>
[snip]
> But, there is an error from R?
>
> AR * total_dose_tau = 658 but that is wrong
>
> Total Dose (mg) = 279 * AR (=2.4) = 670
>
> Please help. I don't want to harm anyone. A difference of 12 mg of a highly
> toxic drug can at the very least cause significant harm.

You set options(digits=2), thus AR is only printed to 2 digits
(2.4), when its true underlying value is  (at least to machine precision)

options(digits=20)
> 1/(1-exp(-k*tau))
[1] 2.357362278468023

Note that options(digits=2) affects only the display of numeric values, not
their underlying values.  You have also done some rounding of intermediate
values, which is probably a bad idea.  Reading R FAQ 7.31 might be useful
as well.

May I respectfully suggest that you not use a system that you don't
understand to compute the dosages of highly toxic drugs ?????

Ben Bolker

```