For example, if we make up some (simple) data
## covariates
n <-20
dat <- data.frame(x=runif(n),grp=sample(letters[1:10], n, replace=T),
wts=runif(n))
dat$wts <- dat$wts/mean(dat$wts)
## model matrices
xmat <- model.matrix(~x, data=dat)
zmat <- model.matrix(~0+grp, data=dat)
## effects
beta <- c(0, 0)
b <- rnorm(10)
## response
dat$y <- rnorm(n=n, mean=xmat %*% beta + zmat %*% b, sd=sqrt(1/dat$wts))
## we can then fit the model with
require(nlme)
mod <- lme(y~x, random=~1|grp, weights=varFixed(value=~I(1/wts)),
data=dat)
## however, while we can extract the weights used during the model fitting
with
(getCovariate(mod$modelStruct$varStruct))
## They are in a *different order* from those in the original data
(1/dat$wts)
Does anyone know a fairly fool-proof way of getting the weights out in the
same format as went into the model?