r-statistics-fanの日記

統計好き人間の覚書のようなもの

TDM

鬼のように忙しい怒涛の2週間であった。 やっと落ち着いてきたので、ちょっとRで遊ぶ。

時間のあるときに遊びでTDMのシミュレーションをしたい。 とりあえず、基本事項として波形を書いてみる。今後続きがあるかどうかは自分でもわからないが、%TAMなどの計算も実装できたらと思う。

なんかRmarkdownをアップデートしたら、うまくHTMLがhatenaに許容されない。うーむ困った。物理的に図のファイルを貼ってしのぐことにする。

nmax <- 10
d <- c(rep(2000, nmax))  #dose mg
Ti <- c(rep(2, nmax))  #infusion time hour
cl <- c(rep(12.01, nmax))    #clrearance L/hour
ke <- c(rep(0.2 , nmax))  #ke  /hour
int <- 8   #infusion interval
time2 <- c(seq(from = 0, to = int * (10 - 1), by = 8))

cpiv <- function(x, d = d[1], Ti = Ti[1], cl = cl[1], ke = ke[1]){
      d/Ti/cl * (1-exp(-ke*x))*(x < Ti) + (x >= Ti)*d/Ti/cl * (1-exp(-ke*Ti))*exp(-ke*(x-Ti))
}

cpn <- function(x, time2 = time2[1], d = d[1], Ti = Ti[1], cl = cl[1], ke = ke[1]){
      cpiv(x - time2, d = d, Ti = Ti, cl = cl, ke = ke)* (x >= time2)
} 

cp.sum <- function(x, nmax){
      res <- 0
      for (i in 1:nmax){
            res <- res + cpn(x,time2[i],d = d[i], Ti = Ti[i], cl = cl[i], ke = ke[i])  
      }
      return(res)
}

curve(cp.sum(x, nmax = nmax), 0, 100)

 

f:id:r-statistics-fan:20140702002352p:plain

今日はここまで