0

I'm trying to extract a parameter from a model fit by ML which has a correlation structure obtained from corPagel (defined in package ape). The parameter of interest is within the element named apVar in the summary.

library(ape); library(nlme)
cor_lambdaML <- corPagel( 1, avestree, fixed=FALSE )
m <- gls(AUTUMN ~ GREGARIOUSNESS + SEASON + TARSUS + MATURATION + SPRING + MIGRATION + DICHROMATISM + HABITAT + POSTJUVENILE + CONSPICUOUSNESS, correlation = cor_lambdaML, data = avesdata, method = 'ML' )
names(m)
m$apVar

This code produces the following output (please, download a dput with model m here):

           corStruct     lSigma
corStruct 0.03848807 0.03090663
lSigma    0.03090663 0.04403168
attr(,"Pars")
  corStruct      lSigma 
0.858126838 0.008131981 
attr(,"natural")
[1] TRUE

Extracting values of the first matrix is trivial, but how can I extract the value of corStruct within the element attr(, "Pars")?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Santi XGR
  • 185
  • 2
  • 13

2 Answers2

1

Not sure how far you need to dig, but m$Pars$corStruct is where the data are stored. Which is to say: m is a list with many components, one of which is Pars . That itself is a list, with a component corStruct .

?glsObject will start you on the path to details of all the list elements.

Carl Witthoft
  • 20,573
  • 9
  • 43
  • 73
  • As far as I understand, Pars is not a list component of my gls object. The component apVar contains one covariate matrix and two elements which I can't extract. If a try 'm$Pars$corStruct' returns a NULL; if I try 'm$apVar$Pars' returns the error $ operator is invalid for atomic vectors; 'm1023$apVar[[3,1]]' returns subindex out of limits. Any clue? – Santi XGR Feb 03 '14 at 17:07
  • No idea. You could use `names` to find all the elements of `m` and recursively find the elements of those list elements. – Carl Witthoft Feb 03 '14 at 17:37
  • Apparently, there's no way to reach these elements. The structure of m$apVar states there is an element `..- attr(*, "Pars")= Named num [1:2] 0.85813 0.00813`, but if I try `m$apVar..- attr(*, "Pars")` it doesn't like the asterisk. Then, if I try `m$apVar..- attr(3, "Pars")` I get numeric(0) – Santi XGR Feb 03 '14 at 17:53
  • `m$apVar$Pars` doesn't get it? – Carl Witthoft Feb 03 '14 at 19:09
  • Nop! As I said it elicits an error message: $ operator is invalid for atomic vectors – Santi XGR Feb 03 '14 at 21:52
  • Then you'll probably have to dig into the code for the appropriate `print` method for objects of class `glsObject` . Bummer – Carl Witthoft Feb 03 '14 at 23:35
-1

just attr(m, "Pars")

Z Gu
  • 163
  • 1
  • 2
  • 9