Last data update: 2014.03.03

R: Returns the stationary distribution of a Markov chain.
statdisR Documentation

Returns the stationary distribution of a Markov chain.

Description

Given a transition matrix A, returns the stationary distribution of a Markov chain by computing the eigen vectors of A.

Usage

statdis(A)

Arguments

A

Transition probability matrix, a squared matrix of probabilities (0 ≤ p ≤ 1) with row and column length equal to that of alpha and beta and row sum and column sum both equal to 1 (within some numerical deviation of 1e-6).

Value

w

Stationary weights for the distributions of K components based on the transition probability matrix.

Author(s)

Yue Li

References

Capp'e, O. (2001). H2M : A set of MATLAB/OCTAVE functions for the EM estimation of mixtures and hidden Markov models. (http://perso.telecom-paristech.fr/cappe/h2m/)

See Also

nbh_em

Examples

	
# Simulate data
TRANS_s <- matrix(c(0.9, 0.1, 0.3, 0.7), nrow=2, byrow=TRUE)
alpha_s <- c(2, 4)
beta_s  <- c(1, 0.25)
Total <- 100

x <- nbh_gen(TRANS_s, alpha_s, beta_s, Total);

count <- x$count
label <- x$label

Total <- length(count)

# dummy initialization
TRANS0 <- matrix(rep(0.5,4), 2)

alpha0 <- c(1, 20)

beta0 <- c(1, 1)

NIT_MAX <- 50
TOL <- 1e-100
nbh <- nbh_em(count, TRANS0, alpha0, beta0, NIT_MAX, TOL)

map.accuracy <- length(which(max.col(nbh$postprob) == label))/Total

vit <- nbh_vit(count, nbh$TRANS, nbh$alpha, nbh$beta)

vit.accuracy <- length(which(vit$class == label))/Total

# Plot the marginal distribution (in the stationnary regime)
# Compute negative binomial distributions for all model states
t <- 0:max(count)

tmp <- nbh_em(t, nbh$TRANS, nbh$alpha, nbh$beta, 1)

dens <- tmp$dens

w <- statdis(nbh$TRANS)

# Plot estimate of marginal probabilities
marprob <- apply(t(dens) * (t(w) %*% matrix(1, ncol=length(t))), 2, sum)

plot(t, marprob, pch=8, col="blue", main="Estimated marginal distribution")

# Plot empirical estimated probabilities
dhist <- matrix(0, ncol=length(t))

for(i in t){
	dhist[1+i] <- sum(count == i)/Total	
}

points(t, dhist, pch=3, col="red")

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(RIPSeeker)
Loading required package: S4Vectors
Loading required package: stats4
Loading required package: BiocGenerics
Loading required package: parallel

Attaching package: 'BiocGenerics'

The following objects are masked from 'package:parallel':

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked from 'package:stats':

    IQR, mad, xtabs

The following objects are masked from 'package:base':

    Filter, Find, Map, Position, Reduce, anyDuplicated, append,
    as.data.frame, cbind, colnames, do.call, duplicated, eval, evalq,
    get, grep, grepl, intersect, is.unsorted, lapply, lengths, mapply,
    match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, rank,
    rbind, rownames, sapply, setdiff, sort, table, tapply, union,
    unique, unsplit


Attaching package: 'S4Vectors'

The following objects are masked from 'package:base':

    colMeans, colSums, expand.grid, rowMeans, rowSums

Loading required package: IRanges
Loading required package: GenomicRanges
Loading required package: GenomeInfoDb
Loading required package: SummarizedExperiment
Loading required package: Biobase
Welcome to Bioconductor

    Vignettes contain introductory material; view with
    'browseVignettes()'. To cite Bioconductor, see
    'citation("Biobase")', and for packages 'citation("pkgname")'.

