tests/testthat/test-FE-formula.R

gfe <- .get_fixed_effects

test_that(".get_fixed_effects", {
  f <- "am ~ disp:wt + (1|gear) + wt + (1+wt|carb)"
  expect_equal(
    gfe(stats::as.formula(f)),
    stats::as.formula("am ~ disp:wt + wt")
  )

  f <- "am ~ disp:wt + wt + (1|gear) + (1+wt|carb)"
  expect_equal(
    gfe(stats::as.formula(f)),
    stats::as.formula("am ~ disp:wt + wt")
  )

  f <- "am ~ (1|gear) + (1+wt|carb) + disp:wt + wt"
  expect_equal(
    gfe(stats::as.formula(f)),
    stats::as.formula("am ~ disp:wt + wt")
  )

  f <- "am ~ 1 + (1|gear)"
  expect_equal(
    gfe(stats::as.formula(f)),
    stats::as.formula("am ~ 1")
  )

  f <- "am ~ 1 + (1+wt|gear)"
  expect_equal(
    gfe(stats::as.formula(f)),
    stats::as.formula("am ~ 1")
  )

  f <- "am ~ disp:wt + (1|gear) + wt + (1+wt|carb)"
  expect_equal(
    gfe(stats::as.formula(f)),
    stats::as.formula("am ~ disp:wt + wt")
  )

  f <- "am ~ disp:wt + (1|gear) + wt + (1*wt|carb)"
  expect_equal(
    gfe(stats::as.formula(f)),
    stats::as.formula("am ~ disp:wt + wt")
  )

  f <- "am ~ (1|gear) + (1+wt|carb) + disp:wt * wt"
  expect_equal(
    gfe(stats::as.formula(f)),
    stats::as.formula("am ~ disp:wt * wt")
  )

  f <- "am ~ disp:wt + poly(gear, 2) + wt + (1+wt|carb)"
  expect_equal(
    gfe(stats::as.formula(f)),
    stats::as.formula("am ~ disp:wt + poly(gear, 2) + wt")
  )

  f <- "y ~ post + time1 + (1 | g2 / g1 / g0) + (post + time1 - 1 | g2)"
  expect_equal(
    gfe(stats::as.formula(f)),
    stats::as.formula("y ~ post + time1")
  )

  f <- "count ~ mined + (1 | site) + offset(Wtemp)"
  expect_equal(
    gfe(stats::as.formula(f)),
    stats::as.formula("count ~ mined + offset(Wtemp)")
  )

  f <- "count ~ mined + offset(Wtemp) + (1 | site)"
  expect_equal(
    gfe(stats::as.formula(f)),
    stats::as.formula("count ~ mined + offset(Wtemp)")
  )

  f <- "time | cens(censored) ~ age * sex + disease + (1|patient)"
  expect_equal(
    gfe(stats::as.formula(f)),
    stats::as.formula("time | cens(censored) ~ age * sex + disease")
  )

  f <- "success | trials(ntrials) ~ x + (1 | patient)"
  expect_equal(
    gfe(stats::as.formula(f)),
    stats::as.formula("success | trials(ntrials) ~ x")
  )
})

Try the insight package in your browser

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

insight documentation built on Nov. 26, 2023, 5:08 p.m.