[R] "NaN" answer don't understand why

varin sacha v@r|n@@ch@ @end|ng |rom y@hoo@|r
Fri Nov 13 23:04:20 CET 2020


Dear R-experts,

Here below my reproducible example. No error message but I can not get a result. I get "NaN" as a result. I don't understand what is going on. Many thanks for your precious help, as usual.


 # # # # # # # # # # # # # # # # # # # # # # # # #
x<-c(499,491,500,517,438,495,501,525,516,494,500,453,479,481,505,465,477,520,520,480,477,416,502,503,497,513,492,469,504,482,502,498,463,504,495)
y<-c(499,496,424,537,480,484,503,575,540,436,486,506,496,481,508,425,501,519,546,507,452,498,471,495,499,522,509,474,502,534,504,466,527,485,525)

library(robustgam)
true.family <- poisson()

#Robust GAM
fit=robustgam(x,y,sp=0,family=true.family,smooth.basis='ps',K=3)

#OLS
fit1 <- lm(y~x)

#Huber-M
library(robustbase)
library(MASS)
fit2=rlm(y~x)

#GAM
library(mgcv)
fit3=gam(y~s(x))

# MSE of OLS linear model
mean(residuals(fit1)^2)

# MSE of Huber-M linear model
mean(residuals(fit2)^2)

# MSE of GAM
mean(residuals(fit3)^2)

# MSE of robust GAM
mean(residuals(fit)^2)
 # # # # # # # # # # # # # # # # # # # # # # # # #
 



More information about the R-help mailing list