Advertisement
Guest User

Untitled

a guest
Jul 24th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #Solution 2 attempt
  2. set.seed(101)
  3. dd <- data.frame(x1= rnorm(1920), x2=rnorm(1920), x3=rnorm(1920), x4=rnorm(1920),
  4. treatment = factor(rep(1:2, each=3)),
  5. replicate = factor(rep(1:3, each=1)),
  6. stage = factor(rep(1:5, each=384)),
  7. country = factor(rep(1:4, each=96)),
  8. plot = factor(rep(1:10, each=24)),
  9. chamber = factor(rep(1:6, each=1)),
  10. n = 1920)
  11.  
  12. library(lme4)
  13. dd$y <- simulate(~ x1 + x2 + x3 + (1|plot),
  14. family = binomial,
  15. weights = dd$n,
  16. newdata = dd,
  17. newparams = list(beta = c(1,1,1,1),
  18. theta = 1))[[1]]
  19.  
  20. # my real response variable 'y' has a poisson distribution, but I had difficulty figuring
  21. # out how to simulate a poisson distribution so I left the bionomial.
  22.  
  23. m0 <- lmer(y~ x1 + x2 + x3 + x4 + treatment*replicate*stage + (1|chamber) + (1|country/plot),
  24. data=dd,
  25. na.action = "na.fail",
  26. REML = F,
  27. lmercontrol = glmerControl(optimizer="bobyqa"))
  28.  
  29. nullmodel <- MuMIn:::.nullFitRE(m0)
  30. dredge(m0, m.lim = c(0,5), rank = "AIC", extra =list(R2 = function(x) {
  31. r.squaredGLMM(x, null = nullmodel)["delta", ]}))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement