[R] NaN response with gam (mgcv library)

varin sacha v@r|n@@ch@ @end|ng |rom y@hoo@|r
Sun Apr 30 23:03:02 CEST 2023


Dear R-experts,

Here below my R code. I get a NaN response for gam with mgcv library. How to solve that problem?
Many thanks.

#########################################################
library(mgcv)
 
y=c(23,24,34,40,42,43,54,34,52,54,23,32,35,45,46,54,34,36,37,48)
x1=c(0.1,0.3,0.5,0.7,0.8,0.9,0.1,0.7,0.67,0.98,0.56,0.54,0.34,0.12,0.47,0.52,0.87,0.56,0.71,0.6)
x2=c(9,7,5,3,2,1,1,2,8,9,6,3,1,5,6,7,3,1,3,5)
x3=c(11,10,13,15,10,9,14,16,18,19,20,9,13,12,14,17,21,19,23,12)
 
model=lm(y~x1+x2+x3)
model1=gam(y ~ s(x1, bs = 'cr', k = 3) + s(x2, bs = 'cr', k = 3)+ s(x3, bs = 'cr', k = 3))
 
 
#Calculate MSE
 model_summ=summary(model)
 mean(model_summ$residuals^2)
 
 
 #Calculate MSE
 model_summ=summary(model1)
 mean(model_summ$residuals^2)
#########################################################



More information about the R-help mailing list