0

I am new to R. While making a Hidden markov model we have to give the following parameters; initial prob, emission prob, transition prob, observations. But I am getting the following error

Length of initial_probs is not equal to the number of states

Can someone help me how to resolve this error? Thanks in advance

Edit: Here is an example data which I uploaded on google drive

Sample data on google drive

Here is the code

    library(HMM)
    library(seqHMM)
    library(TraMineR)
    library(markovchain)

    let_alphabet <- c("1", "0", "2", "3", "4", "5", "6", "7", "8", "9", "10", "S", "D", "UK")
    let_labels <- c("i","O","ii","iii","iv","v","vi","vii","viii","ix","x","Son","Daughter","Unknown")
    let_scodes <- c("1","0","P2","P3","P4","P5","P6","P7","P8","P9","P10","Sn","Daugt","NA")
    let_seq <- seqdef(letsdo, 1:3, alphabet = let_alphabet, states = let_scodes,labels = let_labels, xtstep = 14)

    init_hmm_let <- build_hmm(observations = let_seq, n_states = 2)
   #Transition prob
  trp <- seqtrate(let_seq)
#Initial prob
    inist <- c(0.53, 0.47)
#Emission Prob
    emisp <- matrix(NA, nrow = 2, ncol = 2)
    emisp[1,]<- c(0.51,0.48)
    emisp[2,]<- c(0.58,0.41)
#Building the model
    init_hmm_let <- build_hmm( observations = let_seq, transition_probs = trp,
                                 emission_probs = emisp, initial_probs = inist)
  • Well, the error message seems pretty clear. Why not provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with some sample input data and the code you are actually running. Perhaps you are calling the function incorrectly? – MrFlick Oct 15 '18 at 19:09
  • This is the example data EduM1 Preg# Gender 1 1 S 1 2 UK 1 3 D 1 4 D 1 5 D 0 1 S 0 2 D 0 3 S 0 4 D 0 1 D 0 2 S 0 3 D 0 4 D 0 5 D 0 6 S 0 7 D 0 8 S 0 9 S 0 10 S @MrFlick – Aymen Tasneem Oct 16 '18 at 11:31
  • Edit your question to include this code so it can be properly formatted. Do not put this info in comments. – MrFlick Oct 16 '18 at 13:37
  • @MrFlick Kindly check, I edited my post. – Aymen Tasneem Oct 16 '18 at 18:12
  • I tried to run the code but `letsdo` was undefined. – MrFlick Oct 16 '18 at 18:33
  • I uploaded the dataset "letsdo" on google drive, and shared the link in my post. Kindly check @MrFlick – Aymen Tasneem Oct 17 '18 at 17:35
  • @MrFlick did you check the code.? – Aymen Tasneem Oct 23 '18 at 08:44
  • I'm sorry, I'm not going to download data files from remote sites. Questions should be self-contained for me to be interested in working on them, otherwise I just move on to the next one. – MrFlick Oct 23 '18 at 15:05

0 Answers0