dat<- read.table ("Contracts_Red.txt",header=TRUE) Anzahl<- c(4,3,3,3,3,2,2) # number of states to which transition was possible Zielstates<- read.table("Zielstates.txt", header=FALSE) ldist <- function (x) { #log(distribution function) of the exponential distribution a2<- max(0.0000001,x[2]) y <- log(1-exp(-(x[1]+0.5)/a2)) y } ldens <- function (x) { a2<- max(0.0000001,x[2]) y <- if (x[1]>0.5) log(exp(-(x[1]-0.5)/a2)-exp(-(x[1]+0.5)/a2)) else log(1-exp(-(x[1]+0.5)/a2)) y } L<- function(z) { #implements (9) from the paper, i.e. determines the logLikelihood score from one source state z[1] to other states i, parameters z[i] of the exponential distributions given LL<- 0 for (i in 1:5199) if (dat[i,25]==z[1]){ for (m in 1:Anzahl[z[1]+1]) { x<- c(dat[i,20],z[m+1]) if (Zielstates[z[1]+1,m]==dat[i,24]) LL<- LL-ldens(x) else LL<- LL-ldist(x)} if (dat[i,22]>0) for (m in 1:Anzahl[z[1]+1]){ x<- c(dat[i,22],z[m]) LL<- LL-ldist(x)} } return(LL) } A <- array(0,c(7,4)) #number of transitions from one state to another B <- array(0,c(7,5)) # parameter estimation according to (11) in the paper, B[.5]=likelihood score of the different source states rr<- 0 for (n in 1:7) { State<- n-1; r<-0 for (i in 1:5199) if (dat[i,25]==State){ r<- r+dat[i,20]+dat[i,22] for (m in 1:Anzahl[n]) if (Zielstates[n,m]==dat[i,24]) A[n,m]<- A[n,m]+1 } z<- array(State,c(Anzahl[n]+1)) for (m in 1:Anzahl[n]) z[m+1]<- B[n,m]<- r/A[n,m] B[n,5]<- L(z) rr<- rr+r } print(Zielstates) print(B) print(A) print(rr/324) # checks whether transition times sum up to 600 sec # source("Expo.R")