[Rd] nlme: augPred.lme for factor covariates

Thaler, Thorn, LAUSANNE, Applied Mathematics Thorn.Thaler at rdls.nestle.com
Wed Jul 28 11:12:51 CEST 2010

Hi everybody,

as you may be aware the function augPred.lme does not work as soon as
the covariate is a factor. The problem lies in the line

newprimary <- seq(from = minimum, to = maximum, length.out = length.out)

which does not make sense for factors. I think augPred.lme can be useful
for models with a factor covariate as well. Thus, I propose to change
the code to:

augPred.lme <- function (object, primary = NULL, minimum = min(primary),
maximum = max(primary), 
    length.out = 51, level = Q, newprim = NULL, ...) 
    data <- eval(object$call$data)
    if (!inherits(data, "data.frame")) {
        stop(paste("Data in", substitute(object), "call must evaluate to
a data frame"))
    if (is.null(primary)) {
        if (!inherits(data, "groupedData")) {
            stop(paste(sys.call()[[1]], "without \"primary\" can only be
used with fits of groupedData objects"))
        primary <- getCovariate(data)
        prName <- deparse(getCovariateFormula(data)[[2]])
    else {
        primary <- asOneSidedFormula(primary)[[2]]
        prName <- deparse(primary)
        primary <- eval(primary, data)
    # allow for non numeric covariates #
    if (!is.null(newprim)) {
        newprimary <- newprim
    } else if (is.numeric(primary)) {
    	  newprimary <- seq(from = minimum, to = maximum, length.out =
    } else {
        warning("'primary' is not numeric. Provide either 'newprim' or
use a numeric primary")
        newprimary <- primary

The function now takes an additional parameter newprim. The user thus
can explicitly specify the values based on which the prediction should
be made. Additionally, if the user does not provide newprim and the
primary is not a numeric a warning is issued and the predictions are
based on the original values.

Any feedback appreciated.

BR, Thorn

More information about the R-devel mailing list