# NOT RUN {
## Gamma or Exponential
### if "priors" is not specified, this is an Exponetial distribution
data(NHMMdata)
attach(NHMMdata)
## Set to iters=40 for example only this should be in the thousands
my.nhmm=NHMM(y=ygamma[1:200,1:3], X=matrix(tX[,1:200],1,200),
K=3, iters=40, burnin=2, emdist="gamma", nmix=3, delta=TRUE)
OBIC(my.nhmm)
Oz(my.nhmm) #compare with the truth: tz1
OQQ(my.nhmm) #transition probabilities
# }
# NOT RUN {
bb=OXcoef(my.nhmm)
pp=OWcoef(my.nhmm,FALSE)
tt=Oemparams(my.nhmm,FALSE)
## Normal - X is not used to create this data, so it should not be significant
my.nhmm2=NHMM(y=ynormal, subseq=1000, X=tX, K=3, iters=100,
burnin=10, emdist="normal", nmix=2, delta=FALSE)
OBIC(my.nhmm2)
## Poisson
my.nhmm3=NHMM(y=ypoisson, X=tX, K=3, iters=100, burnin=10,
emdist="poisson", nmix=2, delta=FALSE)
OBIC(my.nhmm3)
## Predictive estimation - make 15 predictive data sets (new X) and 20 replicate data sets (same X)
#filelocation="C:\Users\iamrandom\Desktop\here\"
#my.nhmm4=NHMM(y=ygamma, X=tX, K=3, iters=100, burnin=10,
# emdist="gamma", nmix=3, delta=TRUE,
# outdir=filelocation, yrep=20, Xp=Xp1, ypred=15)
#OBIC(my.nhmm4) #needed larger burnin
#tt=Oemparams(my.nhmm4,TRUE,filelocation)
## Exponential with W variable
#filelocation="C:\Users\iamrandom\Desktop\here\"
#my.nhmm5=NHMM(y=ygamma, X=tX, W=tW1, K=3, iters=50, burnin=10,
# emdist="gamma", nmix=3, delta=TRUE,
# outdir=filelocation, yrep=20, Xp=Xp1, Wp=Wp1,ypred=35)
#OBIC(my.nhmm5)
#pp=OWcoef(my.nhmm5,filelocation)
## Gamma with fixed first variables nmix=2
nmix=2; K=3; J=dim(ygamma)[2]
prior1=array(1,dim=c(5,nmix,K,J)); prior1[1,1,,]=1;
prior1[1,2,,]=2; prior1[2,,,]=NA
my.nhmm6=NHMM(y=ygamma, X=tX, priors=prior1, K=3, iters=100,
burnin=10, emdist="gamma", nmix=2, delta=TRUE)
## One dimensional y vector case (J=1)
#my.nhmm=NHMM(y=matrix(ygamma[1:200,1],200,1), X=matrix(tX[,1:200],1,200),
#K=3, iters=40, burnin=2, emdist="gamma", nmix=3, delta=TRUE)
### Compare my.nhmm6 (K=3) and my.nhmm7 (K=1) using both BIC
### and PLS (yhold is the last 10% of the data)
#ygamma2=ygamma
#ygamma2[1600,10]=NA #add some missingness
#ygamma2[1840,10]=NA #add some missingness to yhold
#filelocation="C:\Users\iamrandom\Desktop\here\"
#my.nhmm7=NHMM(y=ygamma2[1:1800,], X=matrix(tX[,1:1800],1,1800),
# W=array(tW[,1:1800,],dim=c(1,1800,15)),
# K=3, iters=50, burnin=10, emdist="gamma", nmix=3,
# delta=TRUE, outdir=filelocation, ymiss=TRUE, yrep=10,
# Xp=matrix(tX[,1801:2000],1,200), Wp=array(tW[,1801:2000,],dim=c(1,200,15)),
# ypred=10, yhold=ygamma2[1801:2000,])
#OBIC(my.nhmm7)
#compare K=1 and K=3
# }
Run the code above in your browser using DataLab