1

Currently my app needs to calculate the plasma concentration (multiple doses). I'm expecting it to be cyclical like depicted in this case: Wikipedia example

However, when I try to calculate and plot it out, it comes out like current graphed plot

The equation that I was told that it should be is relavent pharmacokentic equation and my function looks like the one below

function calculatePlasmaConcentration(x, bioavailability, vd, ka, ke, dosing, dose) {
    var firstPart, secondPart, c;

    firstPart = ((bioavailability * dose * ka) / (vd * ka - vd * ke));
    secondPart = (Math.exp(-ke * x) / (1 - Math.exp(-ke * dosing))) - (Math.exp(-ka * x) / (1 - Math.exp(-ka * dosing)));
c = firstPart * secondPart;

    return c;
}

I can't seem to see that I wrote the equation wrong, what am I doing wrong? the parameter x should be time in hours.

adding the default values here:

defaultDrugInfo = {
    dose: 500,
    dosing: 24,
    bioavailability: .89,
    ka: .883,
    ke: .0578,
    vd: 6,
    optimalTopRange: 10,
    optimalBottomRange: 5
}

Thanks in advance!

Community
  • 1
  • 1
Daemedeor
  • 1,013
  • 10
  • 22
  • you can print out those two parts and find out what's wrong – dandice Nov 12 '14 at 23:04
  • 1
    Could you provide the variables `ke`, `dosing` and `dose`? – Weafs.py Nov 12 '14 at 23:06
  • @chocolateentities well the problem is that i didn't make the first graph so i have no idea of the points at every step. and its not that the equation is wrong per se... just wondering why it's not cyclical like the first graph. – Daemedeor Nov 13 '14 at 00:43
  • @Daemedeor - So, you want to compute plasma concentration for 0 - 104 hours? – Weafs.py Nov 13 '14 at 00:48
  • @chipChocolate.py well at least long enough to see some cyclical pattern like the first graph. – Daemedeor Nov 13 '14 at 00:56

1 Answers1

1

You need to call the function calculatePlasmaConcentration(...) this way:

Fiddle

// four cycles
for (cycle = 0; cycle < 4; cycle++) {
    // 24 hr dosing
    for (t = 0; t < 24; t++) {
        nums.push(Math.round(calculatePlasmaConcentration(t, 0.89, 6, 0.883, 0.0578, 24, 500) * 1000) / 1000);
    }
}

The graph created by the numbers generated by this function is:

enter image description here

[Edit]

When the time hits 24 hour intervals, the plasma concentration values for the next day are supposed to add up with the last plasma concentration value from the previous day, since the dose doesn't just disappear from the body.

Next, when we append the tau(τ), (i in our case) along with the plasma concentration value(temp.push([i + delta, pcStack + pc]);) we need to add up 24 to i, everytime the time hits 24 hour intervals.

Fiddle

This is the updated function.

function generateData(drugInfo) {
    var pcStack = 0;
    var temp = [],
        mainArray = [],
        tempObject = {};
    var start = 0;
    var end = 24;
    var delta = 0;
    for (cycle = 0; cycle < 4; cycle++) {
        for (i = 0; i < 24; i += 0.05) {
            var pc = calculatePlasmaConcentration(i, drugInfo.bioavailability, drugInfo.vd, drugInfo.ka, drugInfo.ke, drugInfo.dosing, drugInfo.dosage);
            temp.push([i + delta, pcStack + pc]);
        }
        pcStack += pc;
        delta += 24;
    }
    tempObject = {
        data: temp
    };
    mainArray.push(tempObject);
    return mainArray;
}
Weafs.py
  • 22,731
  • 9
  • 56
  • 78
  • hmmm interesting,, I think that the use of cycles is missing though? Cause when I tried it out, it just resolved back to the beginning. I'll see what I can do to fix it on my end. and then i'll mark it correct... cause i'm using flot's library to render the grpah so this is how i'm calling it right now: 'for (var i = 0; i < length; i += steps) { temp.push([i, func(i, drugInfo.bioavailability, drugInfo.vd, drugInfo.ka, drugInfo.ke, drugInfo.dosing, drugInfo.dosage)]);}' – Daemedeor Nov 13 '14 at 02:57
  • @Daemedeor - Please add the entire code to your question or create a [Fiddle](http://jsfiddle.net/). – Weafs.py Nov 13 '14 at 03:01
  • fair enough, one moment. – Daemedeor Nov 13 '14 at 03:04
  • Here you go an updated fiddle of what my thing is plotting without your updates: http://jsfiddle.net/cphske3r/1/ – Daemedeor Nov 13 '14 at 03:17
  • @Daemedeor - It's done! Check out the updated answer. – Weafs.py Nov 13 '14 at 04:49
  • oh @chipChocolate.py one note, isn't the pcStack supposed to equal the last pc so you're not "+=" instead you're just setting it at the last opertunity – Daemedeor Nov 13 '14 at 05:23
  • If you replace `+=` with `=`, it will just add it once. – Weafs.py Nov 13 '14 at 05:33
  • @Daemedeor - [Have a look at this](http://www.pharmpress.com/files/docs/clinical_pharmacokinetics_samplechapter.pdf#page=24&zoom=auto,-186,663). – Weafs.py Nov 13 '14 at 05:36