moc                   package:moc                   R Documentation

_G_e_n_e_r_a_l _N_o_n_l_i_n_e_a_r _M_i_x_t_u_r_e _o_f _C_u_r_v_e_s.

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

     `moc' fits user-specified mixture of curves models to one,two and
     three parameters distributions. The likelihood for the vector of
     observation over time or repeated measurements of a subject takes
     the form


 f( Y[i] = y[i] | Z[i] = z[i], W[i] = w[i])  = Sum_k P( C[i] = k | z[i]) h( y[i] | C[i] = k, w[i])


     The C[i] represents the mixture groups ( or latent classes ) and
     h() the conditional joint density of Y[i] given the covariates.
     The user supplies either the joint or marginal conditional
     density(ies) of the components of Y[i]. In the latter case, the
     joint conditional density is constructed by taking the product of
     the marginal densities. Censoring should be  handled by the
     supplied density.  The user can also define the mixture
     probability function.

     The procedure minimizes the resulting -log likelihood without
     constraints, the parameters are all assumed to be real numbers.
     Thus the user should supply appropriate link functions and
     parameterize the density accordingly ( see the examples ).

     The printed output includes  -2 log likelihood, the corresponding
     df, AIC and BIC, mean mixture probabilities, mean expected and
     observed latent curves, the maximum likelihood estimates and
     standard errors.

     The deviance residuals, fitted values and posterior probabilities
     are obtained through the use of the methods `residuals',`fitted'
     and `post'. The user has the option of weighting the residuals
     according to the posterior mixture probabilities.

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

            moc(y, density=NULL, joint=FALSE, groups=1,
            gmu=NULL, gshape=NULL, gextra=NULL, gmixture=glogit, expected = NULL,
            pgmu=NULL, pgshape=NULL, pgextra=NULL, pgmix=NULL, wt=1,
            ndigit=10, gradtol=0.0001, steptol=gradtol,iterlim=100,...)

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

       y: A matrix giving the vector of observations for each subject.

 density: A function giving the conditional joint or marginal density
          of the observations and calling the location, shape and extra
          functions.

   joint: Specify if the density gives the joint or common marginal
          density of the vector of observations.

  groups: Number of mixtures.

     gmu: A user-specified function of `pgmu', giving the regression 
          equation of the location parameter for each time and latent
          groups. The function should return a vector of length
          times*groups when the locations are the same across
          individuals or a matrix of n such vectors.

  gshape: A user-specified function of `pgshape', giving the regression
          equation of the dispersion or shape parameter for each  time
          and latent groups. The function should return a vector of 
          length times*groups or a matrix of n such vectors.  This
          function is usually parametrized such that the parameters 
          are the log of the dispersion.

  gextra: A user-specified function of `pgextra', giving the regression
          equation of the extra parameter for each time and latent
          groups. The function should return a vector of length
          times*groups or a matrix of n such vectors.

gmixture: A user-specified function `pgmix', giving the regression 
          function of the mixture probabilities. The function should
          return  a vector of length groups or a matrix of n such
          vectors.  The default is the the inverse generalized logit.

expected: A function returning the expected response value with respect
          to the parameters. This function will be used to compute the
          fitted values and response residuals (not deviance). By
          default, `gmu' will be taken. It is especially useful for
          cases where the location function dosn't correspond to the
          expected value as for censored normal or zero inflated
          poisson distributions. 

    pgmu: Vector of initial estimates for parameters of the location
          function.

 pgshape: Vector of initial estimates for parameters of the shape
          function.

 pgextra: Vector of initial estimates for parameters of the extra
          function.

   pgmix: Vector of initial estimates for parameters of the mixture
          function.

      wt: Weight vector.

ndigit,gradtol,steptol,iterlim,...: Arguments controlling `nlm'.

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

     A list of class `moc' is returned that contains all of the
     relevant information calculated, including error codes.

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

     Bernard Boulerice <Bernard.Boulerice@umontreal.ca>

