[Rd] nlme: augPred.lme for factor covariates

From: Thaler, Thorn, LAUSANNE, Applied Mathematics <Thorn.Thaler_at_rdls.nestle.com>
Date: Wed, 28 Jul 2010 11:12:51 +0200


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 = 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



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 28 Jul 2010 - 09:17:18 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 28 Jul 2010 - 10:50:20 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive