[R] Error: bad index in plotmo functions for MARS model (package earth)
Stephen Milborrow
milbo at sonic.net
Fri Jul 22 17:38:38 CEST 2011
On 2011-07-28 12:14:32, Cleber N.Borges wrote:
> I am tring make a simple surface plot ( 2 by 2 terms of a MARS model
> (with earth package) but I get the follow error message:
>
> > library( earth )
> > data( gasoline, package='pls' )
> > nir <- gasoline$NIR
> > class( nir )
> [1] "AsIs"
> > oct <- gasoline$octane
> > mars <- earth( oct ~ nir, nk=300, nfold=10, degree=3, trace=0 )
> > plotmo( mars )
> Error: bad index (missing column in x?)
The plotmo function is understandably confused by the fact that the class of
gasoline$NIR is "AsIs". Here is a work around:
g <- data.frame(octane=gasoline$octane, as.matrix(data.frame(gasoline$NIR)))
colnames(g) <- sub("gasoline.NIR.", "", colnames(g))
mars <- earth(octane ~ ., data=g, degree=2)
plotmo(mars, clip=F)
Earth is not suited to highly collinear data like this. Note that
summary(lm(octane ~ ., data=g)) gives
"ALL 60 residuals are 0: no residual degrees of freedom"
I will issue a new version of plotmo with better error handling for this
problem. I have cc'ed this email to the maintainer of the pls package to
let them know that the gasoline data has a strange class. Cleber, per the
posting guide you should have sent your email directly to me, the author of
the plotmo package, and not to r-help, so let's continue any further
discussion off the list. Feel free to contact me if you have further
questions.
Regards,
Steve Milborrow
www.milbo.users.sonic.net
More information about the R-help
mailing list