Thaler, Thorn, LAUSANNE, Applied Mathematics
2010-Jul-28  09:12 UTC
[Rd] nlme: augPred.lme for factor covariates
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
Maybe Matching Threads
- Observed responses in 'augPred' data frame - Wrong order ?
- Follow Up To: Splitting the left and right hand terms of a formula
- problem plotting nls objects: couldn't find function "..."
- Weird problem / bug with augPred() from nlme
- Can plot(augPred()) be used with objects that are not groupedData?
