2
$\begingroup$

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!

The image is just to demonstrate heterogenous data that should be conveniently fixed with the varFixed()

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Ira S Dec 23 '14 at 1:12
  • $\begingroup$ do you mind pointing to the example data you are using? $\endgroup$ – AdamO May 30 '17 at 19:42
  • $\begingroup$ 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). $\endgroup$ – AdamO May 30 '17 at 19:47
2
$\begingroup$

Now I know!

To add in a variance function (ie one from a generalized least squares; see Ch4 Zurr et al 2009) you must specify the model using GAMM.

However, note that in GAMM you can only add a variance function if using a normal probability distribution. This is because GAMM is simply a wrapper function (think of it as a control panel) that acts on other functions hidden within/behind it. If using a normal probabiltiy distribution then GAMM calls lme() and you can specify a variance function.

Once you change to a different probability distribution, then GAMM calls GLMM.PQL, which does not take variance functions (at least as far as I know).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.