J
2004-Oct-03 07:18 UTC
[R] creating new varFunc classes in nlme .. error: "Don't know how to get coefficients for .. object"
Hello. I am trying my hand at modifying the varFunc class varExp, but I must be missing a step. All I want to do right now is make a working copy of varExp, call it varExp2, and then later change it. coef.varExp2, coef<-.varExp2, and Initialize.varExp2 all seem to work properly after I construct them. I can successfully use the commands: v2 <- varExp2(form = ~age|Sex,fixed = c(Female=0)) v2 <- Initialize(v2, Orthodont) But, after this when I type "v2" at the prompt, I get the message: Error in coef.varFunc(x, uncons = FALSE, allCoef TRUE) : Don't know how to get coefficients for varExp2 object Im not sure what to do. Im sure it is a simple fix or statement I need to enter. Can anyone offer suggestions? Do I have to use the command varFunc(varExp2) at some point? As background, I created VarExp2 by using: varExp2 <- function (value = numeric(0), ... [and the rest of the VarExp function] ...) At the end of the function I had to change the statement: c("varExp",... to c("varExp2... Then I used: setMethod("Initialize","varExp2", function (object, data, ...) { form <- formula(object) ... [and the rest of the Initialize.varExp function] ...) I did the same with the coef and coef<- functions. Im not sure why coef, coef<-, and Initialize seem to work (they produce the same output and attributes as varExp), but still I get the error message. Would it have anything to do with the warning I get when I create the coef.varExp2 and other functions: In the method signature for function "coef<-", class "varExp2" has no current definition in: matchSignature(signature, fdef, where) Any help would be greatly appreciated. Do I somehow need to tell nlme where to find my new functions? John
J
2004-Oct-03 12:42 UTC
[R] Re: creating new varFunc classes in nlme .. error: "Don't know how to get coefficients for .. object"
Ah!! After way too many hours of work Ive answered my own question. To get varExp2, a copy of varExp, to work as a new varFunc, one needs to use this sort of syntax: update.varExp2 <- function (object, data, ...) { print ("enter update") val <- NextMethod() if (length(val) == 0) { aux <- coef(val, allCoef = TRUE) if (!is.null(grps <- getGroups(val))) { aux <- aux[grps] } attr(val, "logLik") <- sum(log(attr(val, "weights") <- exp(-aux * getCovariate(val)))) } val } setMethod("update", "varExp2", update.varExp2) And then do the same for all methods used by varExp (see methods(class="varExp")). When writing the setMethod for coef<-.varExp2, use cat("coef<-.varExp2") in the statement. Or at least that worked for me. But I still have an unanswered question from the other day (see [R] two questions on nlme: error messages and nested variance). What is the best way in nlme to model the variance when the variance of the variance is not constant but is dependent on a covariate? Thanks. John
Possibly Parallel Threads
- how to view the syntax of a method which is not a generic method
- Potential clue for Bug 16975 - lme fixed sigma - inconsistent REML estimation
- question regarding variance function in gls
- varComb in gls/lme
- need help getting started writing a new varFunc class for lme()