# NOT RUN {
#Defining parallel_opt parallel settings.
#parallel_opt can also be left empty to be defined automatically by the function.
require(parallel)
num_workers <- min(c(detectCores(),2))
parall <- list(cl=makeCluster(num_workers), forward=FALSE, loginfo=TRUE)
#Fixed shift size (essentially Duncan's cycle model) - no optimisation.
stat_deg <- Markovstat(shiftfun="deg", h=1, k=1, sigma=1, s=0.2, delta=2.5)
res1 <- Markovchart(statdist=stat_deg, cs=1, crparams=20, coparams=50)
res1
# }
# NOT RUN {
#Fixed shift size (essentially Duncan's cycle model) - with optimisation.
res2 <- Markovchart(statdist=stat_deg, OPTIM=TRUE, cs=1, crparams=20, coparams=50,
lower = c(0.01,0.01), upper = c(5,5),
parallel_opt=parall)
res2
#Exponential shift - no optimisation - default cost functions.
stat_exp <- Markovstat(shiftfun="exp", h=0.5, k=2, sigma=1, s=0.2, delta=2,
RanRep=FALSE, Vd=30, V=18)
res3 <- Markovchart(stat_exp, p=0.9, cs=1, coparams=c(10,3), crparams=c(1,2))
res3
# }
# NOT RUN {
#Exponential shift - with optimisation - default cost functions.
stat_exp2 <- Markovstat(shiftfun="exp", h=1, k=1, sigma=1, s=0.2, delta=2,
RanRep=TRUE, alpha=1, beta=3, Vd=30, V=18)
parall <- list(cl=makeCluster(num_workers), forward=FALSE, loginfo=TRUE)
res4 <- Markovchart(statdist=stat_exp2, OPTIM=TRUE, p=0.9, cs=1,
coparams=c(10,3), crparams=c(1,2), vcoparams=c(8,1.5),
vcrparams=c(5,2), parallel_opt=parall)
res4
# }
# NOT RUN {
#Exponential-geometric mixture shift - no optimisation -
#random sampling - custom repair variance function.
stat_expgeo <- Markovstat(shiftfun="exp-geo",h=1.5, k=2, sigma=1,
s=0.2, delta=1.2, probmix=0.7, probnbin=0.8,
disj=2, RanRep=TRUE, alpha=1, beta=3, RanSam=TRUE,
StateDep=TRUE, a=1, b=15, Vd=100, V=8)
vcrfun_new <- function(mudist,vcrparams)
{
mudist=mudist
vcrb=vcrparams[1]
vcrs=vcrparams[2]
vcrs2=vcrparams[3]
vcr <- vcrb + vcrs/(mudist + vcrs2)
return(vcr)
}
res5 <- Markovchart(statdist=stat_expgeo, p=0.9, cs=1,
coparams=c(10,6), crparams=c(20,3),
vcoparams=c(10000,100), vcrfun=vcrfun_new,
vcrparams=c(50000,-600000,1.5))
res5
#Exponential shift - no optimisation - vectorised.
parall <- list(cl=makeCluster(num_workers), forward=FALSE, loginfo=TRUE)
Gmtx <- Markovchart(statdist=stat_exp2, h=seq(1,10,by=(10-1)/5),
k=seq(0.1,5,by=(5-0.1)/5), p=0.9, cs=1,
coparams=c(10,3), crparams=c(1,2),
vcoparams=c(8,1.5), vcrparams=c(5,2),
V=18, parallel_opt=parall)
Gmtx
# }
Run the code above in your browser using DataLab