depmix               package:depmixS4               R Documentation

_D_e_p_e_n_d_e_n_t _M_i_x_t_u_r_e _M_o_d_e_l _S_p_e_c_i_f_i_c_t_i_o_n: _t_h_e _l_o_n_g _w_a_y

_D_e_s_c_r_i_p_t_i_o_n:

     'makeDepmix' creates an object of class 'depmix'.  This function
     is meant for full control, e.g. specifying each response model and
     the transition and prior models 'by hand'.  For the default easier
     specification of models, please see 'depmix'.  This function is
     meant for specifying one's own response models.

_U_s_a_g_e:

             
             makeDepmix(response, transition, prior, ntimes = NULL, stationary = TRUE, 
         ...)        
             

_A_r_g_u_m_e_n_t_s:

response: A two-dimensional list of response models. See 'Details'.

transition: A list of transition models, each created by a call to
          'transInit' on for possibilities of specifying such models. 
          The lenght of this list should be the nubmer of states of the
          model.

   prior: The initial state probabilities model; created through a call
          to 'transInit'.

  ntimes: A vector specifying the lengths of individual, ie
          independent, time series. If not specified, the responses are
          assumed to form a single time series.

stationary: Logical indicating whether the transition models include
          time-varying covariates; used internally to determine the
          dimensions of certain arrays, notably 'trDens'.

     ...: Not used currently.

_D_e_t_a_i_l_s:

     The function 'makeDepmix' creates an S4 object of class 'depmix',
     which needs to be fitted using 'fit' to optimize the parameters.
     This function is provided to have full control, eg by specifying
     one's own response models with distributions that are not
     provided. 

     The response model(s) should be created by call(s) to 'response'
     or one's own created response models that should extend the
     response class and have the following methods: dens, predict and
     optionally fit.  The fit function should have an argument w,
     providing the weights.  If the fit function is not provided,
     optimization should be done by using Rdonlp (use method="donlp" in
     calling fit on the depmix model, this is currently not done
     automatically).  The first index of response models runs over the
     states of the model, and the seconde index over the responses to
     be modeled.

_V_a_l_u_e:

     See the 'depmix' help page for the return value, a 'depmix'
     object.

_A_u_t_h_o_r(_s):

     Ingmar Visser & Maarten Speekenbrink

_S_e_e _A_l_s_o:

     'fit', 'transInit', 'response', 'depmix-methods' for accessor
     functions to 'depmix' objects.

_E_x_a_m_p_l_e_s:

     # below example recreates the model from the depmix help page albeit in a
     # roundabout way

     data(speed)   

     rModels <- list(
             list(
                     GLMresponse(formula=rt~1,data=speed,family=gaussian(),pstart=c(5.52,.202)),
                     GLMresponse(formula=corr~1,data=speed,family=multinomial(),pstart=c(0.5,0.5))
             ),
             list(
                     GLMresponse(formula=rt~1,data=speed,family=gaussian(),pstart=c(6.39,.24)),
                     GLMresponse(formula=corr~1,data=speed,family=multinomial(),pstart=c(.1,.9))
             )
     )

     trstart=c(0.9,0.1,0.1,0.9)

     transition <- list()
     transition[[1]] <- transInit(~1,nstates=2,data=data.frame(1),pstart=c(trstart[1:2]))
     transition[[2]] <- transInit(~1,nstates=2,data=data.frame(1),pstart=c(trstart[3:4]))

     instart=c(0,1)
     inMod <- transInit(~1,ns=2,ps=instart,data=data.frame(rep(1,3)))

     mod <- makeDepmix(response=rModels,transition=transition,prior=inMod,ntimes=attr(speed,"ntimes"))

     logLik(mod)

     fm <- fit(mod)

     fm 

     summary(fm)

