It’s happy houR. I’m in a happy place, and I’m going to spend an hour trying
to learn something new. Earlier today I watched a video of Hadley Wickham explaining his approach to handling many models.
Now I want to see if this combination of purrr and broom can make my approach to multi-model inference easier.
So here’s what I’d have done last year. This is point count data of 3 species of prairie songbirds together with 3 habitat covariates. I’m
pretty sure this comes from Andrea Hanson’s 2007 MSc. thesis, Conservation and beneficial functions of grassland birds in agroecosystems. Normally I would do a bunch of model checking on my most complex model, but I’m in a rush to try broom, so I create a list of possible models. With 3 main effects and their 3 interactions, we have 48 possible models to consider. That is far too many for such a limited dataset. Background knowledge suggests that VOR will be important, so all models I consider include that effect. Then I’ll add each of the landscape variables in turn, together with the interaction with VOR.
Now that I have a list of fitted models, I can get a model selection table:
Now in Hadley’s approach, I would put the formulas and the models as rows in a data.frame.
Ah. There I seem to be stuck. I’d thought I’d be able to put the list of models into a column of a data.frame.
I mean, Hadley put a whole column of data.frames into a data.frame! Surely this isn’t any more difficult. Can this be a vector?
No. Hmmm. Happy houR is rapidly coming to a close and I haven’t achieved my goal. Maybe the trick is to use tidyr::nest()? No, because that only worked to put subsets of the variables into single rows. I guess I could coerce the whole thing to a character vector
OK that works. But now I’ll have to coerce that to a formula before fitting … I guess I can use a function to handle all that
Well nuts. I’m guessing map() isn’t doing what I’m expecting, which is walking across the rows. But then again …
… it’s a factor. oh.
Aha! progress.
but that’s just a list … OK. I’m calling it a day. Nothing’s ever as simple as it seems.