R Under development (unstable) (2024-06-18 r86781 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. > # Test varia > > require(MuMIn) Loading required package: MuMIn > packageVersion("MuMIn") [1] '1.48.2' > options(na.action = "na.fail") > > #print(packageDescription("MuMIn", fields = "Version")) > # TEST binary response --------------------------------------------------------- > ldose <- rep(0:5, 2) > numdead <- c(1, 4, 9, 13, 18, 20, 0, 2, 6, 10, 12, 16) > sex <- factor(rep(c("M", "F"), c(6, 6))) > SF <- cbind(numdead, numalive=20-numdead) > budworm.lg <- glm(SF ~ sex*ldose, family = binomial) > dd <- dredge(budworm.lg, trace=FALSE) Fixed term is "(Intercept)" > gm <- get.models(dd, 1:4) > model.avg(gm) Call: model.avg(object = gm) Component models: '12' '123' '1' '2' Coefficients: (Intercept) ldose sexM ldose:sexM full -3.365538 1.033944 0.900864 0.06372988 subset -3.365538 1.033944 0.928449 0.35291299 > > # The same, but use cbind directly in the formula > budworm.lg <- glm(cbind(numdead, numalive=20-numdead) ~ sex*ldose, family=binomial) > dd <- dredge(budworm.lg, trace=TRUE) Fixed term is "(Intercept)" 0 : glm(formula = cbind(numdead, numalive = 20 - numdead) ~ 1, family = binomial) 1 : glm(formula = cbind(numdead, numalive = 20 - numdead) ~ ldose + 1, family = binomial) 2 : glm(formula = cbind(numdead, numalive = 20 - numdead) ~ sex + 1, family = binomial) 3 : glm(formula = cbind(numdead, numalive = 20 - numdead) ~ ldose + sex + 1, family = binomial) 7 : glm(formula = cbind(numdead, numalive = 20 - numdead) ~ ldose + sex + ldose:sex + 1, family = binomial) > avgmod <- model.avg(get.models(dd, 1:4)) > > # TEST for consistency of vcov and se calculation ------------------------------ > if(!isTRUE(all.equal(coefTable(avgmod, adjust.se = FALSE)[,2], + sqrt(diag(vcov(avgmod))), tolerance = .001))) + stop("'vcov' has a problem") > > # TEST evaluation from within function ----------------------------------------- > > budworm <- data.frame(ldose = rep(0:5, 2), numdead = c(1, 4, 9, 12, 18, 20, 0, + 2, 6, 10, 12, 16), sex = factor(rep(c("M", "F"), c(6, 6)))) > budworm$SF <- cbind(numdead = budworm$numdead, numalive = 20 - budworm$numdead) > > # evaluate within an exotic environment > (function(dat) (function(dat2) { + #mod <- glm(SF ~ sex*ldose, data = dat2, family = "quasibinomial", trace=T) + mod <- glm(SF ~ sex*ldose, data = dat2, family = "binomial") + #mod <- glm(SF ~ sex*ldose, data = budworm, family = "binomial", trace=F) + print(dd <- dredge(mod, rank = "QAIC", chat = summary(budworm.lg)$dispersion)) + gm <- get.models(dd, subset = NA, family = "binomial") + #print(sys.frames()) + summary(model.avg(gm)) + })(dat))(budworm) Fixed term is "(Intercept)" Global model call: glm(formula = SF ~ sex * ldose, family = "binomial", data = dat2) --- Model selection table (Int) lds sex lds:sex df logLik QAIC delta weight 4 -3.4380 1.053 + 3 -18.736 43.5 0.00 0.552 8 -2.9940 0.906 + + 4 -17.981 44.0 0.49 0.432 2 -2.7810 1.002 2 -23.301 50.6 7.13 0.016 3 -0.4754 + 2 -74.119 152.2 108.77 0.000 1 -0.1671 1 -76.849 155.7 112.23 0.000 Models ranked by QAIC(x, chat = 1) Call: model.avg(object = gm) Component model call: glm(formula = SF ~ <5 unique rhs>, family = binomial, data = dat2) Component models: df logLik QAIC delta weight 12 3 -18.74 43.47 0.00 0.55 123 4 -17.98 43.96 0.49 0.43 1 2 -23.30 50.60 7.13 0.02 2 2 -74.12 152.24 108.77 0.00 (Null) 1 -76.85 155.70 112.23 0.00 Term codes: ldose sex ldose:sex 1 2 3 Model-averaged coefficients: (full average) Estimate Std. Error Adjusted SE z value Pr(>|z|) (Intercept) -3.2356 0.5517 0.6287 5.146 3e-07 *** ldose 0.9885 0.1638 0.1861 5.313 1e-07 *** sexM 0.6493 0.7159 0.7971 0.815 0.415 ldose:sexM 0.1393 0.2368 0.2604 0.535 0.593 (conditional average) Estimate Std. Error Adjusted SE z value Pr(>|z|) (Intercept) -3.2356 0.5517 0.6287 5.146 3e-07 *** ldose 0.9885 0.1638 0.1861 5.313 1e-07 *** sexM 0.6596 0.7169 0.7991 0.825 0.409 ldose:sexM 0.3225 0.2659 0.3129 1.031 0.303 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > > > rm(list=ls()) > > # END TESTS > > proc.time() user system elapsed 1.64 0.23 1.85