I have used nlme to fit and compare nonlinear models in the past. I would now like to use it to fit models to data that are grouped by more than one identifier. It would be great if I could integrate dplyr, purrr, and nlme. One of the nice things would be using the self starting functions that are in the nlme package. I also have a lot of models to run. I'm just not sure if it will all fit together.
Current nlme situation. This works, but limited to only one grouping variable:
library(tidyverse)
library(nlme)
diamonds_grouped <- groupedData(price ~ carat | cut, data = diamonds)
nlsList(price ~ SSlogis(carat, Asym, xmid, scal), data = diamonds_grouped)
Desired sort of workflow. Doesn't work, just how far I've gotten:
fit_mod <- function(df) { ### Not much faith in how I wrote this function
nlsList(price ~ SSlogis(carat, Asym, xmid, scal), data = .)
}
diamonds %>%
group_by(cut, color) %>%
nest() %>%
mutate(
model = map(data, fit_mod),
tidied = map(model, tidy)
)
Not meant to be, or I just don't know how to do it?