## Intro

I see a lot of threads where people discuss what's the optimum dosing for X drug. To truly figure it out, you should graph the result using an ordinary differential equation (ODE) solver. R is a programming language that's free and comes with these features. Today I'll go through a couple examples and show you how.

## Simple Half-life calculation

Let's say you've ingested Hydrocodone (Vicodin) an opioid, which has a half life of 3.8 hours. After the drug is fully absorbed, the quantity of the drug in the body decreases at a rate proportional to the amount left in the body. You've taken an instant release form of Hydrocodone, with a dose of 10 mg. It's 11:30 AM midnight and after 30 minutes the Hydrocodone is completely absorbed.

Now you have a Calculus test the next day at 12:00 PM (Noon). You're wondering how much Hydrocodone will be left in your system. How do you figure that out?

Well since you learned a few things from that class, you start by writing a differential. You know that the drug content will be excreted by your system at a first order rate proportional to the amount left in your body, you call that k. Q represents the initial quantity that you ingested, and dQ/dt is your body's drug removal rate for Hydrocodone, t will be time in hours.

Now you have to solve k. But first in order to do that, solve this differential equation using basic rules of calculus and derivative tables. Q_0 means initial quantity of Q at time 0.

You have the internet at your disposal, you google "hydrocodone half life" and you find out that it's 3.8 hours. Knowing that you write another equation based off of (2). Based off the definition of half life, the quantity

All you're doing is filling in the variables. Using algebra, you solve for k by moving all the other variables to the other side of the equal sign

Now you have a Calculus test the next day at 12:00 PM (Noon). You're wondering how much Hydrocodone will be left in your system. How do you figure that out?

Well since you learned a few things from that class, you start by writing a differential. You know that the drug content will be excreted by your system at a first order rate proportional to the amount left in your body, you call that k. Q represents the initial quantity that you ingested, and dQ/dt is your body's drug removal rate for Hydrocodone, t will be time in hours.

**dQ/dt = -k * Q**(1)Now you have to solve k. But first in order to do that, solve this differential equation using basic rules of calculus and derivative tables. Q_0 means initial quantity of Q at time 0.

**Q = Q_0 * e ^ ( −k * t)**(2)You have the internet at your disposal, you google "hydrocodone half life" and you find out that it's 3.8 hours. Knowing that you write another equation based off of (2). Based off the definition of half life, the quantity

**Q**of Hydrocodone in your body times*to the power of***e****-k**times the half life**t=3.8**is equal to half of whatever value of**Q**at that time was. So you write that out like so**(1/2) * Q_0 = Q_0 * e ^ (-k * 3.8)**(3)All you're doing is filling in the variables. Using algebra, you solve for k by moving all the other variables to the other side of the equal sign

**k = ( -1 / 3.8 )* ln 0.5**(4)**(5)**

k ~= 0.182

k ~= 0.182

## Anyone with Algebra level math skills can do this

eqThat's the full solution.

Line 1: Import differential equation solver library

Line 6: Declare function that represents differential equation.

Line 7: Use with(as.list(...)) to so function exists in list form, which the programming language prefers.

Line 8. The rate equation, we wrote above. k is the constant, Q is the quantity of Hydrocodone in our blood.

Line 9: Similar to line 7, returns result as a list which the program prefers.

Line 13: Giving the equation's initial conditions. Remember Q is quantity, and it was 10 mg. c is a constructor for a vector in R. Similar to 9 and 7, it's just a data-type for parameter inputs that the program prefers.

Line 14: The rate constant. You remember from equation (5) that k is approximately 0.182, so you define it as that in the form the program prefers (wrapped in c's constructor)

Line 15: You specify the time range you're interested. I did the 0th hour until the 24th hour, with a time step of 1 hour.

Line 16: You use the given solver ode, which takes in parameters (initialCondition, bounds, differential equation, parameters). Respectively those are defined as

Line 21: Plots out the data points, you're interested when the x value is 12, because that means its 10 hours away, right when your calculus test begins

When executed it shows this:

__Line by line Breakdown__Line 1: Import differential equation solver library

Line 6: Declare function that represents differential equation.

Line 7: Use with(as.list(...)) to so function exists in list form, which the programming language prefers.

Line 8. The rate equation, we wrote above. k is the constant, Q is the quantity of Hydrocodone in our blood.

Line 9: Similar to line 7, returns result as a list which the program prefers.

Line 13: Giving the equation's initial conditions. Remember Q is quantity, and it was 10 mg. c is a constructor for a vector in R. Similar to 9 and 7, it's just a data-type for parameter inputs that the program prefers.

Line 14: The rate constant. You remember from equation (5) that k is approximately 0.182, so you define it as that in the form the program prefers (wrapped in c's constructor)

Line 15: You specify the time range you're interested. I did the 0th hour until the 24th hour, with a time step of 1 hour.

Line 16: You use the given solver ode, which takes in parameters (initialCondition, bounds, differential equation, parameters). Respectively those are defined as

**y, times, pharm, parms.**

Line 21: Plots out the data points, you're interested when the x value is 12, because that means its 10 hours away, right when your calculus test begins

When executed it shows this:

If Q_0 = 10 , Q(12) = 10 * e ^ (−0.182 * 12) ≈ 1.126 mg. So there will be approximately 1.126 mg left in the body after 12 hours.

## Are we done yet?

As a teaser, I want to show you a few screen shots of what something like this really can do. I don't have time to type out another post but I have the graphs worked out already.

So another common scenario that comes up is when we're dealing with nootropics with very long half lives like Modafinil (~15 hrs), Clomiphene(~ 72 hrs), Memantine (~ 80 hours), Testosterone Enanthate (~ 240 hours) and dosing strategy over time, we end up not knowing what amount is left in our system. In our next post, we're going to be showing you

So another common scenario that comes up is when we're dealing with nootropics with very long half lives like Modafinil (~15 hrs), Clomiphene(~ 72 hrs), Memantine (~ 80 hours), Testosterone Enanthate (~ 240 hours) and dosing strategy over time, we end up not knowing what amount is left in our system. In our next post, we're going to be showing you

**A. A much more realistic representation of the above situation****B. How to plot these graphs so that you can plan for dosing long half life nootropics.**## Intestine (I) Quantity coupled with Blood (B) Quantity

Above shows how much of the drug exists in your instestines still waiting to be absorbed. Both are over a period of 10 days (240 hours)

Below shows your plasma concentration of a drug with a 72 hour half life, if you take 10 mg every 24 hours.

Below shows your plasma concentration of a drug with a 72 hour half life, if you take 10 mg every 24 hours.