inst/nami_simulations/simulation_code/RCT_permtest/helpers_permutationtest.R

get_results <- function(m, parm, level = 0.95, type = c("Wald", "score")) {
  type <- match.arg(type)
  stopifnot(parm %in% names(coef(m)))
  stopifnot(length(parm) == 1L)
  if (type == "score") {
      sc <- score_test(m, parm = parm, level = level, 
                       confint = TRUE)
      return(list(tau = coef(m)[parm], se = sqrt(vcov(m)[parm,parm]),
                  score = sc$conf.int, pvalue = sc$p.value[[1]]))
  } 
  lf <- paste(parm, "=0")
  cc <- glht(m, linfct = lf, coef. = function(x) coef(x, fixed = FALSE))
  ret <- list(tau = coef(m)[parm], 
              pvalue = summary(cc)$test$pvalue[[1]])
  if (inherits(m, "mmlt")) {
          ############## NEWLY IMPLEMENTED PERMUTATION TEST 
          permtest <- perm_test(m, parm = parm, nullvalue = 0, confint = FALSE)
          ret$pvalueperm <- permtest$p.value    
          ###############
  }
  return(ret)
}

Try the tram package in your browser

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

tram documentation built on Nov. 23, 2026, 5:07 p.m.