Consider this dummy dataset.
My real dataset with over 1000 records has
scatter large and small values.
I want to predict for values with NA but I
get negative predictions. Is this a normal
behaviour or I am missing a gam argument
to force the model to predict positive values.
library(mgcv)
test <- data.frame(iddate=seq(as.Date("2014-01-01"),
        as.Date("2014-01-12"), by="days"),
        value=c(300,29,22,NA,128,24,15,1,3,30,NA,2))
test
str(test)
mod <- gam(value ~ s(as.numeric(iddate)),data=test)
# Predict for values with NA's
test$pred <- with(test,ifelse(is.na(value),predict(mod,test),value))
test
	[[alternative HTML version deleted]]

