gavinsimpson / pcurve

Glenn De'Ath's principal curve package
GNU General Public License v2.0
1 stars 2 forks source link

prcurve options using the gam() function fail #1

Open gavinsimpson opened 9 years ago

gavinsimpson commented 9 years ago

Running prcurve() with fit.meth = "poisson" or fit.meth = "binomial" results in an error due it not finding lambda:

> data(sim4var)
> sim4fit <-  pcurve(sim4var, plot.init = FALSE, use.loc = FALSE, fit.meth = "poisson")

Estimating starting configuration using : CA
GCV DFs : Penalty =  1
PC B-spline fit DF =  6.86 
Error in eval(expr, envir, enclos) : object 'lambda' not found

This is likely a scoping issue.

jarioksa commented 9 years ago

Yes, it is a scoping issue. The error comes from this call:

> traceback()
...
3: gam(x[, j] ~ s(pcurve$lambda, m = dfj), family = poisson())
...

The gam function does not see pcurve data with lambda at all, but sees the pcurve function. Following is a dirty fix that passes the lambda in data to gam:

gam(x[,j] ~ s(lambda, m=dfj), data=data.frame(lambda=pcurve$lambda))
gavinsimpson commented 9 years ago

Thanks @jarioksa. This is mainly a reminder for me to fix this once I've gutted pcurve to be more vegan-like than monolithic-like. Current behaviour (but fixed) will be preserved in function oldpcurve().