[R-sig-ME] nlme Fixed Variance Function

Ben Bolker bbolker at gmail.com
Thu Feb 23 22:24:34 CET 2012


Agostino Moro <agostino.moro99 at ...> writes:

> 
> Dear R users,
> 
> I am trying to fit a gls model and weight my data points using a
> VarFixed structure. I have found many examples, but I do not
> understand the difference between the following models with varFixed
> specified in a different way:
> 
> mod<-gls(y~x,weights=varFixed(~1/invsigma)
> 
> mod<-gls(y~x,weights=varFixed(~invsigma)
> 
> In my case I would simply like to weigh my data points by their
> inverse variance.
> 

  It would be interesting to have links to examples that show
these two usages.  One of them must be wrong, or at least weird.
Have you looked at ?varFixed?  It says:

 Letting v denote the variance covariate defined in ‘value’, the variance
     function s2(v) for this class is s2(v)=|v|. 

Thus if you know the variance _a priori_ is 'yvar' I think you want
weights=varFixed(~yvar) .  This will set the variance to yvar and
hence weight by 1/yvar.  (I'm using "yvar" rather than "sigma" or
"invsigma" because it's easy to get confused about whether "sigma"
represents variance or standard deviation ...)

  I would strongly recommend using the 'data' argument: have x, y, 
and yvar as columns in a data frame d and use

mod <- gls(y~x,weights=varFixed(~yvar),data=d)

  Taking a look at Pinheiro and Bates 2000 would be a good idea.
If you're too cheap or in too much of a hurry to buy it, you can
search for "varFixed" within the book on Google books (see p. 209)
for a slightly more extended discussion of the admittedly terse
example in ?varFixed ...




More information about the R-sig-mixed-models mailing list