[R-sig-ME] MCMCglmm:interaction bt continuous variable and categorical random effect

Joshua Wiley jwiley.psych at gmail.com
Sun Mar 31 23:39:25 CEST 2013


 Hi John,

I am not quite sure what road is --- if it is continuous, then:

us(1 + road):wolf

will yield a 2 x 2 variance covariance matrix, so, you would need
something like:

G = list(
  G1 = list(V = diag(2), nu = 1.002),
  G2 = list(V = 1, nu = .002)
)

(set your own nu values).  diag(2) just gives an identity matrix, so
basically the prior has the intercept/slope uncorrelated, although in
the posterior they may be.  Specifying a sensible prior is a bit
outside the scope of this list serv, I think.

If road is categorical, it may be worth thinking more about.  If it
only has a few levels, probably not a big deal.  If you have, say, 20
different roads, interacting that with 70 wolves, may be more complex
than your dataset will reasonably support.

Cheers,

Joshua



On Sun, Mar 31, 2013 at 2:20 PM, john benson <smilodon2000 at hotmail.com> wrote:
> Hi Joshua,
>
> Thanks for the quick reply!  I tried the code you suggested, but I got an
> error message regarding my prior.
>
> Error in priorformat(if (NOpriorG) { :
>   V is the wrong dimension for some prior$G/prior$R elements
>
> Any thoughts on how to structure the prior for the code you suggested?
>
> Many thanks!
>
> John
>
>> Date: Sun, 31 Mar 2013 13:59:20 -0700
>> Subject: Re: [R-sig-ME] MCMCglmm:interaction bt continuous variable and
>> categorical random effect
>> From: jwiley.psych at gmail.com
>> To: smilodon2000 at hotmail.com
>> CC: r-sig-mixed-models at r-project.org
>
>>
>> Hi John,
>>
>> That is the basic idea, but I doubt you want to parameterize it quite
>> that way. I would suggest:
>>
>> Model1 <- MCMCglmm(used ~ slope + elevation + road,
>> random = ~ us(1 + road):wolf + pack, family = "categorical",
>> data = datum, prior = prior1, pr = TRUE)
>>
>> which would fit a random intercept and slope by wolf, that are allowed
>> to be correlated, as well as a random intercept by pack (assumed
>> orthogonal to the others).
>>
>> Having road in the fixed effects portion will give you the overall
>> effect, and then the random effects bit will be shrunken deviations
>> from that.
>>
>> Cheers,
>>
>> Joshua
>>
>>
>> On Sun, Mar 31, 2013 at 1:32 PM, john benson <smilodon2000 at hotmail.com>
>> wrote:
>> >
>> >
>> >
>> >
>> >
>> >
>> > Hi,
>> > I am using MCMCglmm to fit resource selection models for wolves using
>> > logistic regression where the response variable is pixels on the landscape
>> > that are either used by, or available to, wolves. I have named the response
>> > variable "used". Observed locations of wolves are coded 1 and available
>> > locations for wolves (systematic locations across their home ranges) are
>> > coded 0. My initial interest was to assess relative selection (in a
>> > use-available context) of various environmental variables which are things
>> > like slope, elevation, and distance to roads. I'm including a random term
>> > for individual wolf to account for the unbalanced sample sizes (of
>> > observations) across individuals and a random term for pack to account for
>> > the fact that I have sampled multiple wolves within some packs. Here is my
>> > code and prior:
>> >
>> >
>> > prior1<-list(R=list(V=1,fix=1),G=list(G1=list(V=1,nu=0.002),G2=list(V=1,nu=0.002)))Model1<-MCMCglmm(used~slope+elevation+road,random=~wolf+pack,family="categorical",data=datum,prior=prior1)
>> > This seems to have worked quite well and the various diagnostics
>> > indicate good chain mixing and low autocorrelation, as long as I used
>> > sufficient iterations, thinning, and burnin. I am making population-level
>> > inference on the relative selection or avoidance of the fixed effects.
>> > Although not my primary question, I'd be interested in confirmation that my
>> > code looks correct for the desired inference.
>> > My real question is that I'd like to derive individual selection
>> > coefficients for each wolf in relation to a given environmental variable
>> > (i.e. road). I would then use these coefficients in a separate analysis to
>> > see how selection of roads varies in relation to various things such as
>> > availability of roads, genetic ancestry, etc. I have thought of 2 ways to
>> > derive the individual selection coefficients for roads for each wolf:
>> > 1. I could run a separate model for each wolf and simply use the fixed
>> > effect coefficient for road from each model. This seems valid but would be
>> > time consuming (because I have ~70 wolves) and seems to fail to take
>> > advantage of the random effect of wolf in the overall model which presumably
>> > could be used to derive an estimate of individual selection of a given
>> > resource.
>> > 2. So alternatively, I wondered if I could run the overall model, but
>> > this time include an interaction between the random effect of wolf and road
>> > (which is continuous). I'm not sure if this valid or the best way to
>> > structure the code but here is my first try:
>> >
>> > Model1<-MCMCglmm(used~slope+elevation,random=~wolf:road+pack,family="categorical",data=datum,prior=prior1,
>> > pr=TRUE)
>> >
>> > Again my goal is simply to derive a coefficient of selection of roads
>> > for each individual wolf from the overall model. Any help with this would be
>> > greatly appreciated and if anything in my explanation or question is unclear
>> > please let me know and I will try to clarify.
>> > Many thanks in advance!
>> > John
>> >
>> >
>> >
>> >
>> > [[alternative HTML version deleted]]
>> >
>> > _______________________________________________
>> > R-sig-mixed-models at r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>>
>>
>>
>> --
>> Joshua Wiley
>> Ph.D. Student, Health Psychology
>> University of California, Los Angeles
>> http://joshuawiley.com/
>> Senior Analyst - Elkhart Group Ltd.
>> http://elkhartgroup.com



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://joshuawiley.com/
Senior Analyst - Elkhart Group Ltd.
http://elkhartgroup.com



More information about the R-sig-mixed-models mailing list