[R] passing an extra argument to an S3 generic

Michael Friendly friendly at yorku.ca
Fri Feb 10 22:35:56 CET 2012


On 2/10/2012 4:09 PM, Henrik Bengtsson wrote:
> So people may prefer to do the following:
>
> hatvalues.mlm<- function(model, m=1, infl, ...)
> {
>     if (missing(infl)) {
>       infl<- mlm.influence(model, m=m, do.coef=FALSE);
>     }
>
>     hat<- infl$H
>     m<- infl$m
>     names(hat)<- if(m==1) infl$subsets else apply(infl$subsets,1,
> paste, collapse=',')
>     hat
> }
Thanks;  I tried exactly that, but I still can't pass m=2 to the mlm 
method through the generic

 > hatvalues(Rohwer.mod)
          1          2          3          4          5          
6          7          8
0.16700926 0.21845327 0.14173469 0.07314341 0.56821462 0.15432157 
0.04530969 0.17661104
          9         10         11         12         13         
14         15         16
0.05131298 0.45161152 0.14542776 0.17050399 0.10374592 0.12649927 
0.33246744 0.33183461
         17         18         19         20         21         
22         23         24
0.17320579 0.26353864 0.29835817 0.07880597 0.14023750 0.19380286 
0.04455330 0.20641708
         25         26         27         28         29         
30         31         32
0.15712604 0.15333879 0.36726467 0.11189754 0.30426999 0.08655434 
0.08921878 0.07320950
 > hatvalues(Rohwer.mod, m=2)
Error in UseMethod("hatvalues") :
   no applicable method for 'hatvalues' applied to an object of class 
"c('double', 'numeric')"

## This works:
 > hatvalues.mlm(Rohwer.mod, m=2)
    ... output snipped

 > hatvalues
function (model, ...)
UseMethod("hatvalues")
<bytecode: 0x021339e4>
<environment: namespace:stats>
 >

-Michael


-- 
Michael Friendly     Email: friendly AT yorku DOT ca
Professor, Psychology Dept.
York University      Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Street    Web:   http://www.datavis.ca
Toronto, ONT  M3J 1P3 CANADA



More information about the R-help mailing list