1

I would like to build a Markov chain with which I can simulate the daily routine of people (activity patterns). Each simulation day is divided into 144-time steps and the person can carry out one of fourteen activities.

I have already built the first order discrete-state Markov chain model using the function markovchainFit() in markovchain package.

I would like to build a second-order Markov chain model.

I don't know how to find the transition matrix (is the transition matrix constant at every time-step?), and if the second-order Markov chain model is better than the first order MC model? How to evaluate them?

Thank you!

MC1 <- markovchainFit(Aggregated) # MC1 is the fitted MC Model 

    dput(head(Aggregated, 5))
    structure(c(92, 11, 11, 11, 11, 13, 11, 11, 11, 11, 42, 11, 11, 
    11, 11, 41, 11, 11, 11, 11, 82, 11, 11, 11, 11, 12, 13, 11, 11, 
    11, 48, 41, 11, 11, 11, 12, 43, 11, 11, 11, 12, 43, 13, 11, 11, 
    12, 12, 12, 11, 11, 43, 12, 13, 11, 11, 42, 12, 13, 11, 11, 42, 
    12, 100, 11, 41, 42, 43, 100, 11, 61, 42, 43, 100, 11, 61, 41, 
    82, 100, 11, 12, 41, 82, 100, 11, 61, 41, 82, 100, 11, 61, 41, 
    82, 100, 11, 61, 82, 44, 31, 11, 12, 61, 44, 31, 11, 13, 61, 
    42, 31, 11, 13, 61, 42, 31, 41, 13, 61, 42, 31, 83, 13, 61, 42, 
    31, 83, 47, 82, 12, 31, 83, 100, 82, 61, 31, 83, 100, 82, 42, 
    31, 83, 100, 82, 42, 31, 83, 44, 82, 61, 31, 83, 44, 82, 61, 
    31, 83, 44, 41, 61, 31, 92, 44, 61, 61, 31, 92, 44, 61, 61, 31, 
    92, 100, 91, 61, 31, 92, 100, 91, 61, 31, 92, 100, 91, 100, 31, 
    92, 100, 91, 46, 31, 92, 41, 91, 46, 31, 92, 12, 91, 46, 31, 
    92, 12, 91, 46, 31, 92, 12, 91, 46, 31, 92, 12, 91, 46, 31, 92, 
    92, 12, 46, 31, 46, 92, 12, 12, 31, 46, 92, 12, 12, 12, 46, 92, 
    12, 12, 12, 46, 92, 12, 12, 12, 46, 92, 12, 12, 12, 46, 92, 100, 
    46, 12, 46, 92, 100, 46, 12, 46, 92, 100, 100, 12, 46, 92, 100, 
    100, 31, 46, 92, 100, 42, 31, 46, 92, 100, 42, 31, 46, 61, 46, 
    42, 31, 46, 12, 46, 41, 31, 46, 12, 46, 41, 31, 46, 92, 46, 41, 
    100, 46, 92, 46, 41, 100, 46, 92, 46, 41, 100, 46, 92, 42, 41, 
    100, 46, 92, 42, 41, 100, 46, 92, 41, 41, 100, 46, 92, 41, 41, 
    100, 42, 92, 41, 41, 100, 42, 92, 41, 41, 100, 42, 91, 82, 41, 
    83, 83, 41, 82, 63, 83, 83, 41, 82, 63, 83, 83, 41, 82, 63, 83, 
    83, 41, 82, 63, 83, 83, 82, 82, 63, 83, 83, 82, 12, 41, 83, 83, 
    82, 12, 41, 83, 83, 82, 12, 12, 31, 83, 41, 12, 12, 31, 83, 12, 
    12, 12, 31, 31, 12, 92, 12, 31, 31, 12, 92, 42, 12, 13, 92, 92, 
    42, 12, 92, 92, 92, 42, 12, 92, 92, 92, 42, 92, 92, 92, 92, 42, 
    92, 92, 92, 92, 42, 92, 92, 92, 41, 41, 92, 92, 92, 41, 41, 92, 
    92, 92, 41, 41, 92, 92, 92, 41, 92, 41, 92, 92, 41, 92, 12, 92, 
    92, 61, 92, 31, 92, 92, 82, 92, 31, 92, 92, 82, 92, 31, 61, 92, 
    82, 92, 31, 61, 92, 82, 92, 13, 61, 92, 82, 92, 92, 61, 92, 82, 
    92, 92, 61, 82, 61, 13, 13, 11, 82, 61, 13, 11, 11, 82, 61, 13, 
    11, 11, 82, 61, 13, 11, 11, 82, 61, 13, 11, 11, 44, 61, 13, 11, 
    11, 44, 61, 11, 11, 11, 13, 61, 11, 11, 11, 91, 61, 11, 11, 11, 
    91, 61, 11, 11, 11, 91, 82, 11, 11, 11, 11, 82, 11, 11, 11, 11, 
    82, 11, 11, 11, 11, 82, 11, 11, 11, 11, 82, 11, 11, 11, 11, 82, 
    11, 11, 11, 11, 82, 11, 11, 11, 11, 82, 11, 11, 11, 11, 11, 11, 
    11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 
    11, 11, 11, 11, 11, 11, 13, 11, 11, 11, 11, 11, 11, 11, 11, 11, 
    11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 
    11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 
    11, 11, 11, 13, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 
    11, 11, 11, 11, 11, 11, 11, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
    0, 0, 0), .Dim = c(5L, 144L), .Dimnames = list(NULL, c("act1_12", 
    "act1_13", "act1_14", "act1_15", "act1_16", "act1_17", "act1_18", 
    "act1_19", "act1_20", "act1_21", "act1_22", "act1_23", "act1_24", 
    "act1_25", "act1_26", "act1_27", "act1_28", "act1_29", "act1_30", 
    "act1_31", "act1_32", "act1_33", "act1_34", "act1_35", "act1_36", 
    "act1_37", "act1_38", "act1_39", "act1_40", "act1_41", "act1_42", 
    "act1_43", "act1_44", "act1_45", "act1_46", "act1_47", "act1_48", 
    "act1_49", "act1_50", "act1_51", "act1_52", "act1_53", "act1_54", 
    "act1_55", "act1_56", "act1_57", "act1_58", "act1_59", "act1_60", 
    "act1_61", "act1_62", "act1_63", "act1_64", "act1_65", "act1_66", 
    "act1_67", "act1_68", "act1_69", "act1_70", "act1_71", "act1_72", 
    "act1_73", "act1_74", "act1_75", "act1_76", "act1_77", "act1_78", 
    "act1_79", "act1_80", "act1_81", "act1_82", "act1_83", "act1_84", 
    "act1_85", "act1_86", "act1_87", "act1_88", "act1_89", "act1_90", 
    "act1_91", "act1_92", "act1_93", "act1_94", "act1_95", "act1_96", 
    "act1_97", "act1_98", "act1_99", "act1_100", "act1_101", "act1_102", 
    "act1_103", "act1_104", "act1_105", "act1_106", "act1_107", "act1_108", 
    "act1_109", "act1_110", "act1_111", "act1_112", "act1_113", "act1_114", 
    "act1_115", "act1_116", "act1_117", "act1_118", "act1_119", "act1_120", 
    "act1_121", "act1_122", "act1_123", "act1_124", "act1_125", "act1_126", 
    "act1_127", "act1_128", "act1_129", "act1_130", "act1_131", "act1_132", 
    "act1_133", "act1_134", "act1_135", "act1_136", "act1_137", "act1_138", 
    "act1_139", "act1_140", "act1_141", "act1_142", "act1_143", "act1_144", 
    "othact1_1", "othact1_2", "othact1_3", "othact1_4", "othact1_5", 
    "othact1_6", "othact1_7", "othact1_8", "othact1_9", "othact1_10", 
    "othact1_11")))
Rfanatic
  • 2,224
  • 1
  • 5
  • 21
  • A second-order Markov chain is essentially a first-order one with an extended alphabet, e.g. instead of states `{92},{11},{11},...` you have `{92,11}, {11,11},...`. So if you can fit a order-one Markov chain you can use the same method in the correct representation. Note that the number of states grows exponentially with the model order. – VFreguglia Aug 16 '19 at 11:33
  • I also recommend looking at the `VLMC` package for fitting variable length Markov chains, as they allow you to increase the model order while controlling the number of free parameters. – VFreguglia Aug 16 '19 at 11:38

0 Answers0