Re: [R] model non-nested random effects in nlme library

2012-01-23 Thread mwege
Season  Individual  FT  FTLengthCurvIndex   dir.lin
2009W   GW522   1   20  0.538931977 1.8884631
2009W   GW522   2   28  0.498651384 0.8379838
2010W   A1841   17  0.492549537 1.23907
2010W   A1842   23  0.630582873 1.3010501
2010W   A1843   27  0.478359129 0.6488715
2010W   OO456   1   19  0.533888959 2.1471811
2011S   A1421   5   0.777146676 2.1168675
2011S   A1422   9   0.875245592 1.6422436
2011S   A1423   7   0.912760026 1.7903588
2011S   A1424   8   0.368177237 1.8827868
2011S   A1425   12  0.790110963 1.723052
2011S   A1426   17  0.530349103 2.104049
2011S   GW503   1   9   0.822049259 1.1624394
2011S   GW503   2   9   0.805705677 1.4590542
2011S   GW503   3   8   0.764926849 1.3209942
2011S   GW503   4   6   0.802072344 1.3903048
2011S   GW503   5   11  0.651539153 1.8380583
2011S   GW503   6   10  0.830663679 1.588408
2011S   A1881   9   0.710436628 1.648512
2011S   A1882   9   0.718584921 1.8092618
2011S   A1883   11  0.641348724 1.6436084
2011S   A1884   13  0.68348373  1.9246773
2011S   A1885   16  0.652572155 1.8031925
2011S   LB504   1   8   0.852924101 1.3636355
2011S   LB504   2   13  0.823136776 1.4618325
2011S   LB504   3   12  0.75605543  1.3690891
2011S   LB504   4   18  0.478978335 1.4824566
2011W   A1681   14  0.281223063 0.9328787
2011W   LB491   1   16  0.610471298 1.968323
2011W   LB491   2   19  0.510918052 1.4519552
2011W   LB491   3   22  0.503229145 0.8539206
2011W   LB491   4   50  0.538715522 0.9241864
2011W   OO440   1   17  0.565258152 1.7838117
2011W   OO440   2   33  0.561548705 1.0129331
2011W   OO440   3   67  0.272020469 0.4717046
2009W   GW495   1   36  0.501137969 1.5722404
2009W   FB515   1   37  0.573009216 -1.6528193
2009W   FB513   1   25  0.63702884  -2.0009436
2009W   FB513   2   117 0.393231124 -1.213341
2010W   A1641   27  0.734281437 1.3515392
2010W   A1642   48  0.46142686  0.8394697
2010W   A1643   32  0.649801375 0.8179546
2010W   OO455   1   22  0.697236934 1.8904179
2010W   OO455   2   20  0.458066447 2.7011468
2010W   OO455   3   31  0.406230997 2.3547132
2010W   OO478   1   28  0.666138495 1.6501422
2010W   OO478   2   36  0.682536815 1.5002367
2010W   OO478   3   12  0.545977976 1.264352
2010W   OO478   4   57  0.408892851 0.8349835
2010W   A1601   36  0.744976923 1.2087431
2010W   A1602   47  0.552217128 0.8730726

So here I have copied a small subset of my data.  It has to do with seals
swimming to and from an island to forage as obtained from sattelite
telemetry data.  Season is 2009W (2009 winter), 2011s = 2011 summer etc.
Then there is individual.  FTLength is foraging trip length...i.e. how many
days the animal was out to sea. FT is the number of foraging trip. I.e. the
first or the second. CurvIndex is what I call the curvilinear index...which
basically measures how straight or loopy the animal travels to and from the
island. This is my independent variable and varies between 0 and 1, where 1
is straight and 0 is very undirectional...or "loopy" and then dir.lin is the
mean direction from the island which was a circular variable but I converted
to a linear one.

So I basically want to model the following:

lmer(Curvindex~FTLenght+FT+dir.lin + (1|Individual) + (1|Season) 

I used Individual and Season as seperate random effects because although I
have repeated measurements for some individuals, they are within a year and
no individual was tracked in more than one year. You said in your previous
message that if I have good and bad years I might want to nest individual in
year. Well since I only have 3 years, I dont think its really that
feasible...or what  I know from the data...none of the years were
particularly different from the rest or "bad" in a sense.

Is my thinking correct? How would you model my above example in the nlme
library?

Thanks again


--
View this message in context: 
http://r.789695.n4.nabble.com/model-non-nested-random-effects-in-nlme-library-tp4321021p4321650.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] model non-nested random effects in nlme library

2012-01-23 Thread Ben Bolker
mwege  gmail.com> writes:

> 
> Hello all,
> 
> In lme4 if you want to model two non-nested random effects you code it like
> this:
> 
> mod1 <- lmer(y~x + (1|randomvar1) + (1|randomvar2))
> 
> How would you go about to model something similar in nlme?
> 
> In my database I have two variables for which I have repeated measures, lets
> call them "individual" and "year".
> But none of the "individuals" were measured in more than one year. So as I
> understand it, I should not nest individual in year or visa versa.

  Not necessarily.  If you believed that there were good years and
bad years but individuals varied randomly within years (i.e. there
is no such thing as a consistently good individual) then you would
have individuals nested within years.  If you have at least some
multiple measurements of some individuals *within* some years,
then you have a three-level model (samples within individuals
within years, where the among-sample variance is the residual error);
otherwise you have a two-level model (individuals within years).

If you believe there are good individuals and bad individuals
but that years are not good or bad for everyone then you have
years nested within individuals.

  Otherwise you indeed have a crossed design.


>  Someone suggested I do it as above. But I am accustomed to nlme, and dont
> know how one would code non-nested random effects.
> 
> In the Pinheiro and Bates book there is an example coded like this:
> modB <- lme(y~x,
>   +   random = pdBlocked(list(pdIdent(~year-1), pdIdent(~individual-1
> 
> But when I try it I keep getting an error message saying:  "Error in
> getGroups.data.frame(dataMix, groups) : 
>   Invalid formula for groups"

  It would definitely be best to forward this question to the r-sig-mixed-models
 r-project.org mailing list ... (I'm answering via Gmane, otherwise
I would do it myself)

  Can you provide a reproducible example?

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.