How to add a gls fixed variance structure to a GAM

I am using GAM to fit a smooth line to represent the recovery of timber stocks following forest harvest. The data is heterogenous and I do not want to transform it. I understand that a nice way to accommodate the heterogeneity in my data is to add a fixed variance structure.

However, when I try this in GAM I get the following error message: "Error in model.frame.default(formula = t ~ 1 + age, weights = varFixed(~age), : variable lengths differ (found for '(weights)')"

I don't understand why the variable lengths would differ since I am using 'age' for specifying both the fixed variance structure and also the explanatory variable. Have a look: M1<- gam(t~s(age), method = 'REML', weights = varFixed(~age))

Any suggestions would be welcome!

• Here is an update: I could be wrong but I think that a variance structure cannot be added to GAM. It must be added to GAMM along with a random effect. – Ira S Dec 23 '14 at 1:12
• do you mind pointing to the example data you are using? – AdamO May 30 '17 at 19:42
• Also a couple of thoughts: the nlme function varFixed is a structure which depends on other aspects of the fitting procedure, so must be computed in tandem with a model. This makes it possible for varFixed to supply a fixed vector of weights, the type of argument model.matrix requires, giving the error you print. When you say "fixed" variance, I do not know if you mean constant variance, or if you are trying to set the dispersion to a constant in a generalized linear model (which would require other fitting methods than least squares). – AdamO May 30 '17 at 19:47