R Under development (unstable) (2024-06-15 r86749 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > ## simple examples with offsets, to exercise methods etc. > > library(lme4) Loading required package: Matrix > > if (.Platform$OS.type != "windows") { + ## generate a basic Gamma/random effects sim + set.seed(101) + d <- expand.grid(block=LETTERS[1:26],rep=1:100) + d$x <- runif(nrow(d)) ## sd=1 + reff_f <- rnorm(length(levels(d$block)),sd=1) + ## need intercept large enough to avoid negative values + d$eta0 <- 4+3*d$x ## version without random effects + d$eta <- d$eta0+reff_f[d$block] + + ## lmer() test: + d$mu <- d$eta + d$y <- rnorm(nrow(d),mean=d$mu,sd=1) + + fm1 <- lmer(y~x+(1|block), data=d) + fm1off <- lmer(y~x+(1|block)+offset(3*x),data=d) + + ## check equality + stopifnot(all.equal(fixef(fm1)[2]-3,fixef(fm1off)[2])) + + p0 <- predict(fm1) + p1 <- predict(fm1,newdata=d) + p2 <- predict(fm1off,newdata=d) + stopifnot(all.equal(p0,p1), + all.equal(p1,p2)) + + + ## glmer() test: + d$mu <- exp(d$eta) + d$y <- rpois(nrow(d),d$mu) + + gm1 <- glmer(y~x+(1|block), data=d,family=poisson, + control=glmerControl(check.conv.grad="ignore")) + gm1off <- glmer(y~x+(1|block)+offset(3*x),data=d,family=poisson, + control=glmerControl(check.conv.grad="ignore")) + + ## check equality + stopifnot(all.equal(fixef(gm1)[2]-3,fixef(gm1off)[2],tolerance=3e-4)) + + p0 <- predict(gm1) + p1 <- predict(gm1,newdata=d) + p2 <- predict(gm1off,newdata=d) + stopifnot(all.equal(p0,p1), + all.equal(p1,p2)) + + ## FIXME: should also test simulations + } ## skip on windows (for speed) > > proc.time() user system elapsed 1.28 0.12 1.39