Function               package:Design               R Documentation

_C_o_m_p_o_s_e _a_n _S _F_u_n_c_t_i_o_n _t_o _C_o_m_p_u_t_e _X _b_e_t_a _f_r_o_m _a _F_i_t

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

     'Function' is a class of functions for creating other S functions.
     'Function.Design' is the method for creating S functions to
     compute X beta, based on a model fitted with 'Design' in effect.  
     Like 'latex.Design', 'Function.Design' simplifies restricted cubic
     spline functions and factors out terms in second-order
     interactions. 'Function.Design' will not work for models that have
     third-order interactions involving restricted cubic splines.
     'Function.cph' is a particular method for handling fits from
     'cph', for which an intercept (the negative of the centering
     constant) is added to  the model.  'sascode' is a function that
     takes an S function such as one created by 'Function' and does
     most of the editing to turn the function definition into a
     fragment of SAS code for computing X beta from the fitted model,
     along with assignment statements that initialize predictors to
     reference values.

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

     ## S3 method for class 'Design':
     Function(object, intercept=NULL, digits=max(8,
     .Options$digits), ...)
     ## S3 method for class 'cph':
     Function(object, intercept=-object$center, ...)

     # Use result as fun(predictor1=value1, predictor2=value2, ...)

     sascode(object, file='', append=FALSE)

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

  object: a fit created with 'Design' in effect 

intercept: an intercept value to use (not allowed to be specified to
          'Function.cph'). The intercept is usually retrieved from the
          regression coefficients automatically. 

  digits: number of significant digits to use for coefficients and knot
          locations 

    file: name of a file in which to write the SAS code.  Default is to
          write to standard output. 

  append: set to 'TRUE' to have 'sascode' append code to an existing
          file named 'file'. 

     ...: arguments to pass to 'Function.Design' from 'Function.cph'

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

     'Function' returns an S-Plus function that can be invoked in any
     usual context.  The function has one argument per predictor
     variable, and the default values of the predictors are set to
     'adjust-to' values (see 'datadist').  Multiple predicted X beta
     values may be calculated by specifying vectors as arguments to the
     created function. All non-scalar argument values must have the
     same length.

_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:

     'latex.Design', 'Function.transcan', 'predict.Design', 'Design',
     'Design.trans'

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

     set.seed(1331)
     x1 <- exp(rnorm(100))
     x2 <- factor(sample(c('a','b'),100,rep=TRUE))
     dd <- datadist(x1, x2)
     options(datadist='dd')
     y  <- log(x1)^2+log(x1)*(x2=='b')+rnorm(100)/4
     f  <- ols(y ~ pol(log(x1),2)*x2)
     f$coef
     g  <- Function(f, digits=5)
     g
     sascode(g)
     g()
     g(x1=c(2,3), x2='b')   #could omit x2 since b is default category
     predict(f, expand.grid(x1=c(2,3),x2='b'))
     g8 <- Function(f)   # default is 8 sig. digits
     g8(x1=c(2,3), x2='b')
     options(datadist=NULL)

     ## Not run: 
     # Make self-contained functions for computing survival probabilities
     # using a log-normal regression
     f <- psm(Surv(d.time, death) ~ rcs(age,4)*sex, dist='gaussian')
     g <- Function(f)
     surv <- Survival(f)
     # Compute 2 and 5-year survival estimates for 50 year old male
     surv(c(2,5), g(age=50, sex='male'))
     ## End(Not run)

