tests/testthat/test-stereotype.R

tol <- 1e-4

backPainLong <- expandCategorical(backPain, "pain")

## stereotype model
stereotype <- gnm(count ~ pain + Mult(pain, x1 + x2 + x3), 
                  eliminate = id, family = "poisson",
                  data = backPainLong, verbose = FALSE)

test_that("sterotype model as expected for backPain data", {
    # Obtain number of parameters and log-likelihoods for equivalent
    # "Six groups: one-dimensional" multinomial model presented in Table 5
    # maximised log-likelihood
    size <- tapply(backPainLong$count, backPainLong$id, sum)[backPainLong$id]
    expect_equal(round(sum(stereotype$y * log(stereotype$fitted/size)), 2),
                 -151.55)
    # number of parameters
    expect_equal(stereotype$rank - nlevels(stereotype$eliminate), 12,
                 ignore_attr = TRUE)
})

Try the gnm package in your browser

Any scripts or data that you put into this service are public.

gnm documentation built on Sept. 16, 2023, 5:06 p.m.