paulponcet / strip

Lighten your R model outputs
Other
3 stars 1 forks source link

natural splines #2

Open ekhco opened 6 years ago

ekhco commented 6 years ago

A problem I encounter when the .Environment is removed from terms is that natural splines no longer work when predicting:

library(strip)
library(splines)
x <- 1:1000/100
e <- rnorm(1:1000,mean=0, sd=0.3)
y <- sqrt(x) + e
plot(x,y)

# natural spline fit
nsfit <- lm(y ~ ns(x,df=3))
fit0 <- strip(nsfit, keep="predict")
predict(fit0, newdata=data.frame(x=1:10))
spgarbet commented 1 year ago

Just had this same issue. The fact the ticket was opened in 2017 doesn't give me much hope.

spgarbet commented 1 year ago

I've also tried things with rms and biglm to work around this and used rcs, all have similar issues.

spgarbet commented 1 year ago

I am committed to solving this problem for a grant, Using the original code, I find the issue is the handling of the "terms" sub-object.

> object.size(nsfit)
308056 bytes
> object.size(fit0)
9136 bytes
> fit0$terms <- nsfit$terms
> object.size(fit0)
9304 bytes
> predict(fit0, newdata=data.frame(x=1))
1 
0.9332283