[R] strangeness in Predict() {rms}

Frank E Harrell Jr f.harrell at Vanderbilt.Edu
Thu Feb 18 05:22:00 CET 2010


Frank E Harrell Jr wrote:
> William Dunlap wrote:
>> Both plyr and rms contain an object called ".".
>> In plyr it is a "closure" (the common kind of
>> function) and in rms is is NA.  If plyr is attached
>> in front of rms then you get your problem with
>> Predict().
>> Bill Dunlap
>> Spotfire, TIBCO Software
>> wdunlap tibco.com  
> 
> I think I should modify rms to not let this happen.  Whenever an rms 
> function uses ... as an argument to pass this type of information I can 
> change list(...) to eval(substitute(list(...)), list(.=NA))
> 
> If anyone sees a better approach or a problem with this approach please 
> let me know.
> 
> Frank

On second thought I think I will change rms to not require .  I will use 
this construct for Predict, summary, nomogram:

Predict(fit, age, sex='male') -> default range for age, males
Predict(fit, age=c(10,20,30), sex) -> 3 ages x 2 sexes

I found a way to process the ... arguments without evaluating them, so 
that the name of a predictor without a value can trigger the use of the 
default values for that variable.  I hope to have a new version out 
within 2 weeks.  The current . (if plyr is not in effect) or NA methods 
will still work but will not be recommended.

Note that the workaround to the plyr conflict for now is to use NA in 
place of .

Frank
> 
>>
>>> -----Original Message-----
>>> From: r-help-bounces at r-project.org 
>>> [mailto:r-help-bounces at r-project.org] On Behalf Of 
>>> Bill.Venables at csiro.au
>>> Sent: Tuesday, February 16, 2010 4:21 PM
>>> To: dylan.beaudette at gmail.com; r-help at r-project.org
>>> Subject: Re: [R] strangeness in Predict() {rms}
>>>
>>> This works without a glitch on my linux system (info below).  You 
>>> might try upgrading your R to 2.10.1, perhaps.
>>>
>>>> sessionInfo()
>>> R version 2.10.1 (2009-12-14) x86_64-unknown-linux-gnu
>>> locale:
>>>  [1] LC_CTYPE=en_AU.UTF-8       LC_NUMERIC=C               [3] 
>>> LC_TIME=en_AU.UTF-8        LC_COLLATE=en_AU.UTF-8     [5] 
>>> LC_MONETARY=C              LC_MESSAGES=en_AU.UTF-8    [7] 
>>> LC_PAPER=en_AU.UTF-8       LC_NAME=C                  [9] 
>>> LC_ADDRESS=C               LC_TELEPHONE=C            [11] 
>>> LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C      
>>> attached base packages:
>>> [1] splines   grid      stats     graphics  grDevices utils     
>>> datasets [8] methods   base    
>>> other attached packages:
>>> [1] rms_2.1-0       plyr_0.1.9      Design_2.3-0    Hmisc_3.7-0    
>>> [5] survival_2.35-9
>>>
>>> loaded via a namespace (and not attached):
>>> [1] ASOR_0.1       cluster_1.12.1 lattice_0.18-3 tcltk_2.10.1   
>>> tools_2.10.1 
>>>>  
>>>
>>> Bill Venables
>>> CSIRO/CMIS Cleveland Laboratories
>>>
>>>
>>> -----Original Message-----
>>> From: r-help-bounces at r-project.org 
>>> [mailto:r-help-bounces at r-project.org] On Behalf Of Dylan Beaudette
>>> Sent: Wednesday, 17 February 2010 10:05 AM
>>> To: r-help at r-project.org
>>> Subject: [R] strangeness in Predict() {rms}
>>>
>>> Hi,
>>>
>>> Running the following example from ?Predict() throws an error I have 
>>> never seen before:
>>>
>>> set.seed(1)
>>> x1 <- runif(300)
>>> x2 <- runif(300)
>>> ddist <- datadist(x1,x2); options(datadist='ddist')
>>> y  <- exp(x1+ x2 - 1 + rnorm(300))
>>> f  <- ols(log(y) ~ pol(x1,2) + x2)
>>> p1 <- Predict(f, x1=., conf.type='mean')
>>>
>>> Error in paste(nmc[i], "=", if (is.numeric(x)) format(x) else x, sep 
>>> = "") :   cannot coerce type 'closure' to vector of type 'character'
>>> In addition: Warning message:
>>> In is.na(v) : is.na() applied to non-(list or vector) of type 'closure'
>>>
>>> Here is the output from sessionInfo()
>>>
>>> R version 2.9.0 (2009-04-17) i686-pc-linux-gnu
>>> locale:
>>> LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLA
>>> TE=en_US.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=
>>> en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREME
>>> NT=en_US.UTF-8;LC_IDENTIFICATION=C
>>>
>>> attached base packages:
>>> [1] grid      splines   stats     graphics  grDevices utils     
>>> datasets [8] methods   base    
>>> other attached packages:
>>> [1] plyr_0.1.9         mgcv_1.5-5         RColorBrewer_1.0-2 
>>> nlme_3.1-94       [5] rms_2.1-0          Hmisc_3.7-0        
>>> survival_2.35-6    lattice_0.17-25  
>>> loaded via a namespace (and not attached):
>>> [1] cluster_1.12.0
>>>
>>>
>>> Any ideas?
>>> Thanks!
>>>
>>> Dylan
>>>
>>>
>>> -- 
>>> Dylan Beaudette
>>> Soil Resource Laboratory
>>> http://casoilresource.lawr.ucdavis.edu/
>>> University of California at Davis
>>> 530.754.7341
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide 
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.

> 


-- 
Frank E Harrell Jr   Professor and Chairman        School of Medicine
                      Department of Biostatistics   Vanderbilt University



More information about the R-help mailing list