library(saemixextension)
###WARFA
warfa_data <- read.table("data/warfarin_data.txt", header=T)
saemix.data_warfa<-saemixData(name.data=warfa_data,header=TRUE,sep=" ",na=NA, name.group=c("id"),
name.predictors=c("amount","time"),name.response=c("y1"), name.X="time")
model1cpt<-function(psi,id,xidep) {
dose<-xidep[,1]
tim<-xidep[,2]
ka<-psi[id,1]
V<-psi[id,2]
k<-psi[id,3]
CL<-k*V
ypred<-dose*ka/(V*(ka-k))*(exp(-k*tim)-exp(-ka*tim))
return(ypred)
}
saemix.model_warfa<-saemixModel(model=model1cpt,description="warfarin",type="structural"
,psi0=matrix(c(1,7,1,0,0,0),ncol=3,byrow=TRUE, dimnames=list(NULL, c("ka","V","k"))),
transform.par=c(1,1,1),omega.init=matrix(c(1,0,0,0,1,0,0,0,1),ncol=3,byrow=TRUE),
covariance.model=matrix(c(1,0,0,0,1,0,0,0,1),ncol=3,
byrow=TRUE))
###RTTE
timetoevent.saemix <- read.table("data/tte.saemix.csv", header=T, sep=",")
timetoevent.saemix <- timetoevent.saemix[timetoevent.saemix$ytype==2,]
saemix.data_rtte<-saemixData(name.data=timetoevent.saemix,header=TRUE,sep=" ",na=NA, name.group=c("id"),name.response=c("y"),name.predictors=c("time","y"), name.X=c("time"))
timetoevent.model<-function(psi,id,xidep) {
T<-xidep[,1]
N <- nrow(psi)
Nj <- length(T)
censoringtime = 20
lambda <- psi[id,1]
beta <- psi[id,2]
init <- which(T==0)
cens <- which(T==censoringtime)
ind <- setdiff(1:Nj, append(init,cens))
hazard <- (beta/lambda)*(T/lambda)^(beta-1)
H <- (T/lambda)^beta
logpdf <- rep(0,Nj)
logpdf[cens] <- -H[cens] + H[cens-1]
logpdf[ind] <- -H[ind] + H[ind-1] + log(hazard[ind])
return(logpdf)
}
saemix.model_rtte<-saemixModel(model=timetoevent.model,description="time model",type="likelihood",
psi0=matrix(c(2,1),ncol=2,byrow=TRUE,dimnames=list(NULL,
c("lambda","beta"))),
transform.par=c(1,1),covariance.model=matrix(c(1,0,0,1),ncol=2,
byrow=TRUE))
##RUNS
K1 = 200
K2 = 100
iterations = 1:(K1+K2+1)
end = K1+K2
#Warfarin
options_warfa<-list(seed=39546,map=F,fim=F,ll.is=F,
nbiter.mcmc = c(2,2,2), nbiter.saemix = c(K1,K2),nbiter.sa=0,
displayProgress=TRUE,save.graphs=FALSE,nbiter.burn =0)
warfa<-saemix(saemix.model_warfa,saemix.data_warfa,options_warfa)
#Weibull
options_rtte<-list(seed=39546,map=F,fim=F,ll.is=F,
nbiter.mcmc = c(2,2,2), nbiter.saemix = c(K1,K2),nbiter.sa=0
,displayProgress=TRUE,save.graphs=FALSE,nbiter.burn =0)
rtte<-saemix(saemix.model_rtte,saemix.data_rtte,options_rtte)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.