File: test-median-binomial.R

package info (click to toggle)
r-cran-brglm2 0.9.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 872 kB
  • sloc: ansic: 52; makefile: 5
file content (37 lines) | stat: -rwxr-xr-x 1,609 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
library("mbrglm")

data("lizards", package = "brglm2")
data("endometrial",package = "brglm2")

links <- lapply(c("logit", "probit", "cloglog", "cauchit"), make.link)

tol <- 1e-10
mbrglmControl <- mbrglm.control(mbr.epsilon = 1e-10, mbr.maxit = 1000)

for (l in seq_along(links)) {
    ## Lizards
    lizardsFormula <- cbind(grahami, opalinus) ~ height + diameter + light + time
    lizardsMBRlegacy <- mbrglm(lizardsFormula, family = binomial(links[[l]]), data = lizards,
                                       method = "mbrglm.fit",
                                       control.mbrglm = mbrglmControl)
    expect_warning(lizardsMBR <- glm(lizardsFormula, family = binomial(links[[l]]), data = lizards,
                                     method = "brglmFit", type="AS_median", epsilon = 1e-10, maxit = 1000))

    ## Endometrial
    endoFormula <- HG ~ NV + PI + EH
    expect_warning({
        endoMBRlegacy <- mbrglm(endoFormula, family = binomial(links[[l]]), data = endometrial,
                                        method = "mbrglm.fit",
                                        control.mbrglm = mbrglmControl)
        endoMBR <- glm(endoFormula, family = binomial(links[[l]]), data = endometrial,
                       method = "brglmFit", type = "AS_median", epsilon = 1e-10, maxit = 1000)
    })

    c1 <- coef(summary(endoMBRlegacy))
    c2 <- coef(summary(endoMBR))

    ## glm with brglmFit method and mbrglm return the same coefficients when link is" links[[l]]$name
    expect_equal(coef(lizardsMBR), coef(lizardsMBRlegacy), tolerance = tol)
    expect_equal(c1, c2, tolerance = tol)
}