Problem
I've been using a tidy
wrapper for the drc
package—tidydrc
— to build growth curves which produces a tidy
version of the normal output (best for ggplot
). However, due to the inherit nesting of the models, I can't run simple drc
functions since the models are nested inside a dataframe. I've attached code that mirrors drc
and tidydrc
package below.
Goal
To compare information criteria from multiple model fits for the tidydrc
output using the drc
function mselect()
—ultimately to efficiently select the best fitting model.
Ideal Result (works with drc
)
library(tidydrc) # To load the Puromycin data
library(drc)
model_1 <- drm(rate ~ conc, state, data = Puromycin, fct = MM.3())
mselect(model_1, list(LL.3(), LL.5(), W1.3(), W1.4(), W2.4(), baro5()))
# DESIRED OUTPUT SIMILAR TO THIS
logLik IC Lack of fit Res var
MM.3 -78.10685 170.2137 0.9779485 70.54874 # Best fitting model
LL.3 -78.52648 171.0530 0.9491058 73.17059
W1.3 -79.22592 172.4518 0.8763679 77.75903
W2.4 -77.87330 173.7466 0.9315559 78.34783
W1.4 -78.16193 174.3239 0.8862192 80.33907
LL.5 -77.53835 177.0767 0.7936113 87.80627
baro5 -78.00206 178.0041 0.6357592 91.41919
Not Working Example with tidydrc
library(tidyverse) # tidydrc utilizes tidyverse functions
model_2 <- tidydrc_model(data = Puromycin, conc, rate, state, model = MM.3())
summary(model_2)
Error:
summary.vctrs_list_of()
not implemented.
Now, I can manually tease apart the list of models in the dataframe model_2
but can't seem to figure out the correct apply
statements (it's a mess) to get this working.
Progress Thus Far
These both produce the same error, so at least I've subsetted a level down but now I'm stuck and pretty sure this is not the ideal solution.
mselect(model_2$drmod, list(LL.3(), LL.5(), W1.3(), W1.4(), W2.4(), baro5()))
model_2_sub <- model_2$drmod # Manually subset the drmod column
apply(model_2_sub, 2, mselect(list(LL.3(), LL.5(), W1.3(), W1.4(), W2.4(), baro5())))
Error in UseMethod("logLik") : no applicable method for 'logLik' applied to an object of class "list"
I've even tried the tidyverse
function unnest()
to no avail
model_2_unnest <- model_2 %>% unnest_longer(drmod, indices_include = FALSE)