Learn R Programming

HMMCont (version 1.0)

hmmsetcont: Setting an initial HMM object

Description

The function sets an initial Hidden Markov Model object with initial set of model parameters. It returns the object of class ContObservHMM that can be analysed with Baum-Welch (function baumwelchcont) and Viterbi algorithms (viterbicont).

Usage

hmmsetcont(Observations, Pi1 = 0.5, Pi2 = 0.5, A11 = 0.7, A12 = 0.3, A21 = 0.3, A22 = 0.7, Mu1 = 5, Mu2 = (-5), Var1 = 10, Var2 = 10)
"print"(x, ...) "summary"(object, ...) "plot"(x, Series=x$Observations, ylabel="Observation series", xlabel="Time", ...)

Arguments

Observations
Vector of observations (class "numeric"), a weakly stationary process (e.g. returns time series).
Pi1
Initial probability of state 1.
Pi2
Initial probability of state 2.
A11
Initial transition probability from state 1 to state 1.
A12
Initial transition probability from state 1 to state 2.
A21
Initial transition probability from state 2 to state 1.
A22
Initial transition probability from state 2 to state 2.
Mu1
Initial mean for Gaussian PDF for state 1.
Mu2
Initial mean for Gaussian PDF for state 2.
Var1
Initial variance for Gaussian PDF for state 1.
Var2
Initial variance for Gaussian PDF for state 2.
x
An object returned by the function hmmsetcont.
object
An object returned by the function hmmsetcont.
Series
Observations time series to be plotted along the Markov states.
ylabel
Y axis label.
xlabel
X axis label.
...
Not used.

Value

The function returns an object of the class ContObservHMM that is a list comprising the observations, tables accumulating the model parameters and results after each Baum-Welch iterations (i.e. after each execution of the function baumwelchcont), table for the state sequence derived by the Viterbi algorithm (function viterbicont), and table of the b-probabilities. The object can be analysed with the class-specific functions print, summary, and plot.

See Also

Functions: baumwelchcont, viterbicont, and statesDistributionsPlot.

Examples

Run this code

Returns<-logreturns(Prices) # Getting a stationary process
Returns<-Returns*10 		# Scaling the values

hmm<-hmmsetcont(Returns) 	# Creating a HMM object
print(hmm) 					# Checking the initial parameters

for(i in 1:6){hmm<-baumwelchcont(hmm)} # Baum-Welch is 
# executed 6 times and results are accumulated
hmmcomplete<-viterbicont(hmm) # Viterbi execution
print(hmm) 		# Checking the accumulated parameters
summary(hmm) 	# Getting more detailed information
par(mfrow=c(2,1))
plot(hmmcomplete, Prices, ylabel="Price") 
plot(hmmcomplete, ylabel="Returns") # the revealed 
# Markov chain and the observations are plotted

Run the code above in your browser using DataLab