# Fitting a gam model with simple Gaussian/Student-t heteroskedasticity

I am fitting a gam model in R (using the gam function in mgcv) to account for some non-linear effects in my data. A stripped down example of what I am doing in R is:

mod=gam(y~s(x)+s(z),data=df)


However, I want to add a slightly more complicated variance model to my regression of the form

$$\epsilon \sim N(0,\sigma^2),\ \sigma = f(\hat{\mu})$$

where $\hat{\mu}$ is the fitted value of the model. (Actually, it would be nice if $\epsilon \sim t_\nu$ for some $\nu$ but sticking to this for now. I have managed to do this in the gls function from nlme using the varFunc(form=fitted(.)) type approach, but can't figure out if there is an option to do the same kind of thing using gam.

I recognise this is not really the intention of a GLM/GAM model, but I don't want to reinvent the wheel if I am just missing something obvious

Edit: In response to the question in the comment below, I am hoping to fit a linear or quadratic function for $f$. I do not know the exact form of $f$ but plan to iteratively estimate it from the residuals if this can't be done automatically.

Edit2: Typo in R code - first spline is not meant to be a function of y!

• Do you know the functional form of $f$? Oct 16, 2013 at 21:00
• Well.. I don't know for sure, but I was planning on fitting either a linear or quadratic function of the fitted values. Oct 16, 2013 at 23:02
• Is your target variable $y > 0$ or perhaps $\geq 0$? If so, that opens up some options... Oct 17, 2013 at 15:30
• The "family" parameter in gam specifies a link function, as with a generalized linear model; part of that is a specification of a mean-variance relationship. For example, for the Poisson family, variance = mean (with the default link function); for the Gamma, the standard deviation = the mean (with the default link function.) You may still be able to make use of this approach by transforming y mildly; the nonparametric nature of the right hand side (at least in your example) means you don't have to worry (much) about functional forms being changed by doing so. Oct 17, 2013 at 21:18
• Yes, that's another idea. It's just that if you can do it easily with the "family" parameter, the iteration is handled for you. But if it's going to be work, it might well be better to do it all by hand, well inside a loop at any rate, and get more flexibility. Oct 17, 2013 at 22:50