chooseModel.data.frame: Determines the set of significant terms from results stored...

chooseModel.data.frameR Documentation

Determines the set of significant terms from results stored in a data.frame, taking into account the marginality relations of terms and recording the tests used in a data.frame.

Description

Uses the p.values from a set of hypothesis tests that are stored in the supplied data.frame to choose a model to describe the effects of the terms corresponding to the p-values, taking into account the hierarchy or marginality of terms. In particular, a term will not be tested if it is marginal to (or nested in) one that is significant. For example, if A:B is significant, then neither A nor B will be tested. The tests used in choosing the selected model are listed in the data.frame choose.summary.

No change is made to the p.values, the DF and denDF being for information only.

Usage

## S3 method for class 'data.frame'
chooseModel(object, terms=NULL, p.values = "Pr", 
            DF = "Df", denDF = "denDF", omit.DF = FALSE, 
            terms.marginality=NULL, alpha = 0.05, ...)

Arguments

object

a data.frame object containing the results of hypothesis tests for a set of terms. It components should include terms, p.values, and, if not set to NA, DF and denDF.

terms

A character giving the name of the column in object containing the terms corresponding to the p.values. If NULL, it is assumed that the row names of object give the terms.

p.values

A character giving the name of the column in object containing the p-values to use in deciding whether or not terms are significant.

DF

Can be a character or a numeric that specifies the numerator degrees of freedom for the tests. If it is a character, it must be the name of a column in object containing the numerator degrees of freedom that are to be included in the choose.summary data.frame. if it is a numeric, its length must equal 1 or the number of rows in object. In either case, a column labelled DF will be included in the choose.summary data.frame. It will contain either the replicated single value (which can be NA) or the values supplied.

denDF

Can be a character or a numeric that specifies the denominator degrees of freedom for the tests. If it is a character, it must be the name of a column in object containing the denominator degrees of freedom that are to be included in the choose.summary data.frame. if it is a numeric, its length must equal 1 or the number of rows in object. In either case, a column labelled denDF will be included in the choose.summary data.frame. It will contain either the replicated single value (which can be NA) or the values supplied.

omit.DF

A logical indicating whether or not both the numerator and denominator degrees of freedom are to be omitted from choose.summary. Doing so will mean that the choose.summary no longer has the same columns as a test.summary from an asrtests.object.

terms.marginality

A square matrix of ones and zeros with row and column names being the names of the those terms in the terms column of object that are to be tested. The diagonal elements should be one, indicating that a term is marginal to itself. Elements should be one if the row term is marginal to the column term. All other elements should be zero. The names of the rows and columns should match the those elements of terms that are to be tested.

alpha

The significance level for the hypothesis testing.

...

Provision for passing arguments to functions called internally - not used at present.

Value

A list containing:

  1. choose.summary: a data.frame summarizing the tests carried out in choosing the significant terms; provided omit.DF = FALSE, it has the same columns as a test.summary from an asrtests.object

  2. sig.tests: a character vector whose elements are the significant terms amongst those tested.

Author(s)

Chris Brien

See Also

chooseModel, chooseModel.asrtests

Examples

  
  data("Ladybird.dat")
  
  ## Use asreml to get the table of p-values

  ## Not run: 
  m1.asr <- asreml(logitP ~ Host*Cadavers*Ladybird, 
                   random = ~ Run,
                   data = Ladybird.dat)
  current.asrt <- as.asrtests(m1.asr)
  fixed.tab <-  current.asrt$wald.tab
  col.p <- "Pr"
  df = "Df"
  den.df = "denDF"
  
## End(Not run)
  
  ## Use lmeTest to get the table of p-values
  if (requireNamespace("lmerTest", quietly = TRUE) & 
      requireNamespace("emmeans", quietly = TRUE))
  {
    m1.lmer <- lmerTest::lmer(logitP ~ Host*Cadavers*Ladybird + (1|Run),
                              data=Ladybird.dat)
    fixed.tab <- anova(m1.lmer, type = "II")
    col.p <- "Pr(>F)"
    df = "NumDF"
    den.df = "DenDF"
  }
  
  ## Select a model using the table of p-values obtained with either asreml or lmerTest
  if (exists("fixed.tab"))
  {
    term.marg <- dae::marginality(dae::pstructure(~ Host*Cadavers*Ladybird, 
                                                  data = Ladybird.dat))
    chosen <- chooseModel(fixed.tab, p.values = col.p, DF = df, denDF = den.df, 
                          terms.marginality = term.marg)
  }

asremlPlus documentation built on Oct. 27, 2024, 5:06 p.m.