gendata                package:Design                R Documentation

_G_e_n_e_r_a_t_e _D_a_t_a _F_r_a_m_e _w_i_t_h _P_r_e_d_i_c_t_o_r _C_o_m_b_i_n_a_t_i_o_n_s

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

     If 'nobs' is not specified, allows user to specify predictor
     settings by e.g. 'age=50, sex="male"', and any omitted predictors
     are set to reference values (default=median for continuous
     variables, first level for categorical ones - see 'datadist').  If
     any predictor has more than one value given, 'expand.grid' is
     called to generate all possible combinations of values.  If 'nobs'
     is given, a data frame is first generated which has 'nobs' of
     adjust-to values duplicated.  Then an editor window is opened
     which allows the user to subset the variable names down to ones
     which she intends to vary (this streamlines the 'data.ed' step). 
     Then, if any predictors kept are discrete and 'viewvals=TRUE', a
     window (using 'page') is opened defining the possible values of
     this subset, to facilitate data editing.  Then the 'data.ed'
     function is invoked to allow interactive overriding of predictor
     settings in the 'nobs' rows.  The subset of variables are combined
     with the other predictors which were not displayed with 'data.ed',
     and a final full data frame is returned. 'gendata' is most useful
     for creating a 'newdata' data frame to pass to 'predict'.

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

     gendata(fit, ...)
     ## S3 method for class 'Design':
     gendata(fit, nobs, viewvals=FALSE,
       editor=.Options$editor, ..., factors)
     ## Default S3 method:
     gendata(fit, ...)

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

     fit: a fit object created with 'Design' in effect 

    nobs: number of observations to create if doing it interactively
          using X-windows 

viewvals: if 'nobs' is given, set 'viewvals=TRUE' to open a window
          displaying the possible value of categorical predictors 

  editor: editor to use to edit the list of variable names to consider.
          Default is 'options(editor=)' value ('"xedit"' is this is not
          specified by 'using.X()==TRUE'. 

     ...: predictor settings, if 'nobs' is not given.  

 factors: a list containing predictor settings with their names.  This
          is an alternative to specifying the variables separatey in
          ... . 

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

     if you have a variable in '...' that is named 'n, no, nob, nob',
     add 'nobs=FALSE' to the invocation to prevent that variable from
     being misrecognized as 'nobs'

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

     a data frame with all predictors, and an attribute 'names.subset'
     if 'nobs' is specified.  This attribute contains the vector of
     variable names for predictors which were passed to 'data.ed' and
     hence were allowed to vary.  If neither 'nobs' nor any predictor
     settings were given, returns a data frame with adjust-to values.

_S_i_d_e _E_f_f_e_c_t_s:

     optionally writes to the terminal, opens X-windows, and generates
     a temporary file using 'sink'.

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

     Frank Harrell
      Department of Biostatistics
      Vanderbilt University
      f.harrell@vanderbilt.edu

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

     'predict.Design', 'survest.cph', 'survest.psm', 'Design.Misc',
     'expand.grid', 'data.entry', 'page', 'print.datadist',
     'edit.data.frame', 'plot.Design'

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

     set.seed(1)
     age <- rnorm(200, 50, 10)
     sex <- factor(sample(c('female','male'),200,TRUE))
     race <- factor(sample(c('a','b','c','d'),200,TRUE))
     y <- sample(0:1, 200, TRUE)
     dd <- datadist(age,sex,race)
     options(datadist="dd")
     f <- lrm(y ~ age*sex + race)
     gendata(f)
     gendata(f, age=50)
     d <- gendata(f, age=50, sex="female")  # leave race=reference category
     d <- gendata(f, age=c(50,60), race=c("b","a"))  # 4 obs.
     d$Predicted <- predict(f, d, type="fitted")
     d      # Predicted column prints at the far right
     options(datadist=NULL)
     ## Not run: 
     d <- gendata(f, nobs=5, view=TRUE)        # 5 interactively defined obs.
     d[,attr(d,"names.subset")]             # print variables which varied
     predict(f, d)
     ## End(Not run)

