Skip to content
Prev 386858 / 398502 Next

Error in UseMethod("predict")

Eric,

No problem. Let's see if somebody else has a solution. I have changed the smooth basis from P-splines ('ps') to thin plate ('tp'). It still does not work, but this time I get another error message.


##########################
#Data
y=c(34000,45000,19000,48900,65000,67000,78000,90000,51000,32000,54000,85000,38000,76345,87654,90990,78654,67894,56789,65432,18998,78987,67543,45678,76543,67876)
x=c(345,543,543,456,432,378,543,579,432,254,346,564,611,543,542,632,345,468,476,487,453,356,490,499,567,532)

Dataset=data.frame(y,x)

#Plot
plot(x,y)

#Robust GAM
library(robustgam)
true.family <- poisson()
fit=robustgam(x,y, sp=2424,family=true.family,smooth.basis='tp')
x.new <- seq(range(x)[1], range(x)[2])
robustfit.new <- pred.robustgam(fit, data.frame(X=x.new))$predict.values
lines(x.new, robustfit.new, col="green", lwd=2)

# To find the ? sp ? to include in the fit function here above
robustfit.gic<-robustgam.GIC.optim(x,y,family=true.family,p=3,c=1.6,show.msg=FALSE,smooth.basis="ps", method="L-BFGS-B")

## CROSS VALIDATION REPLICATIONS MSE ROBUST GAM

# Create a list to store the results
lst<-list()

# This statement does the repetitions (looping)
for(i in 1 :1000)
{

n=dim(Dataset)[1]
p=0.667
sam=sample(1 :n,floor(p*n),replace=FALSE)
Training =Dataset [sam,]
Testing = Dataset [-sam,]

fit18<-robustgam(x,y, sp=2424,family=true.family,smooth.basis='tp')

ypred=pred.robustgam(fit18,data.frame(X=Testing))
MSE = mean((y-ypred)^2)
MSE
lst[i]<-MSE
}
mean(unlist(lst))
####################################





Le dimanche 17 janvier 2021 ? 15:02:45 UTC+1, Eric Berger <ericjberger at gmail.com> a ?crit : 





Hi Sacha,?
I took a quick look. Sorry, I don't see immediately what is causing the problem.
Maybe someone else can help.