[R] GAMS, std errors and confidence intervals

David Winsemius dwinsemius at comcast.net
Thu Jul 7 02:36:20 CEST 2016


> On Jul 4, 2016, at 11:44 AM, Dan Jaffe <djaffe at uw.edu> wrote:
> 
> Can anyone help me calculating CIs from a GAM analysis?
> 
> I have calculated a GAM fit (m3) and the associated std errors using
> predict.gam
> I assume that the 95% CI around each fit value would be 1.96
> times the se.    But when I do this both on the original and a test
> dataset, I find the CI's only encompass about half of the true response
> values.

I would have expected a CI to have been constructed around the mean ( and be a CI for the mean) and so would not have thought that this was an odd result. You seem to have expected a "prediction interval" rather than a confidence interval. To get an estimate of the standard deviation within groups, you might consider multiplying the se by the sqrt(n) for each group. At least that would be the approach in an ordinary linear model. Not sure how it translates to GAMs.


>    I have  tried this using predict.gam using both type="response"
> and type="link"  and get nearly the same result.  What am I  doing wrong?
> 
> Here is the code I am using to get the 95% CIs.
> 
> se3=predict.gam(m3,dat, type="response", se.fit=TRUE)
> 
> upr <- se3$fit + (1.96 * se3$se.fit)
> upr <- m3$family$linkinv(upr)
> lwr <- se3$fit - (1.96 * se3$se.fit)
> lwr <- m3$family$linkinv(lwr)
> CI95=upr-lwr
> CI95=CI95/2
> 
> 	[[alternative HTML version deleted]]

Plain text requested.

> 
> ______________________________________________
> 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.

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list