@@ -1523,10 +1523,10 @@ List inferHyperparam(NumericMatrix transMatr = NumericMatrix(), NumericVector sc
1523
1523
// ' Used only when \code{method} equal to "mle".
1524
1524
// ' @param confint a boolean to decide whether to compute Confidence Interval or not.
1525
1525
// ' @param hyperparam Hyperparameter matrix for the a priori distribution. If none is provided,
1526
- // ' default value of 1 is assigned to each parameter. This must be of size kxk
1527
- // ' where k is the number of states in the chain and the values should typically
1528
- // ' be non-negative integers.
1529
- // ' @param stringchar It can be a nx2 matrix or a character vector or a list
1526
+ // ' default value of 1 is assigned to each parameter. This must be of size
1527
+ // ' {k x k} where k is the number of states in the chain and the values
1528
+ // ' should typically be non-negative integers.
1529
+ // ' @param stringchar It can be a {n x n} matrix or a character vector or a list
1530
1530
// ' @param toRowProbs converts a sequence matrix into a probability matrix
1531
1531
// ' @param sanitize put 1 in all rows having rowSum equal to zero
1532
1532
// ' @param possibleStates Possible states which are not present in the given sequence
@@ -1549,7 +1549,7 @@ List inferHyperparam(NumericMatrix transMatr = NumericMatrix(), NumericVector sc
1549
1549
// ' package version 0.2.5
1550
1550
// '
1551
1551
// ' @author Giorgio Spedicato, Tae Seung Kang, Sai Bhargav Yalamanchi
1552
- // ' @note This function has been rewritten in Rcpp. Bootstrap algorithm has been defined "euristically ".
1552
+ // ' @note This function has been rewritten in Rcpp. Bootstrap algorithm has been defined "heuristically ".
1553
1553
// ' In addition, parallel facility is not complete, involving only a part of the bootstrap process.
1554
1554
// ' When \code{data} is either a \code{data.frame} or a \code{matrix} object, only MLE fit is
1555
1555
// ' currently available.
@@ -1581,6 +1581,10 @@ List markovchainFit(SEXP data, String method = "mle", bool byrow = true, int nbo
1581
1581
double confidencelevel = 0.95 , bool confint = true ,
1582
1582
NumericMatrix hyperparam = NumericMatrix(), bool sanitize = false,
1583
1583
CharacterVector possibleStates = CharacterVector()) {
1584
+
1585
+ if (method != " mle" && method != " bootstrap" && method != " map" && method != " laplace" ) {
1586
+ stop (" method should be one of \" mle\" , \" bootsrap\" , \" map\" or \" laplace\" " );
1587
+ }
1584
1588
1585
1589
// list to store the output
1586
1590
List out;
@@ -1607,55 +1611,50 @@ List markovchainFit(SEXP data, String method = "mle", bool byrow = true, int nbo
1607
1611
1608
1612
// byrow assumes distinct observations (trajectiories) are per row
1609
1613
// otherwise transpose
1610
- if (!byrow) {
1611
- mat = _transpose (mat);
1612
- }
1614
+ if (!byrow)
1615
+ mat = _transpose (mat);
1613
1616
1614
- S4 outMc =_matr2Mc (mat, laplacian, sanitize, possibleStates);
1617
+ S4 outMc = _matr2Mc (mat, laplacian, sanitize, possibleStates);
1615
1618
1616
1619
// whether to compute confidence interval or not
1617
1620
if (confint) {
1618
1621
// convert matrix to list
1619
1622
int nrows = mat.nrow ();
1620
1623
List manyseq (nrows);
1621
- for ( int i = 0 ;i < nrows;i++) {
1622
- manyseq[i] = mat (i,_);
1623
- }
1624
+
1625
+ for ( int i = 0 ; i < nrows; i++)
1626
+ manyseq[i] = mat (i, _);
1624
1627
1625
1628
out = _mcFitMle (manyseq, byrow, confidencelevel, sanitize, possibleStates);
1626
1629
out[0 ] = outMc;
1627
1630
} else {
1628
1631
out = List::create (_[" estimate" ] = outMc);
1629
1632
}
1630
1633
}
1631
- else if (TYPEOF (data) == VECSXP) {
1634
+ else if (TYPEOF (data) == VECSXP) {
1632
1635
if (method == " mle" ) {
1633
- out = _mcFitMle (data, byrow, confidencelevel, sanitize, possibleStates);
1636
+ out = _mcFitMle (data, byrow, confidencelevel, sanitize, possibleStates);
1634
1637
} else if (method == " map" ) {
1635
1638
out = _mcFitMap (data, byrow, confidencelevel, hyperparam, sanitize, possibleStates);
1636
- }
1639
+ } else
1640
+ stop (" method not available for a list" );
1637
1641
}
1638
1642
else {
1639
1643
if (method == " mle" ) {
1640
1644
out = _mcFitMle (data, byrow, confidencelevel, sanitize, possibleStates);
1641
- }
1642
-
1643
- if (method == " bootstrap" ) {
1645
+ } else if (method == " bootstrap" ) {
1644
1646
out = _mcFitBootStrap (data, nboot, byrow, parallel,
1645
1647
confidencelevel, sanitize, possibleStates);
1646
- }
1647
-
1648
- if (method == " laplace" ) {
1648
+ } else if (method == " laplace" ) {
1649
1649
out = _mcFitLaplacianSmooth (data, byrow, laplacian, sanitize, possibleStates);
1650
- }
1651
-
1652
- if (method == " map" ) {
1650
+ } else if (method == " map" ) {
1653
1651
out = _mcFitMap (data, byrow, confidencelevel, hyperparam, sanitize, possibleStates);
1654
1652
}
1655
1653
}
1656
1654
1657
1655
// markovchain object
1658
1656
S4 estimate = out[" estimate" ];
1657
+
1659
1658
if (name != " " ) {
1660
1659
estimate.slot (" name" ) = name;
1661
1660
}
0 commit comments