Learn R Programming

asremlPlus (version 4.2-32)

facRecode.alldiffs: Recodes factor levels using values in a vector. The values in the vector do not have to be unique.

Description

Recodes the levels and values of a factor, in the prediction component of an alldiffs.object using each value in the newlevels vector to replace the corresponding value in the vector of levels of the factor. The matching changes are made to the other components of the alldiffs.object. The levels of the factors are recoded using fac.recode from the dae package.

Usage

# S3 method for alldiffs
facRecode(object, factor, newlevels,  ...)

Arguments

object
factor

A character containing the name of a factor in the prediction component of object whose levels are to be recoded.

newlevels

A vector of length levels(factor) containing values to use in the recoding.

...

Further arguments passed to the factor call creating the new factor.

Value

A modified alldiffs.object.

See Also

as.alldiffs, allDifferences.data.frame, print.alldiffs, sort.alldiffs, facCombine.alldiffs, facRename.alldiffs, renewClassify.alldiffs; fac.recode in package dae.

Examples

Run this code
# NOT RUN {
  data("Ladybird.dat")
  
  ## Use asreml to get predictions and associated statistics

  
# }
# NOT RUN {
  m1.asr <- asreml(logitP ~ Host*Cadavers*Ladybird, 
                   random = ~ Run,
                   data = Ladybird.dat)
  current.asrt <- as.asrtests(m1.asr)
  HCL.pred <- asreml::predict.asreml(m1.asr, classify="Host:Cadavers:Ladybird", 
                                     sed=TRUE)
  HCL.preds <- HCL.pred$pvals
  HCL.sed <- HCL.pred$sed
  HCL.vcov <- NULL
  wald.tab <-  current.asrt$wald.tab
  den.df <- wald.tab[match("Host:Cadavers:Ladybird", rownames(wald.tab)), "denDF"]
  
# }
# NOT RUN {
  
  ## Use lmeTest and emmmeans to get predictions and associated statistics
  if (requireNamespace("lmerTest", quietly = TRUE) & 
      requireNamespace("emmeans", quietly = TRUE))
  {
    m1.lmer <- lmerTest::lmer(logitP ~ Host*Cadavers*Ladybird + (1|Run),
                              data=Ladybird.dat)
    HCL.emm <- emmeans::emmeans(m1.lmer, specs = ~ Host:Cadavers:Ladybird)
    HCL.preds <- summary(HCL.emm)
    den.df <- min(HCL.preds$df)
    ## Modify HCL.preds to be compatible with a predictions.frame
    HCL.preds <- as.predictions.frame(HCL.preds, predictions = "emmean", 
                                      se = "SE", interval.type = "CI", 
                                      interval.names = c("lower.CL", "upper.CL"))
    HCL.vcov <- vcov(HCL.emm)
    HCL.sed <- NULL
  }
  
  ## Use the predictions obtained with either asreml or lmerTest
  if (exists("HCL.preds"))
  {
    ## Form an all.diffs object
    HCL.diffs <- as.alldiffs(predictions = HCL.preds, classify = "Host:Cadavers:Ladybird", 
                             sed = HCL.sed, vcov = HCL.vcov, tdf = den.df)
    
    ## Check the class and validity of the alldiffs object
    is.alldiffs(HCL.diffs)
    validAlldiffs(HCL.diffs)

    ## Recode Ladybird
    HCL.diffs <- facRecode(HCL.diffs, factor = "Ladybird", newlevels = c("none", "present"))
    
    ## Check the validity of HCL.diffs
    validAlldiffs(HCL.diffs)
  }
# }

Run the code above in your browser using DataLab