AIC value for two models uing 96 well plate data

I am using Growthrate package in R to calculate maximum growth rate value. I used two models fit_easylinear and fit_spline models.
Now, I want to extract AIC value for each well after fitting two models. any help at this moment is highly appreciated.
dataset:
library(growthrates)
split_df <- split(bactgrowth,~strain+replicate+conc)
timeseries <- lapply(split_df, function(x) x$value)

df <- cbind(data.frame(time = 1:31),
as.data.frame(timeseries))

fit_easymodel <- lapply(2:length(colnames(df)), function(x) fit_easylinear(df$time, df[]))
fit_splinemodel <- lapply(2:length(colnames(df)), function(x) fit_spline(df$time, df[],spar=0.5))

So I need to extract AIC value for fit_easymodel and fit_splinemodel and store them separately for each well.

Trying to use the AIC on e.g. one of the fit fit_splinemodel-s gives me an error message:

AIC(fit_splinemodel[[3]] ) 
Error in UseMethod("logLik") : 
  no applicable method for 'logLik' applied to an object of class "c('smooth.spline_fit', 'growthrates_fit')"

Personally I prefer to use the map functions of the purrr package instead of lapply.
In the code below I extract the deviance value from the first six model results.
Do not know if that makes any sense to you.
?`rsquared,growthrates_fit-method ` shows which results can be accessed

library(growthrates)
#> Loading required package: lattice
#> Loading required package: deSolve
data("bactgrowth")
split_df <- split(bactgrowth,~strain+replicate+conc)
timeseries <- lapply(split_df, function(x) x$value)

df <- cbind(data.frame(time = 1:31),
                as.data.frame(timeseries))

library(purrr)

# fit_easymodel <- lapply(2:length(colnames(df)), function(x) fit_easylinear(df$time, df[] ))
fit_easymodel <- purrr::map(2:length(colnames(df)), function(x) fit_easylinear(df$time, df[,x] ))
#> Warning in summary.lm(m): essentially perfect fit: summary may be unreliable

#> Warning in summary.lm(m): essentially perfect fit: summary may be unreliable

### other warnings manually removed

head(purrr::map_dbl(fit_easymodel,function(x) deviance(x )))
#> [1] 0.012487437 0.020573997 0.006437104 0.038155104 0.022007107 0.003899535
 
# fit_splinemodel <- lapply(2:length(colnames(df)), function(x) fit_spline(df$time, df[],spar=0.5))
fit_splinemodel <-  purrr::map(2:length(colnames(df)),  function(x) fit_spline(df$time, df[,x],spar=0.5))

head(purrr::map_dbl(fit_splinemodel,function(x) deviance(x)))
#> [1] 0.02368248 0.03203602 0.03861812 0.13365795 0.03155168 0.02578376
Created on 2022-10-21 with reprex v2.0.2
1 Like

Thank you for your help. It's not giving the actual AIC value but giving RSS. I can use that but what I need is to get AIC which I am not sure how to get it.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.