[R-sig-ME] How to extract num. of observations and groups used in a mixed model using gee package
Ben Bolker
bbolker at gmail.com
Tue Apr 24 18:19:29 CEST 2012
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 12-04-24 12:11 PM, david oseguera montiel wrote:
> Ben, Rob and David, Thank you all, to resume, the option given by
> Ben worked when id variable is stored like in the sleeping data
> set.
>
> library(lme4) mod <- gee(Reaction ~ Days, id=Subject,
> data=sleepstudy, corstr="exchangeable") length(unique(mod$id)) [1]
> 18
>
> The option given by David worked when id variable is stored like in
> the warpbreaks data set.
>
>
> summgee <- summary(gee(breaks ~ tension, id=wool, data=warpbreaks,
> corstr="exchangeable"))
>
> summgee$call$id # wool
> length(levels(warpbreaks[[as.character(summgee$call$id)]])) #[1] 2
>
This is the difference between a 'gee' object and 'summary.gee'
object. Please make sure to read the details quoted below, to make
sure that you are not misled in cases where the clusters are coded as
non-unique (but contiguous) levels ... (and it wasn't my idea, it was
Chuck Cleland's).
Ben
>
> On 24/04/2012 10:01, Ben Bolker wrote:
>> On 12-04-24 10:54 AM, Robert Kushler wrote:
>>> The following lines from the gee help page ...
>>>
>>> Details
>>>
>>> Though input data need not be sorted by the variable named
>>> "id", the program will interpret physically contiguous records
>>> possessing the same value of id as members of the same cluster.
>>> Thus it is possible to use the following vector as an id vector
>>> to discriminate 4 clusters of size 4:
>>> c(0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1).
>>>
>>>
>>> ... indicate that the proposed strategy may not yield a
>>> correct answer. In fact, the above suggests that you could get
>>> different results depending on whether or not your data set is
>>> sorted. I find this quite disturbing, but haven't taken the
>>> time to test it.
>>>
>>> Regards, Rob Kushler
>> Yow. Good catch.
>>
>> Maybe length(rle(geemodel$id)$length) would work?
>>
>>
>>> (id<- rep(c(0,1,0),each=3))
>> [1] 0 0 0 1 1 1 0 0 0
>>> length(rle(id)$lengths)
>> [1] 3
>>> (id<- rep(c(0,1,0,1),each=3))
>> [1] 0 0 0 1 1 1 0 0 0 1 1 1
>>> length(rle(id)$lengths)
>> [1] 4
>>
>>>
>>>
>>>
>>>
>>> On 4/24/2012 10:25 AM, David Winsemius wrote:
>>>> On Apr 24, 2012, at 9:46 AM, Ben Bolker wrote:
>>>>
>>>>> david oseguera montiel<oseguera.david at ...> writes:
>>>>>
>>>>>> I meant the grouping factor in the model indicated by id.
>>>>>> From gee documentation 'id = a vector which identifies
>>>>>> the clusters..'. So in the warpbreaks data set, id = wool
>>>>>> has 54 obs, in two clusters (groups).
>>>>> [snip]
>>>>>
>>>>>>>> David, Thank you very much. Number of observations
>>>>>>>> solved, but I am still missing how to find out the
>>>>>>>> number of groups used. In the warpbreaks data set
>>>>>>>> these are 2. Any ideas. Thank you.
>>>>>>>>
>>>>>>> I must be unclear what you mean by "number of groups".
>>>>>
>>>>> Didn't Chuck Cleland's answer work, i.e.
>>>>> length(unique(model$id)) ... ?
>>>> It didn't work for me. length(unique(summgee$id)) [1] 0
>>>>> summgee$id
>>>> NULL
>>>>
>>>> See my other reply for what did work. I suppose it could be
>>>> that both the OP and I are behind on gee versions. Mine is
>>>> 4.13-17 and I see that there is a more recent binary on CRAN.
>>>> With a (slightly out-of-date) version loaded, I am loath to
>>>> detach because getting things to all sync up is a bit of a
>>>> hassle and error-prone without a fresh start and I have other
>>>> work time-consuming running in this session.
>>>>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iQEcBAEBAgAGBQJPltKQAAoJED2whTVMEyK9nUQH/0DZis3/ko00hw4TaHQcK7LT
pxMpbrjnwEO/RWFnmAosXznjHyfCuxZkWA4YJZPsEcNTC7RxLo8LuMITp1U5DVTt
JOuJExiAE1oR9/EnRhu2VmhHqeyMgU94Lg5SKZ2GWofgTlPw8Rly3o2DYG7K/s8M
QRWeXdqSJsl6sjmQGpy1t0PClEJ9ix9OBEMVJsAsNBY6pHIsB1dbBI1eTor21imU
ihJb3Yu11ye1nPZJqhXC13OP1quv8BQzDgDCaFQxT94Lm6z1QjiGE7HAp8RA4UwR
3nZIWZ4BlZFbFhVzK2JvOASXN9u75WYAioVob0nLq6r1gnuDSWCyg20V5RuJOkI=
=ep+g
-----END PGP SIGNATURE-----
More information about the R-sig-mixed-models
mailing list