coefFrame              package:gmodels              R Documentation

_R_e_t_u_r_n _m_o_d_e_l _p_a_r_a_m_e_t_e_r_s _i_n _a _d_a_t_a _f_r_a_m_e

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

     Fits a model to each subgroup defined by 'by', then returns a data
     frame with one row for each fit and one column for each parameter.

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

     coefFrame(mod, data, by = NULL, fit.on = TRUE, fitfun, keep.unused.levels = TRUE, byvar.sep = "\001", ...) 

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

     mod: a model formula, to be passed to by 'fitfun'.

    data: a data frame, row subsets of which will be used as the 'data'
          argument to 'fitfun'.

      by: names of columns in 'x' that will be used to define the
          subgroups.

  fit.on: a logical vector indicating which rows of 'x' are to be used
          to fit the model (like the 'subset' argument in a lot of
          other functions). Can be given in terms of variables in 'x'

  fitfun: a model fitting function (e.g. lm, nls). More specifically, a
          function that expects at least a formula object (as the first
          argument) and a data.frame object (passed as an argument
          named 'data') and returns a model object for which a 'coef'
          method has been defined (e.g. coef.lm, coef.nls) to extract
          fit values of model parameters.

keep.unused.levels: Include rows in output for all unique values of
          'by', even those which were excluded by 'fit.on'. The default
          value 'TRUE' should be left alone if you are going to go on
          to pass the result to 'backFit'.

byvar.sep: passed to 'frameApply', used to form the subsets of the
          data.

     ...: other arguments to pass to 'fitfun'.

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

     a data frame with a row for each unique row of 'x[by]', and column
     for each model paramter, as well as columns specified in 'by'.

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

     Jim Rogers james_a_rogers@groton.pfizer.com

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

     # load example data
     library(gtools)
     data(ELISA)

     # Coefficients for four parameter logistic fits:
     coefFrame(log(Signal) ~ SSfpl(log(Concentration), A, B, xmid, scal),
                data = ELISA, fitfun = nls,
                by = c("PlateDay", "Read"),
                fit.on = Description == "Standard" & Concentration != 0)

     # Coefficients for linear fits:
     coefFrame(log(Signal) ~ log(Concentration), 
                data = ELISA, fitfun = lm, 
                by = c("PlateDay", "Read"),
                fit.on = Description == "Standard" & Concentration != 0 )

     # Example passing arguments to fitfun, and example of
     # error handling during model fitting:
     ELISA$Signal[1] <- NA
     coefFrame(log(Signal) ~ log(Concentration), 
                data = ELISA, fitfun = lm, na.action = na.fail,
                by = c("PlateDay", "Read"),
                fit.on = Description == "Standard" & Concentration != 0 )

