Roy Sanderson
2005-Jul-12 11:10 UTC
[R] Design: predict.lrm does not recognise lrm.fit object
Hello I'm using logistic regression from the Design library (lrm), then fastbw to undertake a backward selection and create a reduced model, before trying to make predictions against an independent set of data using predict.lrm with the reduced model. I wouldn't normally use this method, but I'm contrasting the results with an AIC/MMI approach. The script contains: # Determine full logistic regression lrm_logist = lrm(PresAbs ~ Size + X2ndpc + soil + AAR + tjan.jun, data=training) # Backward selection of variables in model lrm_stp = fastbw(lrm_logist, rule="p", sls=0.05) # Fit reduced model lrm_reduced = lrm.fit(training[,lrm_stp$parms.kept[-1]], training$PresAbs) # Predict using parameters from reduced model against a new dataset predict(lrm_reduced, testing, type="fitted.ind") It is the last command that fails, reporting the error: Error in getOldDesign(fit): fit was not created with a Design library fitting function. On further investigation, the class of the object from lrm.fit is only "lrm", whereas predict.lrm seems to be expecting objects with the class "lrm", "Design", "glm", judging from the examples on the predict.lrm help page. Many of the attributes differ also. Does anyone know a simple work-around for this problem? Many thanks Roy
Frank E Harrell Jr
2005-Jul-12 12:34 UTC
[R] Design: predict.lrm does not recognise lrm.fit object
Roy Sanderson wrote:> Hello > > I'm using logistic regression from the Design library (lrm), then fastbw to > undertake a backward selection and create a reduced model, before trying to > make predictions against an independent set of data using predict.lrm with > the reduced model. I wouldn't normally use this method, but I'm > contrasting the results with an AIC/MMI approach. The script contains: > > # Determine full logistic regression > lrm_logist = lrm(PresAbs ~ Size + X2ndpc + soil + AAR + tjan.jun, > data=training) > # Backward selection of variables in model > lrm_stp = fastbw(lrm_logist, rule="p", sls=0.05) > # Fit reduced model > lrm_reduced = lrm.fit(training[,lrm_stp$parms.kept[-1]], training$PresAbs) > # Predict using parameters from reduced model against a new dataset > predict(lrm_reduced, testing, type="fitted.ind")lrm.fit is used internally by lrm and related functions. You'll need to use lrm. Take lrm_stp$names.kept and create a formula - here is a first stab: form <- as.formula(paste('PresAbs ~', paste(lrm_stp$names.kept,collapse='+'))) lrm_reduced <- lrm(form, ...) This only works because you are forcing everything to be linear (highly unlikely) and are not allowing any interactions. Remember that is you use resampling to validate the model you need to start with the full list of candidate variables for each resample, having validate or calibrate functions repeat fastbw internally. Frank> > It is the last command that fails, reporting the error: > Error in getOldDesign(fit): fit was not created with a Design library > fitting function. > > On further investigation, the class of the object from lrm.fit is only > "lrm", whereas predict.lrm seems to be expecting objects with the class > "lrm", "Design", "glm", judging from the examples on the predict.lrm help > page. Many of the attributes differ also. Does anyone know a simple > work-around for this problem? > > Many thanks > Roy > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University