[R-sig-ME] Mixed models with a dichotomous outcome, random slopes, and accounting for autocorrelation
Ben Bolker
bbo|ker @end|ng |rom gm@||@com
Tue Apr 4 20:06:08 CEST 2023
[adding r-sig-mixed back to the cc: list]
This looks mostly right. The only thing you have to watch out for is
that you want `linear_time` to be *numeric* for the fixed-effect model
but numFactor()-ized for the ar1() term. So
dat$linear_time_f <- numFactor(dat$linear_time)
so as not to mess up the original variable, then use linear_time_f
within ar1().
On 2023-04-04 1:59 p.m., Adam Roebuck wrote:
> Hi again Professor Bolker,
>
> Thank you kindly for taking the time to respond and even follow up on my
> original question.
>
> My original post to the listserv was actually asking about a different
> project where I had three levels – day, team, and year – without
> cross-classification. However, my curiosity about handling
> auto-correlation applies to that project and this new one with
> cross-classification.
>
> The new project has a cross-classification of (a) ego and (b) alter
> nested within a higher level team. Ratings of ego and alter are captured
> over time, hence the desire to account for auto-correlation.
> Extrapolating from your email, then, I am guessing the base model would
> look something like the following:
>
> dat$linear_time <- numFactor(dat$linear_time)
>
> mod <- glmmTMB(continuous_outcome ~ 1 + linear_time + Predictor_X +
> (1|ego) + (1|alter) + (1|team) + ar1(linear_time + 0 | ego:alter)
>
> Does that seem to track?
>
> Any additional information would be above and beyond, though highly
> appreciated.
>
> Thanks again for the reply and for all you have done for mixed-level
> modeling.
>
> My best,
> Adam
>
> On Tue, Apr 4, 2023 at 9:47 AM Ben Bolker <bbolker using gmail.com
> <mailto:bbolker using gmail.com>> wrote:
>
> *Message sent from a system outside of UConn.*
>
>
> This seems to have slipped through the cracks, sorry about that.
>
> lme4 doesn't do correlation structures, but glmmTMB does. The closest
> analogue would be something like
>
> ## this should be observation number within group
> dat$times <- numFactor(dat$times)
>
> model2 <- glmmTMB(continuous_outcome ~ 1 + Predictor_X + Day +
> (1 + Day | Team / Year) + ar1(times + 0 | Team:Year)
>
> (your random effect has two | in it; was the second meant to be a
> / ?)
>
> See https://glmmtmb.github.io/glmmTMB/articles/covstruct.html
> <https://glmmtmb.github.io/glmmTMB/articles/covstruct.html>
>
> On 2023-01-25 5:13 p.m., Adam Roebuck wrote:
> > Hello,
> >
> > I am attempting to set up a multilevel model with two grouping
> variables
> > (team and year), random slopes for day of the year, and
> accounting for
> > autocorrelation. I have a number of different outcome variables I
> can use.
> > When the outcome variable is continuous, I can set up a simple
> growth model
> > using the nlme package that looks something like the following:
> >
> > model1 <- lme(continuous_outcome ~ 1 + Predictor_X + Day,
> >
> > random = ~1 + Day | Team | Year, data = dat, method = "REML",
> >
> > control=list(opt="optim"), correlation = corAR1()
> >
> > However, I now want to build a model with a dichotomous outcome
> variable.
> > As far as I know, nlme cannot account for all of the above and a
> > dichotomous outcome. I have, however, seen a few references to
> glmer (in
> > the lme4 package) and glmmTMB being capable of such. I've gone
> back through
> > the archives, though, and am not seeing any clear explanations on
> how to
> > set up such a model.
> >
> > Using the parameters above and the variables I specified, could
> someone
> > please help specify what that model might look like in R or at
> least point
> > me in the right direction?
> >
> > Thanks,
> > Adam
> >
>
>
>
>
> --
> Dr. Benjamin Bolker
> Professor, Mathematics & Statistics and Biology, McMaster University
> Director, School of Computational Science and Engineering
> (Acting) Graduate chair, Mathematics & Statistics
> > E-mail is sent at my convenience; I don't expect replies outside of
> working hours.
>
> _______________________________________________
> R-sig-mixed-models using r-project.org
> <mailto:R-sig-mixed-models using r-project.org> mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
> <https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models>
>
>
>
> --
> *Adam Roebuck*
> University of Connecticut | School of Business
> Doctoral Candidate | Management
> 2100 Hillside Rd., Unit 1041
> Storrs, CT 06269
> (248) 613-9609
--
Dr. Benjamin Bolker
Professor, Mathematics & Statistics and Biology, McMaster University
Director, School of Computational Science and Engineering
(Acting) Graduate chair, Mathematics & Statistics
> E-mail is sent at my convenience; I don't expect replies outside of
working hours.
More information about the R-sig-mixed-models
mailing list