.BG
.FN avg.surv
.TL
This function calculates adjusted survival curves
following
the "corrected group prognosis" (average of individual survival
curve) method.
Based on a fitted Cox proportional hazards model,
for each specified value of a given variable,
the function returns the mean of the family of fitted
survival curves relative to the 
specified variable value and a set of "reference" values for the
remaining covariates.
.DN
Model-based adjusted survival curves.
.CS
avg.surv(cfit, var.name, var.values, data, weights)
.RA
.AG cfit
An object of class "coxph", typically produced by the application of the
coxph function.
.AG var.name
A variable from the model represented in cfit.
.AG var.values
Values of the variable defining strata for which mean survival curves
are to be calculated.
.AG data
A dataframe with variables corresponding to those represented in cfit.
The values for the covariates (i.e. model variables setting aside 
the response and the variable specified in var.name) 
define the reference population.  If data is not
specified, the function looks first to see if cfit has a model component
(from selecting model=T in the original application of coxph) to use as
the data, and failing that, tries to construct a dataframe using
model.frame and the parent frame.
.AG weights
An optional vector of weights of length equal to the number of rows of
data, used to weight the mean survival curve over the set of reference
covariate values.
.OA
.RT
An object of class "survfit", suitable for plotting (see example).
.DT
The function organizes a sequence of calls to survfit.coxph which does
the real work.  The function returns curves which are the averages of
covariate specific survival curves, NOT a fitted survival curve at
the mean of the covariate values.
.SH REFERENCES
Nieto, F.J., Coresh, J. (1996), Adjusting survival curves for
confounders: a review and a new method, \fIAmerican Journal of
Epidemiology\fP, \fB143:10\fP, 1059-1068.
.SA
survfit.coxph
.EX

# Variables for fit should be defined prior to application of coxph
# so that model formula contains only already defined variables, i.e. no
# "transformations" of variables, such as Surv or log.
stime <- Surv(fu.time, status) 
cfit <- coxph(stime ~ sex + age + diabmell +  hyperten + creat + chf)
# select diabetes variable, a factor with levels "Y" and "N".
afits <- avg.surv(cfit, "diabmell", c("Y","N"))
# plot unadjusted Kaplan-Meier curves
plot(survfit(stime ~ diabmell))
# add adjusted curves for comparison
matlines(afits$time,afits$fits)

.KW survival data
.WR