[R-sig-ME] Extracting weights from an lme object

robert bagchi bagchi.r at gmail.com
Fri Oct 10 15:56:49 CEST 2014

Dear list,

My apologies if this is an elementary problem, but I can't find a solution
and it's driving me crazy!

As part of a function that bootstraps from an lme model, I need to extract
the weights argument that was used during model fitting.

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),
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

mod <- lme(y~x, random=~1|grp, weights=varFixed(value=~I(1/wts)),
## however, while we can extract the weights used during the model fitting

## They are in a *different order* from those in the original data

Does anyone know a fairly fool-proof way of getting the weights out in the
same format as went into the model?

Any help would be much appreciated.

Dr Robert Bagchi
Ecosystem Management
Department of Environmental Systems Science
ETH Zürich
Universitätstrasse 16
8092 Zurich

tel: +41 (0)44 63 26805
email: bagchi.r at gmail.com (preferred)
robert.bagchi at usys.ethz.ch
web: http://www.ecology.ethz.ch/people/obass/rbagchi

*Recent publications:*
Pathogens and insect herbivores drive rainforest plant diversity and
Testing for enemy‐mediated density‐dependence in the mortality of
seedlings: field experiments with five Neotropical tree species
Shifting Baselines on a Tropical Forest Frontier: Extirpations Drive
Declines in Local Ecological Knowledge
PLoS One

	[[alternative HTML version deleted]]

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