dear professor: thank you for your help,witn your help i develop the nomogram successfully. after that i want to do the internal validation to the model.i ues the bootpred to do it,and then i encounter problem again,just like that.(´íÎóÓÚerror to :complete.cases(x, y, wt) : ²»ÊÇËùÓеIJÎÊý¶¼Ò»Ñù³¤(the length of the augment was different)) i hope you tell me where is the mistake,and maybe i have chosen the wrong function. thank you turly yours ...... load package 'rms'> ddist <- datadist(dfr) > options(datadist='ddist') > n<-100 > set.seed(10) > T.Grade<-factor(0:3,labels=c("G0", "G1", "G2","G3")) > Sex<-factor(sample(0:1, 100, replace=TRUE),labels=c("F","M")) > Smoking<-factor(sample(0:1, 100, replace=TRUE),labels=c("No","yes")) > dfr$L<-with(dfr,0.559*as.numeric(T.Grade)-0.896*as.numeric(Smoking)+0.92*as.numeric(Sex)-1.338) > dfr$y <- with(dfr, ifelse(runif(n) < plogis(L), 1, 0) ) > dfr <- data.frame(T.Grade,Sex,Smoking, L, y) > ddist <- datadist(dfr) > options(datadist='ddist') > f<-lrm(y~T.Grade +Sex+Smoking, data=dfr) > nom<-nomogram(f,fun=function(x)1/(1+exp(-x)),fun.at=c(.01,.05,seq(.1,.9,by=.2),.9,1),funlabel="Risk of Death") > plot(nom, xfrac=0.45)load package bootstrap .................the problem....................> theta.fit <- function(dfr,y){lsfit(dfr,y)} > theta.predict <- function(fit,dfr){cbind(1,dfr)%*%fit$coef} > sq.err <- function(y,yhat) { (y-yhat)^2} > results <- bootpred(x,y,50,theta.fit,theta.predict,err.meas=sq.err)´íÎóÓÚerror to :complete.cases(x, y, wt) : ²»ÊÇËùÓеIJÎÊý¶¼Ò»Ñù³¤(the length of the augment was different) È«¹ú×îµÍ¼Û£¬ÌìÌìÔÚ¼Ò³åÕÕƬ£¬24Сʱ·¢»õÉÏÃÅ£¡ [[alternative HTML version deleted]]
On Oct 4, 2010, at 7:29 AM, ?? wrote:> dear professor:If this is directed to my posting, I am not a professor.> thank you for your help,witn your help i develop the nomogram > successfully. > after that i want to do the internal validation to the model.i ues > the bootpred to do it,and then i encounter problem again,just like > that.(??????error to :complete.cases(x, y, wt) : > ??????????????????????(the length of the > augment was different)) > i hope you tell me where is the mistake,and maybe i have chosen the > wrong function.I think so, at least to the limited extent that I I am understanding your efforts. It appears you are trying to use boot to do simulation, but the goal is rather unclear. I think you would get further along the way if you imported your data into R your data and constructed a model within the rms system. None of your functions in this posting are creating a new instance of dfr$y. They are all depending on the single constructed version of the data which may be peculiar or it may be exactly typical, but one cannot tell. Rather than boot() you might get further with replicate(), but I am not inclined to offer further code in support of what is an unclear and possibly futile direction.> thank you > turly yours > ...... > load package 'rms' > >> ddist <- datadist(dfr) >> options(datadist='ddist') >> n<-100 >> set.seed(10) >> T.Grade<-factor(0:3,labels=c("G0", "G1", "G2","G3")) >> Sex<-factor(sample(0:1, 100, replace=TRUE),labels=c("F","M")) >> Smoking<-factor(sample(0:1, 100, replace=TRUE),labels=c("No","yes")) >> dfr$L<-with(dfr,0.559*as.numeric(T.Grade)-0.896*as.numeric(Smoking) >> +0.92*as.numeric(Sex)-1.338) >> dfr$y <- with(dfr, ifelse(runif(n) < plogis(L), 1, 0) ) >> dfr <- data.frame(T.Grade,Sex,Smoking, L, y) >> ddist <- datadist(dfr) >> options(datadist='ddist') >> f<-lrm(y~T.Grade +Sex+Smoking, data=dfr) >> nom<-nomogram(f,fun=function(x)1/(1+exp(-x)),fun.at=c(.01,.05,seq(. >> 1,.9,by=.2),.9,1),funlabel="Risk of Death") >> plot(nom, xfrac=0.45) > > load package bootstrap > > .................the problem....................This is not a problem statement. It is merely evidence that you have some sort of unspecified problem.>> theta.fit <- function(dfr,y){lsfit(dfr,y)} >> theta.predict <- function(fit,dfr){cbind(1,dfr)%*%fit$coef}(There is already a predict() function for regular regression problems and a Predict() function for use with rms fit objects, which if you explained clearly what you were attempting might be urseful.)>> sq.err <- function(y,yhat) { (y-yhat)^2}It's probably possible to get the sum-squared error for a linear fit from function lm() by more direct means. I do not understand what the next line is supposed to be doing, so am unable to offer further suggestion. Refitting the same model 50 times to the same data seems an uninformative exercise.>> results <- bootpred(x,y,50,theta.fit,theta.predict,err.meas=sq.err) > ??????error to :complete.cases(x, y, wt) : > ??????????????????????(the length of the > augment was different) > > > > ????????????????????????????24????? > ????????? > [[alternative HTML version deleted]]-- David Winsemius, MD West Hartford, CT
dear teacher: thank you for your help,witn your help i develop the nomogram successfully. after that i want to do the internal validation to the nomogram.i wish to use the bootstrap to achieve the prediction accuracy of the nomogram,and then i encounter problem again,just like that.(error to :complete.cases(x, y, wt) : (the length of the augment was different)) i hope you tell me where is the mistake,and maybe i have chosen the wrong function. thank you turly yours ...... load package 'rms'>> n<-100 >> set.seed(10) >> T.Grade<-factor(0:3,labels=c("G0", "G1", "G2","G3")) >> Sex<-factor(0:1,labels=c("F","M")) >> Smoking<-factor(0:1,labels=c("No","yes")) >> L<-0.559*as.numeric(T.Grade)-0.896*as.numeric(Smoking) >> +0.92*as.numeric(Sex)-1.338 > L[1] -0.755 -0.172 0.363 0.946>> y <- ifelse(runif(n) < plogis(L), 1, 0) >>dfr <- data.frame(T.Grade,Sex,Smoking, L, y)ddist <- datadist(dfr) # wrap the vectors into a dataframe. options(datadist='ddist') f<-lrm(y~T.Grade +Sex+Smoking, data=dfr) # skip the as.numeric()'s ### Gives an error message due to singular X matrix.> f<-lrm(y~T.Grade +Sex+Smoking, data=dfr)singular information matrix in lrm.fit (rank= 5 ). Offending variable(s): Sex=M Error in lrm(y ~ T.Grade + Sex + Smoking, data = dfr) : Unable to fit model using ?lrm.fit? ##### Try instead: n<-100 set.seed(10) T.Grade<-factor(0:3,labels=c("G0", "G1", "G2","G3")) Sex<-factor(sample(0:1, 100, replace=TRUE),labels=c("F","M")) Smoking<-factor(sample(0:1, 100, replace=TRUE),labels=c("No","yes")) dfr$L <- with(dfr, 0.559*as.numeric(T.Grade)-0.896*as.numeric(Smoking) +0.92*as.numeric(Sex)-1.338) dfr$y <- with(dfr, ifelse(runif(n) < plogis(L), 1, 0) ) dfr <- data.frame(T.Grade,Sex,Smoking, L, y) ddist <- datadist(dfr) options(datadist='ddist') f<-lrm(y~T.Grade +Sex+Smoking, data=dfr) nom <- nomogram(f, fun=function(x)1/(1+exp(-x)), # or fun=plogis fun.at=c(.001,.01,.05,seq(.1,.9,by=.1),.95,.99,.999), funlabel="Risk of Death") plot(nom, xfrac=.45) load package bootstrap(achieve the prediction accuracy of the nomogram) .................the problem....................> theta.fit <- function(dfr,y){lsfit(dfr,y)} > theta.predict <- function(fit,dfr){cbind(1,dfr)%*%fit$coef} > sq.err <- function(y,yhat) { (y-yhat)^2} > results <- bootpred(x,y,50,theta.fit,theta.predict,err.meas=sq.err)error to :complete.cases(x, y, wt) : (the length of the augment was different.