Learn R Programming

incubate (version 1.4.0)

test_diff: Test the difference for model parameter(s) between two uncorrelated groups

Description

The test is in fact a model comparison between a null model where the parameters are enforced to be equal and an unconstrained full model. The model parameters can be fit with various methods: MPSE, MLEn, MLEc or MLEw. Parametric bootstrap tests and likelihood ratio tests are supported. As test statistic for the bootstrap test we use twice the difference in best (=lowest) objective function value, i.e. 2 * (val_0 - val_1). The factor 2 does not matter but it becomes reminiscent of a likelihood ratio test statistic albeit the objective function is not a negative log-likelihood in all cases (e.g. it is the negative of the maximum product spacing metric for the MPSE-method).

Usage

test_diff(
  x,
  y = stop("Provide data for group y!"),
  distribution = c("exponential", "weibull"),
  twoPhase = FALSE,
  type = c("all", "bootstrap", "GOF", "moran", "pearson", "logrank", "LRT"),
  param = "delay1",
  method = c("MPSE", "MLEw", "MLEc", "MLEn"),
  profiled = method != "MPSE",
  ties = c("density", "equispaced", "error"),
  doLogrank = TRUE,
  R = 400,
  chiSqApprox = FALSE,
  verbose = 0
)

Value

list with the results of the test. Element P contains the different P-values, for instance from parametric bootstrap

Arguments

x

data from reference/control group.

y

data from the treatment group.

distribution

Name of the distribution to use or distribution object.

twoPhase

logical(1). Do we model two phases per group? Default is FALSE, i.e. a single delay phase per group.

type

character. Which type of tests to perform?

param

character. Names of parameters to test difference for. Default value is 'delay1'. You can specify multiple parameters, by providing multiple parameter names or by concatenating them with a + in a single string. Ignored for non-parametric tests.

method

character. Which method to fit the models.

profiled

logical. Use the profiled likelihood?

ties

character. How to handle ties in data vector of a group?

doLogrank

logical. Do also non-parametric logrank tests?

R

numeric(1). Number of bootstrap samples to evaluate the distribution of the test statistic.

chiSqApprox

logical flag. In bootstrap, should we estimate the best degrees of freedom for chi-square to match the distribution of the test statistic under H0?

verbose

numeric. How many details are requested? Higher value means more details. 0=off, no details.

Details

High values of this difference speak against the null model (i.e., high val_0 indicates bad fit under the null model0 and/or low values of val_1 indicate a good fit under the more general model1. The test is implemented as a parametric bootstrap test, i.e., we

  1. take the given null-model fit as ground truth

  2. regenerate data according to this model fit

  3. recalculate the test statistic

  4. appraise the observed test statistic in light of the generated distribution under H0

Examples

Run this code
set.seed(123)
# generate example data
grA <- rweib_delayed(n = 70, delay1 = 5, shape1 = 2, scale1 = 8)
grB <- rweib_delayed(n = 60, delay1 = 7, shape1 = 1.8, scale1 = 6)

# difference in delay parameter is significant at 5% level
test_diff(x = grA, y = grB,
  distribution = "weibull", param = "delay1",
  type = "bootstrap", method = "MPSE", R = 50)

# but the non-parametric logrank test is not significant
# no need to specify parameters
test_diff(x = grA, y = grB,
  type = "logrank")

Run the code above in your browser using DataLab