Loading required package: Rsamtools
Loading required package: Biostrings
Loading required package: XVector
Loading required package: GenomicAlignments
Loading required package: rtracklayer
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/RIPSeeker/statdis.Rd_%03d_medium.png", width=480, height=480)
> ### Name: statdis
> ### Title: Returns the stationary distribution of a Markov chain.
> ### Aliases: statdis
> 
> ### ** Examples
> 	
> # Simulate data
> TRANS_s <- matrix(c(0.9, 0.1, 0.3, 0.7), nrow=2, byrow=TRUE)
> alpha_s <- c(2, 4)
> beta_s  <- c(1, 0.25)
> Total <- 100
> 
> x <- nbh_gen(TRANS_s, alpha_s, beta_s, Total);
> 
> count <- x$count
> label <- x$label
> 
> Total <- length(count)
> 
> # dummy initialization
> TRANS0 <- matrix(rep(0.5,4), 2)
> 
> alpha0 <- c(1, 20)
> 
> beta0 <- c(1, 1)
> 
> NIT_MAX <- 50
> TOL <- 1e-100
> nbh <- nbh_em(count, TRANS0, alpha0, beta0, NIT_MAX, TOL)
Iteration 0:	-298.930
Iteration 1:	-245.659
Iteration 2:	-238.285
Iteration 3:	-237.340
Iteration 4:	-237.145
Iteration 5:	-237.027
Iteration 6:	-236.932
Iteration 7:	-236.854
Iteration 8:	-236.789
Iteration 9:	-236.735
Iteration 10:	-236.690
Iteration 11:	-236.652
Iteration 12:	-236.620
Iteration 13:	-236.592
Iteration 14:	-236.567
Iteration 15:	-236.546
Iteration 16:	-236.527
Iteration 17:	-236.510
Iteration 18:	-236.494
Iteration 19:	-236.480
Iteration 20:	-236.467
Iteration 21:	-236.455
Iteration 22:	-236.444
Iteration 23:	-236.434
Iteration 24:	-236.424
Iteration 25:	-236.415
Iteration 26:	-236.406
Iteration 27:	-236.397
Iteration 28:	-236.389
Iteration 29:	-236.381
Iteration 30:	-236.374
Iteration 31:	-236.366
Iteration 32:	-236.359
Iteration 33:	-236.353
Iteration 34:	-236.346
Iteration 35:	-236.340
Iteration 36:	-236.333
Iteration 37:	-236.327
Iteration 38:	-236.322
Iteration 39:	-236.316
Iteration 40:	-236.310
Iteration 41:	-236.305
Iteration 42:	-236.300
Iteration 43:	-236.295
Iteration 44:	-236.290
Iteration 45:	-236.285
Iteration 46:	-236.280
Iteration 47:	-236.276
Iteration 48:	-236.271
Iteration 49:	-236.267
> 
> map.accuracy <- length(which(max.col(nbh$postprob) == label))/Total
> 
> vit <- nbh_vit(count, nbh$TRANS, nbh$alpha, nbh$beta)
> 
> vit.accuracy <- length(which(vit$class == label))/Total
> 
> # Plot the marginal distribution (in the stationnary regime)
> # Compute negative binomial distributions for all model states
> t <- 0:max(count)
> 
> tmp <- nbh_em(t, nbh$TRANS, nbh$alpha, nbh$beta, 1)
Iteration 0:	-216.205
> 
> dens <- tmp$dens
> 
> w <- statdis(nbh$TRANS)
> 
> # Plot estimate of marginal probabilities
> marprob <- apply(t(dens) * (t(w) %*% matrix(1, ncol=length(t))), 2, sum)
> 
> plot(t, marprob, pch=8, col="blue", main="Estimated marginal distribution")
> 
> # Plot empirical estimated probabilities
> dhist <- matrix(0, ncol=length(t))
> 
> for(i in t){
+ 	dhist[1+i] <- sum(count == i)/Total	
+ }
> 
> points(t, dhist, pch=3, col="red")
> 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>