Dear all, I tried to use "step" function to do model selection, but I got an error massage. What I don't understand is that data as data.frame worked well for my other programs, how come I cannot make it run this time. Could you please tell me how I can fix it? ***************************************************************************************************>all<-data.frame(z1,z2,z3)>fit.model.all<- coxph(Surv(t,cen) ~z1+z2+z3,data=all)> reg.model.all<-step(fit.model.all)Start: AIC= 689.1 Surv(t, cen) ~ z1 + z2 + z3 Error in as.data.frame.default(data) : cannot coerce class "function" into a data.frame *************************************************************************************************** Thanks a lot! Jia
Hi, Step works for a Cox model. And I got the same error massage using stepAIC. Jia _____ From: Ritwik Sinha [mailto:ritwik.sinha@gmail.com] Sent: Thursday, June 15, 2006 12:12 AM To: Li, Jia Subject: Re: [R] A question about stepwise procedures: step function Hi, The step documentation says "object: an object representing a model of an appropriate class (mainly '"lm"' and '"glm"'). This is used as the initial model in the stepwise search. " I wonder if it will work for a cox proportional hazard model. You could try stepAIC in MASS. On 6/14/06, Li, Jia < LI@nsabp.pitt.edu <mailto:LI@nsabp.pitt.edu> > wrote: Dear all, I tried to use "step" function to do model selection, but I got an error massage. What I don't understand is that data as data.frame worked well for my other programs, how come I cannot make it run this time. Could you please tell me how I can fix it? ************************************************************************ *************************** >all<-data.frame(z1,z2,z3) >fit.model.all<- coxph(Surv(t,cen) ~z1+z2+z3,data=all) > reg.model.all<-step(fit.model.all) Start: AIC= 689.1 Surv(t, cen) ~ z1 + z2 + z3 Error in as.data.frame.default(data) : cannot coerce class "function" into a data.frame ************************************************************************ *************************** Thanks a lot! Jia ______________________________________________ R-help@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 -- Ritwik Sinha Graduate Student Epidemiology and Biostatistics Case Western Reserve University http://darwin.cwru.edu/~rsinha [[alternative HTML version deleted]]
Sorry, I still cannot find what's wrong with it. And it seems that nothing is wrong with t. Jia> z1<-rnorm(N,0,1) > z2<-rnorm(N,3,5) > z3<-rbinom(N,1,0.6) > > prop.cens<-0.45 > cen<-rbinom(N,1,1-prop.cens) #<-- censor indicator:45% censor inthe data.> t<- rexp(N)> all<-data.frame(z1,z2,z3) > fit.model.all<- coxph(Surv(t,cen) ~z1+z2+z3,data=all) > fit.model.allCall: coxph(formula = Surv(t, cen) ~ z1 + z2 + z3, data = all) coef exp(coef) se(coef) z p z1 0.057466 1.059 0.1377 0.4173 0.68 z2 0.000907 1.001 0.0332 0.0273 0.98 z3 -0.349273 0.705 0.2867 -1.2184 0.22 Likelihood ratio test=1.81 on 3 df, p=0.613 n= 100> reg.model.all<-step(fit.model.all)Start: AIC= 376.39 Surv(t, cen) ~ z1 + z2 + z3 Error in as.data.frame.default(data) : cannot coerce class "function" into a data.frame _____ From: Hong Ooi [mailto:Hong.Ooi@iag.com.au] Sent: Thursday, June 15, 2006 10:53 AM To: Li, Jia Subject: RE: [R] A question about stepwise procedures: step function Note: This e-mail is subject to the disclaimer contained at the bottom of this message. _____ t is the name of a function. If you have a variable called t in your dataset, try renaming it. _____ From: r-help-bounces@stat.math.ethz.ch on behalf of Li, Jia Sent: Thu 15/06/2006 11:52 PM To: r-help@stat.math.ethz.ch; ritwik.sinha@gmail.com Subject: Re: [R] A question about stepwise procedures: step function Hi, Step works for a Cox model. And I got the same error massage using stepAIC. Jia _____ From: Ritwik Sinha [mailto:ritwik.sinha@gmail.com] Sent: Thursday, June 15, 2006 12:12 AM To: Li, Jia Subject: Re: [R] A question about stepwise procedures: step function Hi, The step documentation says "object: an object representing a model of an appropriate class (mainly '"lm"' and '"glm"'). This is used as the initial model in the stepwise search. " I wonder if it will work for a cox proportional hazard model. You could try stepAIC in MASS. On 6/14/06, Li, Jia < LI@nsabp.pitt.edu <mailto:LI@nsabp.pitt.edu> > wrote: Dear all, I tried to use "step" function to do model selection, but I got an error massage. What I don't understand is that data as data.frame worked well for my other programs, how come I cannot make it run this time. Could you please tell me how I can fix it? ************************************************************************ *************************** >all<-data.frame(z1,z2,z3) >fit.model.all<- coxph(Surv(t,cen) ~z1+z2+z3,data=all) > reg.model.all<-step(fit.model.all) Start: AIC= 689.1 Surv(t, cen) ~ z1 + z2 + z3 Error in as.data.frame.default(data) : cannot coerce class "function" into a data.frame ************************************************************************ *************************** Thanks a lot! Jia ______________________________________________ R-help@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 -- Ritwik Sinha Graduate Student Epidemiology and Biostatistics Case Western Reserve University http://darwin.cwru.edu/~rsinha [[alternative HTML version deleted]] ______________________________________________ R-help@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 _____ The information transmitted in this message and its attachme...{{dropped}}
Frede Aakmann Tøgersen
2006-Jun-16 06:34 UTC
[R] A question about stepwise procedures: step function
Well Jia, you use 'all' as a name for your dataframe, but this is also a function, see ?all. If I try it with mydata <- data.frame(z1,z2,z3) all goes well. Med venlig hilsen Frede Aakmann T?gersen> -----Oprindelig meddelelse----- > Fra: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] P? vegne af Li, Jia > Sendt: 15. juni 2006 17:45 > Til: Hong Ooi; r-help at stat.math.ethz.ch > Emne: Re: [R] A question about stepwise procedures: step function > > Sorry, I still cannot find what's wrong with it. And it seems > that nothing is wrong with t. > > Jia > > > z1<-rnorm(N,0,1) > > z2<-rnorm(N,3,5) > > z3<-rbinom(N,1,0.6) > > > > prop.cens<-0.45 > > cen<-rbinom(N,1,1-prop.cens) #<-- censor indicator:45% censor in > the data. > > t<- rexp(N) > > > all<-data.frame(z1,z2,z3) > > fit.model.all<- coxph(Surv(t,cen) ~z1+z2+z3,data=all) fit.model.all > Call: > coxph(formula = Surv(t, cen) ~ z1 + z2 + z3, data = all) > > > coef exp(coef) se(coef) z p > z1 0.057466 1.059 0.1377 0.4173 0.68 > z2 0.000907 1.001 0.0332 0.0273 0.98 > z3 -0.349273 0.705 0.2867 -1.2184 0.22 > > Likelihood ratio test=1.81 on 3 df, p=0.613 n= 100 > > reg.model.all<-step(fit.model.all) > Start: AIC= 376.39 > Surv(t, cen) ~ z1 + z2 + z3 > > Error in as.data.frame.default(data) : cannot coerce class "function" > into a data.frame > > > _____ > > From: Hong Ooi [mailto:Hong.Ooi at iag.com.au] > Sent: Thursday, June 15, 2006 10:53 AM > To: Li, Jia > Subject: RE: [R] A question about stepwise procedures: step function > > > > Note: This e-mail is subject to the disclaimer contained at the bottom > of this message. > > _____ > > t is the name of a function. If you have a variable called t in your > dataset, try renaming it. > > > _____ > > From: r-help-bounces at stat.math.ethz.ch on behalf of Li, Jia > Sent: Thu 15/06/2006 11:52 PM > To: r-help at stat.math.ethz.ch; ritwik.sinha at gmail.com > Subject: Re: [R] A question about stepwise procedures: step function > > > > Hi, > > Step works for a Cox model. And I got the same error massage using > stepAIC. > > Jia > > _____ > > From: Ritwik Sinha [mailto:ritwik.sinha at gmail.com] > Sent: Thursday, June 15, 2006 12:12 AM > To: Li, Jia > Subject: Re: [R] A question about stepwise procedures: step function > > > Hi, > > The step documentation says > > "object: an object representing a model of an appropriate class > (mainly '"lm"' and '"glm"'). This is used as the initial > model in the stepwise search. > " > I wonder if it will work for a cox proportional hazard model. > You could > try stepAIC in MASS. > > > > > On 6/14/06, Li, Jia < LI at nsabp.pitt.edu <mailto:LI at nsabp.pitt.edu> > > wrote: > > Dear all, > > I tried to use "step" function to do model > selection, but I got > an error massage. What I don't understand is that data as data.frame > worked well for my other programs, how come I cannot make it run this > time. Could you please tell me how I can fix it? > > > ************************************************************** > ********** > *************************** > > >all<-data.frame(z1,z2,z3) > > >fit.model.all<- coxph(Surv(t,cen) ~z1+z2+z3,data=all) > > > reg.model.all<-step(fit.model.all) > Start: AIC= 689.1 > Surv(t, cen) ~ z1 + z2 + z3 > Error in as.data.frame.default(data) : cannot coerce class > "function" into a data.frame > > ************************************************************** > ********** > *************************** > Thanks a lot! > > Jia > > ______________________________________________ > 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 > > > > > > -- > Ritwik Sinha > Graduate Student > Epidemiology and Biostatistics > Case Western Reserve University > > http://darwin.cwru.edu/~rsinha > > [[alternative HTML version deleted]] > > ______________________________________________ > 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 > > > _____ > > The information transmitted in this message and its > attachme...{{dropped}} > > ______________________________________________ > 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 >