testGOF: Test Goodness Of Fit of Gaussian Random Effect Distribution...

Description Usage Arguments Details Value References Examples

View source: R/testGOF.R

Description

This function implements the GOF test introduced Tchetgen & Coull (2006) Biometrika. The test is designed to determine whether the presumed Gaussian distribution of the random effect in a logsitic mixed model has adequate fit. A major contribution of the glmerGOF package is to estimate the variance matrix from a glmer model for computing the chi-squared statistic introduced in Tchetgen & Coull (2006).

Usage

1
2
3
testGOF(data, fitted_model_clogit, fitted_model_glmm, var_names = list(DV
  = NULL, grouping = NULL), gradient_derivative_method = NULL,
  use_Richardson_derivative = NULL)

Arguments

data

The original dataset.

fitted_model_clogit

A fitted conditional logistic model object, from clogit.

fitted_model_glmm

A fitted generalized linear (logistic) mixed model object, from glmer.

var_names

A list indicating the column names (as strings) of two important variables

gradient_derivative_method

User must select either 'simple' (faster) or 'Richardson' (slower but more accurate) as the desired method for the numerical derivative procedure. For more information, see the method argument in grad.

use_Richardson_derivative

defaults to FALSE

Details

The method is based on an asymptotically chi-squared test statistic comparing the difference between estimated components of a generalized linear mixed model (glmm) and a conditional logistic model (clogit). Before using this function, the user should fit his/her desired glmm with glmer, and a clogit model with clogit. The fitted model objects are required arguments, and their estimated components are wrangled in grabModelEstimates.

Value

An object of class "TCGOF", with the following list items:

results

The test statistic and p-value. See the print() generic.

var_names

The list of var_names.

split_data

A list object of the data after it has been split into clusters and NA rows have been removed.

fits

Estimated components from the two models, and other important computations. See the summary() generic.

References

Tchetgen Tchetgen, E. J., & Coull, B. A. (2006) A Diagnostic Test for the Mixing Distribution in a Generalised Linear Mixed Model. Biometrika, 93(4), 1003-1010. https://doi.org/10.1093/biomet/93.4.1003

Examples

 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
library(glmerGOF)
set.seed(1)
n <- 50
m <- 4
beta <- c(2, 2)
id <- rep(1:n, each=m)
x <- rnorm(m*n)
b <- rep(rnorm(n), each=m)
y <- rbinom(m*n, 1, plogis(cbind(1, x) %*% beta + b))
my_data <- data.frame(y,x,id)

variable_names <- list(DV = "y", grouping = "id")

library(lme4)
fit_glmm <- lme4::glmer(
  formula = y ~ x + (1|id),
  family = "binomial",
  data = my_data
)
library(survival)
fit_clogit <- survival::clogit(
  formula = y ~ x + strata(id),
  data = my_data,
  method = "exact"
)

test_results <- testGOF(
  data = my_data,
  fitted_model_clogit = fit_clogit,
  fitted_model_glmm  = fit_glmm,
  var_names = variable_names,
  gradient_derivative_method = "simple"
)
test_results

BarkleyBG/glmerGOF documentation built on July 18, 2019, 6:43 p.m.