NaN response with gam (mgcv library)
Dear Simon, Thanks ! It works ! Best, Le lundi 1 mai 2023 ? 11:19:26 UTC+2, Simon Wood <simon.wood at bath.edu> a ?crit : try... sum(residuals(model1)^2)
On 30/04/2023 22:03, varin sacha via R-help wrote:
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) #########################################################
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Simon Wood, School of Mathematics, University of Edinburgh, https://www.maths.ed.ac.uk/~swood34/