I am trying to create a nested tibble with columns containing models. I succeeded in creating a column with the nlsList models. I am failing at creating a column with the corresponding nlme's.
Even when I extract one nlsList element and try to use it without map() it fails. I am stumped.
library(nlme)
fm1 = nlsList(uptake ~ SSasympOff(conc, Asym, lrc, c0),
data = CO2, start = c(Asym = 30, lrc = -4.5, c0 = 52))
# str(CO2)
gCO2 <- CO2 %>%
dplyr::group_by(Treatment) %>%
nest() %>%
mutate(gdat = map(data, ~ groupedData(uptake ~ conc | Plant, data = .x)))
gCO2
# # A tibble: 2 x 3
# # Groups: Treatment [2]
# Treatment data gdat
# <fct> <list> <list>
# 1 nonchilled <tibble [42 × 4]> <tibble [42 × 4]>
# 2 chilled <tibble [42 × 4]> <tibble [42 × 4]>
map(gCO2$gdat, ~class(.)) #OK?
gCO2 <- gCO2 %>%
mutate(nlsLst1 =
map(gdat,
~ nlsList(uptake ~ SSasympOff(conc, Asym, lrc, c0),
data = .x, start = c(Asym = 30,
lrc = -4.5,
c0 = 52))))
map(gCO2$nlsLst1, ~class(.)) #OK?
gCO2 <- gCO2 %>%
mutate(nlme1 = map(nlsLst1, ~nlme(model = .x,
random = Asym ~ 1)))
# Error: Problem with `mutate()` input `nlme1`.
# x object '.x' not found
# ℹ Input `nlme1` is `map(nlsLst1, ~nlme(model = ., random = Asym ~ 1))`.
# ℹ The error occurred in group 1: Treatment = "nonchilled".
# Run `rlang::last_error()` to see where the error occurred.