Re: [R] A question about stepwise procedures: step function

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Mon 19 Jun 2006 - 01:33:01 EST

On Fri, 16 Jun 2006, Frede Aakmann Tøgersen wrote:

> 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.

Exactly: 'step' is in the stats namespace and so object 'all' in the base namespace is preferred to the object you have in the user workspace.

You are advised not to use the names of base R objects for other purposes. Use conflicts() to find out if you have done so.

(Here R could have figured out that a function was not appropriate, and it is smarter about that in pre-2.4.0.)

>
>
> Med venlig hilsen
> Frede Aakmann Tøgersen
>
>
>
>
>> -----Oprindelig meddelelse-----
>> Fra: r-help-bounces@stat.math.ethz.ch
>> [mailto:r-help-bounces@stat.math.ethz.ch] På vegne af Li, Jia
>> Sendt: 15. juni 2006 17:45
>> Til: Hong Ooi; r-help@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@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}}
>>
>> ______________________________________________
>> 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
>>
>
> ______________________________________________
> 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
>

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


______________________________________________ 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

Received on Mon Jun 19 01:45:15 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Mon 19 Jun 2006 - 02:11:16 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.