flaremixEM             package:mixtools             R Documentation

_E_M _A_l_g_o_r_i_t_h_m _f_o_r _M_i_x_t_u_r_e_s _o_f _R_e_g_r_e_s_s_i_o_n_s _w_i_t_h _F_l_a_r_e

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

     Returns output for 2-component mixture of regressions with flaring
     using an EM algorithm with one step of Newton-Raphson requiring an
     adaptive barrier for maximization of the objective function. A
     mixture of regressions with flare occurs when there appears to be
     a common regression relationship for the data, but the error terms
     have a mixture structure of one normal component and one
     exponential component.

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

     flaremixEM(y, x, lambda = NULL, beta = NULL, sigma = NULL, 
                alpha = NULL, nu = NULL, epsilon = 1e-04, 
                maxit = 10000, verb = FALSE, restart = 50)

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

       y: An n-vector of response values.

       x: An n-vector of predictor values.  An intercept term will be
          added by default.

  lambda: Initial value of mixing proportions.  Entries should sum to
          1.

    beta: Initial value of 'beta' parameters.  Should be a 2x2 matrix
          where the columns corresond to the component.

   sigma: A vector of standard deviations.

   alpha: A scalar for the exponential component's rate.

      nu: A vector specifying the barrier constants to use.  The first
          barrier constant where the algorithm converges is used.

 epsilon: The convergence criterion.

   maxit: The maximum number of iterations.

    verb: If TRUE, then various updates are printed during each
          iteration of the algorithm.

 restart: The number of times to restart the algorithm in case
          convergence is not attained. The default is 50.

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

     'flaremixEM' returns a list of class 'mixEM' with items: 

       x: The set of predictors (which includes a column of 1's).

       y: The response values.

posterior: An nx2 matrix of posterior probabilities for observations.

  lambda: The final mixing proportions.

    beta: The final regression coefficients.

   sigma: The final standard deviations.

   alpha: The final exponential rate.

  loglik: The final log-likelihood.

all.loglik: A vector of each iteration's log-likelihood.

      ft: A character vector giving the name of the function.

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

     'regmixEM'

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

     ## Simulation output.

     j=1
     while(j == 1){
         x1=runif(30, 0, 10)
         x2=runif(20, 10, 20)
         x3=runif(30, 20, 30)
         y1=3+4*x1+rnorm(30, sd = 1)
         y2=3+4*x2+rexp(20, rate = .05)
         y3=3+4*x3+rnorm(30, sd = 1)
         x=c(x1, x2, x3)
         y=c(y1, y2, y3)
         nu=(1:30)/2

         out=try(flaremixEM(y, x, beta = c(3, 4), nu = nu,
                 lambda = c(.75, .25), sigma = 1), silent = TRUE)
         if(class(out) == "try-error"){
             j=1
         } else j=2
     }

     out[4:7]
     plot(x, y)
     abline(out$beta)

