as.predictions.frame: Forms a 'predictions.frame' from a 'data.frame', ensuring...

as.predictions.frameR Documentation

Forms a predictions.frame from a data.frame, ensuring that the correct columns are present.

Description

Creates a predictions.frame from a data.frame by adding the class predictions.frame to it, and renaming the columns containing the predictions, se, est.status and error.intervals.

Usage

as.predictions.frame(data, classify = NULL, 
                     predictions = NULL, se = NULL, est.status = NULL, 
                     interval.type = NULL, interval.names = NULL)

Arguments

data

A data.frame containing columns giving the variables that uniquely index the predicted values and columns with the predicted values, their standard errors and, optionally, their estimation status (est.status).

classify

A character string giving the variables that define the margins of the multiway table that was predicted. Multiway tables are specified by forming an interaction type term from the classifying variables, that is, separating the variable names with the : operator. For predicting the overall mean, the classify is set to "(Intercept)".

predictions

A character giving the name of the column in data that contains the predicted values. This column will be renamed to predicted.value.

se

A character giving the name of the column in data that contains the standard errors of the predicted values. This column will be renamed to standard.error.

est.status

A character giving the name of the column in data that contains the estimation status of the predicted values. It will have a value Estimable for predicted values that have been estimated and a value Aliased for predicted values that are NA. If a column named est.status is not present in data and est.status is NULL, a column est.status will be generated.

interval.type

A character specifying the type of error.intervals stored in data that require renaming. If NULL, error.intervals will not be renamed, even if they are present. Otherwise, interval.type should be set to one of "CI", "SE" or "halfLSD".

interval.names

A character specifying the column names of the lower and upper limits stored in data that are to be renamed. The character must be of length two, with the first element being the name of the 'lower' limit and the second element being the name of the 'upper' limit.

Value

An S3-class predictions.frame.

Author(s)

Chris Brien

See Also

asremlPlus-package, predictions.frame, is.predictions.frame, predictions.frame,
validPredictionsFrame

Examples

  data(Oats.dat)
  
  ## Use asreml to get predictions and associated statistics

  ## Not run: 
  m1.asr <- asreml(Yield ~ Nitrogen*Variety, 
                   random=~Blocks/Wplots,
                   data=Oats.dat)
  current.asrt <- as.asrtests(m1.asr)
  Var.pred <- asreml::predict.asreml(m1.asr, classify="Nitrogen:Variety", 
                                      sed=TRUE)
  if (getASRemlVersionLoaded(nchar = 1) == "3")
    Var.pred <- Var.pred$predictions
 #Form predictions.frame changing asreml-R4 names to the standard names, if these are present
 Var.preds <- as.predictions.frame(Var.pred$pvals, se = "std.error", 
                                    est.status = "status")
  
## End(Not run)
  
  ## Use lmerTest 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)
    Var.emm <- emmeans::emmeans(m1.lmer, specs = ~ Nitrogen:Variety)
    Var.preds <- summary(Var.emm)
    Var.preds <- as.predictions.frame(Var.preds, predictions = "emmean", 
                                      se = "SE", interval.type = "CI", 
                                      interval.names = c("lower.CL", "upper.CL"))
  }

  ## Check the class and validity of the alldiffs object
  if (exists("Var.preds"))
  {
    is.predictions.frame(Var.preds)
    validPredictionsFrame(Var.preds)
  }

asremlPlus documentation built on Nov. 5, 2023, 5:07 p.m.