--- title: "Model selection" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Model selection} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r setup, output=FALSE} library(serosv) ``` ```{r, warning=FALSE} 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 ```{r} # provide models with name compare_models(muench_linelist = model1, muench_aggregated = model2, griffith = model3, penalized_spline = model4) # provide models without name compare_models(model1, model2, model3, model4) # user can provide arbitrary number of models compare_models(model3, model4) ```