On Wed, 17 Sep 2003 12:20:29 -0600
Russell.Ivory@MerrickBank.com wrote:
> I have a model
>
> testmodel <- lrm(depvar ~ age+fscore+accts+lates+stage)
>
> As part of my diagnostics I want to manipulate things one continuous measure
> at a time. I want to write a function to run a new model that will in short
> look for linearity. I have the steps of my function down but I'm having
> trouble manipulating the model arguments in the function call.
>
> I'd like to have the aruments be very simple as
>
> function(testmodel,indvar)
>
> where testmodel is the existing model object and indvar is the variable in
> question that I will pull out and manipulate. For example, if I were
> looking at age in the model above, the function call would look like
>
> function(testmodel,age)
>
> and the model would then become lrm(depvar ~ age +fscore+accts+lates+stage -
> age + agemanipulated)
>
> In other words, I would pull age out of the existing model and plug in a
> manipulated version of age then re-run the model.
>
> I've tried to simply pull age out as a first step with things like
>
> modelvars <- depvar ~ age+fscore+accts+lates+stage
> > modelvars
> depvar ~ age+fscore+accts+lates+stage
> as.formula(paste("lrm(",modelvars,"-age)"))
>
> or
>
> paste("lrm(", substring(testmodel$call, 1, max(nchar(testmodel$call)))[2],
> "-age)")
> [1] "lrm( depvar ~ age+fscore+accts+lates+stage -age)"
>
> but to no avail.
>
> I'm sure the solution is simple, but I cannot find it. Any pointers would
> be greatly appreciated.
>
> Russell Ivory
> Senior Risk Scoring Analyst
> Merrick Bank
> 10705 South Jordan Gateway
> Suite 200
> South Jordan, Ut 84095
> (801) 545-6640
>
Try to let lrm and anova.Design do the work for you. If the nonlinearity you
are entertaining can be captured by ordinary (pol( )) or segmented (rcs( ))
polynomials or by linear splines (lsp( )), represent age by a matrix in the
model (e.g., y ~ x + rcs(age,5) to get a 5 knot restricted cubic spline with
default knot locations) and then just run anova on the fit object to get a Wald
test of nonlinearity.
Beware: the P-value for such tests cannot be used for anything other than "See
boss, complexity is needed, linearity won't do. I should get a raise now." If
you remove insignificant terms from the model much of statistical inference
goes out the window, and even predictive accuracy is hurt.
---
Frank E Harrell Jr Professor and Chair School of Medicine
Department of Biostatistics Vanderbilt University
|