_R_e_f_e_r_e_n_c_e_s:

     McLachlan, Geoffrey and Peel, David (2000) Finite mixture
     models,Wiley-Interscience, New York.

     Roeder, K., Lynch, K. and Nagin, D. (1999) Modeling Uncertainty in
     Latent Class Membership: A Case Study in Criminology, J. Amer.
     Statist. Assoc., 94, pp. 766-776.

     Lindsay, Bruce G. and Roeder, K. (1992) Residual diagnostics for
     mixture models, J. Amer. Statist. Assoc., 87, pp. 785-794.

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

     `residuals.moc',`fitted.moc',`post.moc',`AIC.moc',`logLik.moc',`nl
     m'

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

     data(hyp)

     # Censored Normal

     cnorm<-function(x,mu,sig,min,max)
     {mi<-(x==min)*1
     ma<-(x==max)*1
     mi*pnorm((min-mu)/sig)+ma*(1-pnorm((max-mu)/sig))+(1-mi-ma)*dnorm((x-mu)/sig)/sig}

     cmean<-function(mu,sig,min,max) {
     max-(max-mu)*pnorm((max-mu)/sig)+(min-mu)*pnorm((min-mu)/sig)-sig*(dnorm((max-mu)/sig)-dnorm((min-mu)/sig)) }

     cnorm1<-function(x,mu,sig,...) {cnorm(x,mu,sig,0,10)}
     gmu1<- function(p) {rbind(c(rep(p[1],3),rep(p[2],3),rep(p[3],3)))}
     # Homogeneous variances

     gshape1<- function(p) {rbind(c(rep(exp(p[1]),9)))}
     cmean1<-function(p) { cmean(gmu1(p[1:3]),gshape1(p[4]),0,10) }

     moc1<-
     moc(hyp[,2:4],density=cnorm1,groups=3,gmu=gmu1,gshape=gshape1,expected=cmean1,
     pgmu=c(2.1, 4.5, 7.8),pgshape=c(0.56),pgmix=c(0.6, -1.0), gradtol=1E-4)


     # Heterogeneous variances across latent groups

     gshape2<-function(p) {rbind(c(rep(exp(p[1]),3),rep(exp(p[2]),3),rep(exp(p[3]),3)))}

     moc2<-
     moc(hyp[,2:4],density=cnorm1,groups=3,gmu=gmu1,gshape=gshape2,
     pgmu=moc1$coef[1:3],pgshape=c(rep(moc1$coef[4],3)),pgmix=moc1$coef[5:6],gradtol=1E-4)

     # Heterogeneous variances across time

     gshape3<-function(p) {rbind(c(rep(c(exp(p[1]),exp(p[2]),exp(p[3])),3)))}

     moc3<-
     moc(hyp[,2:4],density=cnorm1,groups=3,gmu=gmu1,gshape=gshape3,
     pgmu=moc1$coef[1:3],pgshape=c(rep(moc1$coef[4],3)),pgmix=moc1$coef[5:6],gradtol=1E-4)

     times<-c(1.7,3,4.2)


     # Last class is a linear function of time

     gmu1t<-function(p) {rbind(c(rep(p[1],3),rep(p[2],3),p[3]+p[4]*times))}

     moc4<-
     moc(hyp[,2:4],density=cnorm1,groups=3,gmu=gmu1t,gshape=gshape1,
     pgmu=c(moc1$coeff[1:3],0),pgshape=c(moc1$coef[4]),pgmix=moc1$coef[5:6],gradtol=1E-4)

     # Zero inflated Poisson log-linear in time for the third class

     zip<- function(x,la,shape=1,extra)
     { mix<- exp(extra)/(1+exp(extra))
       mix*(x==0)+(1-mix)*dpois(x,la) }

     gmup<-function(p) {rbind(c(rep(exp(p[1]),3),rep(exp(p[2]),3),exp(p[3]+p[4]*times)))}

     zipfit<-function(p) { gmup(p)/(1+exp(p[5]))}

     gextrap<-function(p) {rbind(c(rep(p[1],9)))}

     moc5<-
     moc(hyp[,2:4],density=zip,groups=3,gmu=gmup,gextra=gextrap,expected = zipfit,
     pgmu=c(0.6, 1.5, 1.9, 0),pgextra=c(-9),pgmix=c(1, -0.5), gradtol=1E-4)


     # Standard Poisson with mixture depending on time independant covariate

     dumm<-hyp[,1]-1
     gmixt<-function(pm)
         {mix<-cbind(pm[1]+pm[2]*dumm,pm[3]+pm[4]*dumm)
     cbind(1,exp(mix))/(1+apply(exp(mix),1,sum))}

     poiss<-function(x,la,...) {dpois(x,la)}

     moc6<-
     moc(hyp[,2:4],density=poiss,groups=3,gmu=gmup,gmixture=gmixt,
     pgmu=c(0.6, 1.5, 1.9, 0),pgmix=c(1.6,-1,0.4,-1),gradtol=1E-4)

