Skip to contents
data <- parvob19_fi_1997_1998[order(parvob19_fi_1997_1998$age), ]
aggregated <- transform_data(data$age, data$seropositive)

# fit with linelisting data
model1 <- polynomial_model(data$age, status = data$seropositive, type = "Muench")
# fit with aggregated data
model2 <- polynomial_model(aggregated$t, pos = aggregated$pos, tot = aggregated$tot, type = "Muench")
# fit with laggregated data
model3 <- polynomial_model(aggregated$t, pos = aggregated$pos, tot = aggregated$tot, type = "Griffith")
# fit with gam
model4 <- penalized_spline_model(aggregated$t, pos = aggregated$pos, tot = aggregated$tot)

Generate models comparison data.frame

Function compare_models() is used for quickly computing AIC and BIC values for given model(s).

The function can take an arbitrary number of models and all models must be created from serosv’s set of *_model() functions. It will then return a data.frame of 4 columns:

  • model model identifier. Either user defined name or index based on the order provided.

  • type type of model (a serosv model class)

  • AIC AIC value for the fitted model (if applicable)

  • BIC AIC value for the fitted model (if applicable)

Sample usage

Compare 4 models defined above

# provide models with name
compare_models(muench_linelist = model1, muench_aggregated = model2, griffith = model3, penalized_spline = model4)
##               model                   type       AIC       BIC
## 1   muench_linelist       polynomial_model 1368.9096 1373.9280
## 2 muench_aggregated       polynomial_model  505.5269  508.8787
## 3          griffith       polynomial_model  489.1185  495.8223
## 4  penalized_spline penalized_spline_model  256.7061  271.3522
# provide models without name
compare_models(model1, model2, model3, model4)
##   model                   type       AIC       BIC
## 1     1       polynomial_model 1368.9096 1373.9280
## 2     2       polynomial_model  505.5269  508.8787
## 3     3       polynomial_model  489.1185  495.8223
## 4     4 penalized_spline_model  256.7061  271.3522
# user can provide arbitrary number of models
compare_models(model3, model4)
##   model                   type      AIC      BIC
## 1     1       polynomial_model 489.1185 495.8223
## 2     2 penalized_spline_model 256.7061 271.3522