[R] smartpred depends on fitted() in flexmix?

Bettina Gruen gruen at ci.tuwien.ac.at
Thu Feb 8 16:01:30 CET 2007


Hi,

which packages do you have attached? Look for example at the output of 
sessionInfo().

For your code you need the function "fitted" and its S3 methods from 
package "stats". So there is no reason why "flexmix" should be 
necessary. However, in "flexmix" S4 methods for "fitted" are provided 
and the S3 methods from "stats" are imported using the following in the 
NAMESPACE:

importFrom(stats, fitted)

I can only guess that the problem might occur because you have for 
example "VGAM" attached. I can run your code if "VGAM" is not attached. 
The code does not work after loading "VGAM" and works again after also 
loading "flexmix":

 > n = 20
 > set.seed(86)
 > x = sort(runif(n))
 > y = sort(runif(n))
 > library(splines)
 > fit = lm(y ~ ns(x, df=5))
 > plot(x, y)
 > lines(x, fitted(fit))
 > library(VGAM)
 > lines(x, fitted(fit))
Error in function (classes, fdef, mtable)  :
         unable to find an inherited method for function "fitted", for 
signature "lm"
 > library(flexmix)
 > lines(x, fitted(fit))

I think this should be possible to solve by also adding 
importFrom(stats, fitted) to the NAMESPACE of "VGAM".

Best,
Bettina

Michael Kubovy wrote:
> Hi,
> 
> I was going through the examples in smartpred. It seems there's an  
> unstated dependency on the fitted() function in package flexmix.
> 
> n = 20
> set.seed(86)
> x = sort(runif(n))
> y = sort(runif(n))
> library(splines)
> fit = lm(y ~ ns(x, df=5))
> plot(x, y)
> lines(x, fitted(fit)) # won't work w/o prior loading of the flexmix  
> package.
> newx = seq(0, 1, len=n)
> points(newx, predict(fit, data.frame(x=newx)), type="b", col=2, err=-1)
> _____________________________
> Professor Michael Kubovy
> University of Virginia
> Department of Psychology
> USPS:     P.O.Box 400400    Charlottesville, VA 22904-4400
> Parcels:    Room 102        Gilmer Hall
>          McCormick Road    Charlottesville, VA 22903
> Office:    B011    +1-434-982-4729
> Lab:        B019    +1-434-982-4751
> Fax:        +1-434-982-4766
> WWW:    http://www.people.virginia.edu/~mk9y/
> 
> ______________________________________________
> 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
> and provide commented, minimal, self-contained, reproducible code.
> 
>



More information about the R-help mailing list