Skip to content
Prev 16388 / 20628 Next

[FORGED] Re: Question about gls --- whoops!!!

G'day Rolf,

On Sat, 24 Mar 2018 11:30:17 +1300
Rolf Turner <r.turner at auckland.ac.nz> wrote:

            
:-)
Because, as you said, you are printing the object. Essentially,
as.vector() just returns the value stored in the object will all
attributes stripped.  Printing on the other hand might call some
function, and here it does:

R> class(fit.gls$modelStruct$corStruct)
[1] "corAR1"    "corStruct"
R> getAnywhere("print.corAR1")
no object named ?print.corAR1? was found
R> getAnywhere("print.corStruct")
A single object matching ?print.corStruct? was found
It was found in the following places
  registered S3 method for print from namespace nlme
  namespace:nlme
with value
[...]
What error did you get?  I do not get an error:

R> foo <- nlme:::coef.corStruct
R> foo(fit.gls$modelStruct$corStruct)
[1] 0.3533897

Or did you mean

R> foo(fit.gls$modelStruct$corStruct, unconstrained=FALSE)
Error in foo(fit.gls$modelStruct$corStruct, unconstrained = FALSE) : 
  do not know how to obtain parameters of ?corAR1? object
There would appear to be no way for the results to be different (look
Well, you are missing that 

R> class(fit.gls$modelStruct$corStruct)
[1] "corAR1"    "corStruct"

And S3 will try to dispatch initially on the first class, then the
second class, and so forth...

And coef.corAR1 exists in the nlme package:

R> nlme:::coef.corAR1
function (object, unconstrained = TRUE, ...) 
{
    if (unconstrained) {
        if (attr(object, "fixed")) {
            return(numeric(0))
        }
        else {
            return(as.vector(object))
        }
    }
    aux <- exp(as.vector(object))
    aux <- c((aux - 1)/(aux + 1))
    names(aux) <- "Phi"
    aux
}
<bytecode: 0x2935e60>
<environment: namespace:nlme>