dear professor: I have a problem about the nomogram.I have got the result through analysing the dataset "exp2.sav" through multinominal logistic regression by SPSS 17.0. and I want to deveop the nomogram through R-Projject,just like this :> 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 > y <- ifelse(runif(n) < plogis(L), 1, 0) > ddist <- datadist(as.numeric(T.Grade,Sex,Smoking))load package "rms"> ddist <- datadist(as.numeric(T.Grade,Sex,Smoking)) > options(datadist='ddist') > f<-lrm(y~as.numeric(T.Grade)+as.numeric(Sex)+as.numeric(Smoking))??? error to:model.frame.default(formula = y ~ as.numeric(T.Grade) + as.numeric(Sex) + : ???????? the length of the variable is different ('as.numeric(T.Grade)') I encounter aproblem in the last program,and I try to settle this problem though several ways ,just like: asis(x, parms, label, name) matrx(x, label, name) pol(x, parms, label, name) lsp(x, parms, label, name) rcs(x, parms, label, name) catg(x, parms, label, name) scored(x, parms, label, name) strat(x, label, name) x1 %ia% x2 and i can not settle this problem can you tell me how to settle this problem,thank you turly yours
David Winsemius
2010-Oct-04 03:31 UTC
[R] I have aproblem about nomogram--thank you for your help
On Oct 3, 2010, at 10:42 PM, ?? wrote:> dear professor: > I have a problem about the nomogram.I have got the result through > analysing the dataset "exp2.sav" through multinominal logistic > regression by SPSS 17.0.That is an inadequate specification of a statistical analysis (although it might pass for such in the typical medical journal).> and I want to deveop the nomogram through R-Projject,just like > this :I know of no way of taking a function developed in SPSS/SAS/Stata and simply dropping it into the nomogram function to generate sensible output. There may be such a method that you could piece together by examining the code, but it appears to me that you are not yet ready for that task. nomogram() was clearly developed to by used as a part of the rms package rather than as a stand-alone graphical utility.> >> 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) # Then follow the example on the help(nomogram page) 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) Please note: this is _not_ your nomogram function due to the random aspects of the creation of "y", and this is NOT multinomial logistic regression (since you only have a dichotomous outcome). For one possible variant of multinomial logistic regression supported in the rms/Hmisc function suite, you would need to use polr. -- David.>> > ??? error to:model.frame.default(formula = y ~ as.numeric(T.Grade) > + as.numeric(Sex) + : > ???????? the length of the variable is different > ('as.numeric(T.Grade)') > > I encounter aproblem in the last program,and I try to settle this > problem though several ways ,just like: > asis(x, parms, label, name) > matrx(x, label, name) > pol(x, parms, label, name) > lsp(x, parms, label, name) > rcs(x, parms, label, name) > catg(x, parms, label, name) > scored(x, parms, label, name) > strat(x, label, name) > x1 %ia% x2 > > and i can not settle this problem > can you tell me how to settle this problem,thank you > turly > yours________________________________--- David Winsemius, MD West Hartford, CT