ord <- order(Age) age <- Age[ord] kyp <- Kyp[ord] agemod <- gam(kyp ~ s(age,3), family=binomial) plot(age,fitted(agemod),type="l")