refit                  package:lme4                  R Documentation

_R_e-_f_i_t _a _m_o_d_e_l _t_o _a _n_e_w _r_e_s_p_o_n_s_e _v_e_c_t_o_r

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

     This generic function fits a model to a new response vector.  It
     typically is used as part of a simulation.  For models fit by
     'lmer' or 'nlmer' it is much faster to use this function to re-fit
     the model than to begin from the model formula.

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

     refit(object, newresp, ...)

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

  object: a fitted model.  Methods are defined for models fit by 'lmer'
          and by 'nlmer'

 newresp: a new response vector - typically a numeric vector.

     ...: further arguments passed for some methods.

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

     For many model-fitting functions in R a large part of the
     execution time is taken up with converting a formula
     representation and the data argument into the numerical structures
     used to evaluate the parameter estimates.  It is common in a
     simulation to use the same model specification and covariate data
     on many simulated responses.  That is, the only thing that changes
     between model fits is the response vector. This generic function
     allows for the model specification to and covariate data to stay
     the same while the only the response vector is changed.

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

     a fitted model similar to 'object'

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

     fm1 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy)
     set.seed(54321)
     system.time(simfe <-
             data.frame(t(apply(simulate(fm1, nsim = 100),
                                2, function(y) fixef(refit(fm1, y)))),
                        check.names = FALSE))
     qqmath(~ `(Intercept)` + Days, simfe, outer = TRUE,
            ylab = NULL, scales = list(y = list(relation = "free")),
            layout = c(1,2), aspect = 1, type = c("g", "p"))
     sapply(simfe, mean)
     sapply(simfe, sd)

