ratioTransform.alldiffs: Calculates the ratios of nominated pairs of predictions...

View source: R/pairTrans.r

ratioTransform.alldiffsR Documentation

Calculates the ratios of nominated pairs of predictions stored in an alldiffs.object.

Description

Ratio predictions and error intervals are formed for two levels of a factor, the ratio.factor. For each pair of a level of the ratio.factor in numerator.levels with a level in denominator.levels, the ratio predictions are formed from all combinations of the other factors as the ratio of the two predictions for each combination, along with confidence intervals for the ratio predictions computed using the Fieller (1954) method.

The printing of the components produced is controlled by the tables argument.

Usage

## S3 method for class 'alldiffs'
ratioTransform(alldiffs.obj, ratio.factor, 
               numerator.levels, denominator.levels, 
               method = "Fieller", alpha = 0.05,  
               response = NULL, response.title = NULL, 
               tables = "predictions", ...)

Arguments

alldiffs.obj

An alldiffs.object.

ratio.factor

A character string giving the name of the factor for whose levels the ratios are to be calculated.

numerator.levels

A character string containing the levels of ratio.factor to be used as numerators of the ratio.

denominator.levels

A character string containing the levels of ratio.factor to be used as denominators of the ratio.

method

A character string specifying the method to use in calculating the ratios and their error.intervals. At present only Fieller is available. For the Fieller method, ratios of predictions are formed and confidence intervals formed for them using Fieller's (1954) theorem.

alpha

A numeric giving the significance level for LSDs or one minus the confidence level for confidence intervals.

response

A character specifying the response variable for the predictions. It is stored as an attribute to the alldiffs.object .

response.title

A character specifying the title for the response variable for the predictions. It is stored as an attribute to the alldiffs.object.

tables

A character vector containing either none or predictions

...

further arguments passed to linTransform.alldiffs.

Value

A list of predictions.frames, each containing the ratio predictions and their confidence limits for a combination of the numerator.levels with the denominator.levels. It will also contain the values of the variables in the classify of alldiffs.obj that index the ratio predictions, except that the ratio.factor is omitted.

If sortFactor attribute of the alldiffs.object is set and is not the ratio.factor, the predictions and their backtransforms will be sorted using the sortOrder attribute of the alldiffs.object.

Author(s)

Chris Brien

References

Fieller, E. C. (1954). Some Problems in Interval Estimation. Journal of the Royal Statistical Society.Series B (Methodological), 16, 175-185.

See Also

pairdiffsTransform, linTransform, predictPlus.asreml, as.alldiffs,
print.alldiffs, sort.alldiffs, subset.alldiffs, allDifferences.data.frame,
redoErrorIntervals.alldiffs, recalcLSD.alldiffs, predictPresent.asreml,
plotPredictions.data.frame,
as.Date, predict.asreml

Examples

#### Form the ratios and Fieller CIs for RGR Salinity
load(system.file("extdata", "testDiffs.rda", package = "asremlPlus", mustWork = TRUE))
Preds.ratio.RGR <- ratioTransform(diffs.RGR,
                                  ratio.factor = "Salinity", 
                                  numerator.levels = "Salt",
                                  denominator.levels = "Control")

#### Form the ratios and Fieller CIs for Nitrogen compared to no Nitrogen                                  
data("Oats.dat")
## Not run: 
m1.asr <- asreml(Yield ~ Nitrogen*Variety, 
                 random=~Blocks/Wplots,
                 data=Oats.dat)
current.asrt <- as.asrtests(m1.asr)
wald.tab <-  current.asrt$wald.tab
Var.diffs <- predictPlus(m1.asr, classify="Nitrogen:Variety", pairwise = TRUE,
                         Vmatrix = TRUE, error.intervals = "halfLeast",
                         LSDtype = "factor", LSDby = "Variety",
                         wald.tab = wald.tab)

## End(Not run)

 ## Use lme4 and emmmeans to get predictions and associated statistics
if (requireNamespace("lmerTest", quietly = TRUE) & 
    requireNamespace("emmeans", quietly = TRUE))
{
  m1.lmer <- lmerTest::lmer(Yield ~ Nitrogen*Variety + (1|Blocks/Wplots),
                              data=Oats.dat)
  ## Set up a wald.tab
  int <- as.data.frame(rbind(rep(NA,4)))
  rownames(int) <- "(Intercept)"
  wald.tab <- anova(m1.lmer, ddf = "Kenward", type = 1)[,3:6]
  names(wald.tab) <- names(int) <- c("Df", "denDF", "F.inc", "Pr")
  wald.tab <- rbind(int, wald.tab)
  #Get predictions
  Var.emm <- emmeans::emmeans(m1.lmer, specs = ~ Nitrogen:Variety)
  Var.preds <- summary(Var.emm)
  ## Modify Var.preds to be compatible with a predictions.frame
  Var.preds <- as.predictions.frame(Var.preds, predictions = "emmean", 
                                    se = "SE", interval.type = "CI", 
                                    interval.names = c("lower.CL", "upper.CL"))
  Var.vcov <- vcov(Var.emm)
  Var.sed <- NULL
  den.df <- wald.tab[match("Variety", rownames(wald.tab)), "denDF"]
  
  #Create alldiffs object
  Var.diffs <- as.alldiffs(predictions = Var.preds, 
                           sed = Var.sed, vcov = Var.vcov, 
                           classify = "Nitrogen:Variety", response = "Yield", tdf = den.df)
} 

if (exists("Var.diffs"))
  Preds.ratio.OatsN <- ratioTransform(alldiffs.obj = Var.diffs,
                                      ratio.factor = "Nitrogen", 
                                      numerator.levels = c("0.2","0.4","0.6"),
                                      denominator.levels = "0.2")

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