fabian-s / RLRsim

R package for fast & exact (restricted) likelihood ratio tests for mixed and additive models
12 stars 4 forks source link

No support for models of class "lm" so cannot compare "lmer" to "lm" #11

Closed travis-leith closed 4 months ago

travis-leith commented 4 months ago

I cannot work out how to use exactRLRT to test a case with a single random effect. This is because lme4 will not let me create a model with no random effects and RLRsim does not support models of class lm.

set.seed(123)
group_intercepts <-
  tibble(
    group_id = 1:10,
    group_effect = rnorm(10)
  )

random_data <- 
  tibble(
    group_id = rep(1:10, each = 10),
    x = rnorm(100)
  ) |>
  inner_join(group_intercepts, by = "group_id") |>
  mutate(
    y = 2 * x + group_effect + rnorm(100) / 2
  )

m_full <- lmer(y ~ x - 1 + (1 | group_id), data = random_data)  
summary(m_full)

m_restricted <- lm(y ~ x - 1, data = random_data)
summary(m_restricted)

exactRLRT(m = m_full, m0 = m_restricted)

exactRLRT(m = m_full, mA = m_full, m0 = m_restricted)

The last 2 lines are me trying to get it to work, but I get errors about not being able to find a method getME for class NULL and lm respectively. Am I doing this right?

travis-leith commented 4 months ago

Ah, I just tried exactRLRT(m = m_full) and got a result. I also note the documentation clearly states "Testing in models with only a single variance component require only the first argument m."