Reputation: 21
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
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)
Upvotes: 0
Views: 48