[R] passing formula arguments cv.glm
Adaikalavan Ramasamy
ramasamy at cancer.org.uk
Mon Jul 25 13:25:50 CEST 2005
I am trying to write a wrapper for the last example in help(cv.glm) that
deals with leave-one-out-cross-validation (LOOCV) for a logistic model.
This wrapper will be used as part of a bigger program.
Here is my wrapper funtion :
logistic.LOOCV.err <- function( formu=NULL, data=NULL ){
cost.fn <- function(cl, pred) mean( abs(cl-pred) > 0.5 )
glmfit <- glm( formula=formu, data=data, family="binomial" )
print("glmfit is OK")
err <- cv.glm( data=data, glmfit=glmfit,
cost=cost.fn, K=nrow(data) )$delta[2]
print("cv.glm OK")
}
When I run the above function line by line with the arguments from
below, it works fine. But when I call it as function, I get this :
rm( glmfit, formu, cv.err ) # cleanup if required
logistic.LOOCV.err( formu=as.formula(r~stage+xray+acid), data=nodal )
logistic.LOOCV.err( formu=as.formula(r~stage+xray+acid), data=nodal )
[1] "glmfit is OK"
Error in model.frame(formula = formu, data = data[j.in, , drop =
FALSE], :
Object "formu" not found
I think this has something to do with formula and environments but I do
not know enough to solve it myself. I searched the archive without much
help (perhaps I was using the wrong keywords).
Any help would be very much appreciated. Thank you.
Regards,
--
Adaikalavan Ramasamy ramasamy at cancer.org.uk
Centre for Statistics in Medicine http://www.ihs.ox.ac.uk/csm/
Wolfson College Annexe Tel : 01865 284 408
Linton Road, Oxford OX2 6UD Fax : 01865 284 424
More information about the R-help
mailing list