Type: | Package |
Title: | 'EMOTIONS: Ensemble Models for Lactation Curves' |
Version: | 1.0 |
Description: | Lactation curve modeling plays a central role in dairy production, supporting management decisions and the selection of animals with superior productivity and resilience. The package 'EMOTIONS' fits 47 models for lactation curves and creates ensemble models using model averaging based on Akaike information criterion, Bayesian information criterion, root mean square percentage error, and mean squared error, variance of the predictions, cosine similarity for each model's predictions, and Bayesian Model Average. The daily production values predicted through the ensemble models can be used to estimate resilience indicators in the package. Additionally, the package allows the graphical visualization of the model ranks and the predicted lactation curves. |
Depends: | R (≥ 4.2) |
Imports: | dplyr, orthopolynom, quantreg, minpack.lm, tidyr, ggplot2, ggridges, parameters, rlang, tidyselect, splines |
License: | GPL-3 |
Encoding: | UTF-8 |
LazyData: | true |
RoxygenNote: | 7.3.2 |
Suggests: | knitr, rmarkdown |
VignetteBuilder: | knitr |
NeedsCompilation: | no |
Packaged: | 2025-06-17 09:59:37 UTC; pablofonseca |
Author: | Pablo Fonseca [aut, cre], Marcos Prates [aut], Aroa Suarez-Vega [aut], Ruth Arribas Gonzalo [aut], Beatriz Gutierrez-Gil [aut], Juan José Arranz [aut] |
Maintainer: | Pablo Fonseca <p.fonseca@csic.es> |
Repository: | CRAN |
Date/Publication: | 2025-06-18 11:50:14 UTC |
Estimate normalized model weights using an Expectation–Maximization (EM) algorithm with a gamma distribution
Description
Estimate normalized model weights using an Expectation–Maximization (EM) algorithm with a gamma distribution
Usage
BMAweight_gamma(converged_models, x, trait)
Arguments
converged_models |
A list containing the fitted models for the individual |
x |
A data frame containing the daily milking records for the individual |
trait |
The name of the column containing daily milking records |
Value
A vector containing the normalized model weights based on the Bayesian Model Averaging (BMA) approach proposed by Duan et al. (2006), adapted to use a gamma distribution
Estimate normalized model weights based on the cosine similarity of each model's predictions
Description
Estimate normalized model weights based on the cosine similarity of each model's predictions
Usage
CosSquaredWeight(converged_models, x)
Arguments
converged_models |
A list containing the fitted models for the individual |
x |
A data frame containing the daily milking records for the individual |
Value
A vector containing the normalized model weights
Estimate the Akaike information criterion (AIC), Bayeasian information criterion (BIC), root mean square percentage error (RMSPE) and mean squared error (MAE) for the fitted models
Description
Estimate the Akaike information criterion (AIC), Bayeasian information criterion (BIC), root mean square percentage error (RMSPE) and mean squared error (MAE) for the fitted models
Usage
GetLacModelsMetrics(converged_models, x, trait)
Arguments
converged_models |
A list containing the fitted models for the individual |
x |
data frame containing the daily milking records for the individual |
trait |
The name of the column containing daily milking records |
Value
A data frame containing the AIC, BIC, RMSPE and MAE for each fitted model for the individual
A wrapper function for the ModelsLac function that fits lactation curve models based on daily production and days in milk records simultaneously for a list of animals
Description
The function uses a data frame containing the daily milking records as input.
Usage
LacCurveFit(
data,
ID,
trait,
dim,
alpha = 0.5,
models = "All",
param_list = NULL,
silent = TRUE
)
Arguments
data |
A data frame containing the daily milking records. |
ID |
The name of the column containing the unique IDs of the individuals. |
trait |
The name of the column containing daily milking records. |
dim |
The name of the column containing days in milk records. |
alpha |
A penalization factor, ranging from 0 to 1, for the estimation of the model's weight. |
models |
A vector describing the models to be included in the analysis. In total, 47 models are included in EMOTIONS. The default option is "All", which results in the inclusion of the 47 models. Alternatively, a vector containing any subset of the following models can be provided: "MMR", "MME", "brody23", "brody24", "SCH", "SCHL", "PBE", "wood", "DHA", "CB", "QP", "CLD", "PapBo1", "PapBo2", "PapBo3", "PapBo4", "PapBo6", "GS1", "GS2", "LQ", "wil", "wilk", "wilycsml", "BC", "DJK", "MG2", "MG4", "MG", "KHN", "AS", "FRP", "PTmult", "PTmod", "MonoG", "MonoGpw", "DiG", "DiGpw", "legpol3", "legpol4", "legpolWil", "cubsplin3", "cubsplin4", "cubsplin5", "cubsplindef", "wilminkPop", "qntReg". |
param_list |
A list composed of the models, named as in the models parameter, and the respective parameters included in the models. |
silent |
A logical value defining whether warnings should be printed during the model fitting. The default value is TRUE (not printing warnings). |
Value
A list containing the fitted models, the model's weights and ranks for each weighting strategy, and the predicted daily production obtained through the model ensemble for each weighting strategy.
A data frame containing the daily milk yield for 100 individuals up to 210 days in milk
Description
A data frame containing the daily milk yield for 100 individuals up to 210 days in milk
Usage
data(LacData)
Format
A data frame with 21,821 rows and 3 variables:
ID: Unique individual code
DIM: Days in milk
DMY: Daily milk yield
Examples
data(LacData)
Create a line plot that shows the range of the ranks obtained for each model across the individuals
Description
Create a line plot that shows the range of the ranks obtained for each model across the individuals
Usage
ModelRankRange(LacCurveFit, metric = "AIC_rank")
Arguments
LacCurveFit |
The object obtained from the LacCurveFit function |
metric |
The name of the metric to be used to plot the model's ranks |
Value
A line plot that shows the range of the ranks obtained for each model across the individuals
Perform model fitting and weight assignment based on different strategies for each individual ID
Description
Perform model fitting and weight assignment based on different strategies for each individual ID
Usage
ModelsLac(
data,
ID_col,
ID,
trait,
dim,
alpha,
models,
param_list = NULL,
silent = silent
)
Arguments
data |
A data frame containing the daily milking records |
ID_col |
The name of the column containing the unique IDs of the individuals |
ID |
The individual ID being analyzed |
trait |
The name of the column containing daily milking records |
dim |
The name of the column containing days in milk (DIM) records |
alpha |
A penalization factor ranging from 0 to 1, used in the estimation of the model weights |
models |
A vector describing the models to be included in the analysis. A total of 47 models are available in EMOTIONS. The default option is "All", which includes all 47 models. Alternatively, a subset of the following models can be provided: "MMR", "MME", "brody23", "brody24", "SCH", "SCHL", "PBE", "wood", "DHA", "CB", "QP", "CLD", "PapBo1", "PapBo2", "PapBo3", "PapBo4", "PapBo6", "GS1", "GS2", "LQ", "wil", "wilk", "wilycsml", "BC", "DJK", "MG2", "MG4", "MG", "KHN", "AS", "FRP", "PTmult", "PTmod", "MonoG", "MonoGpw", "DiG", "DiGpw", "legpol3", "legpol4", "legpolWil", "cubsplin3", "cubsplin4", "cubsplin5", "cubsplindef", "wilminkPop", "qntReg" |
param_list |
A list containing the models (named as in the 'models' parameter) and their respective parameters |
silent |
A logical value indicating whether warnings should be suppressed during model fitting. The default is TRUE (warnings are not printed) |
Value
A list containing the fitted models, model weights and ranks, and the predicted daily production obtained through the model ensemble
Define the parameters for the lactation curve models to be fitted
Description
Define the parameters for the lactation curve models to be fitted
Usage
ParDef(x, trait, dim)
Arguments
x |
A data frame containing the daily milking records for the individual |
trait |
The name of the column containing the daily milking records |
dim |
The name of the column containing the days in milk (DIM) records |
Value
A list containing the parameters to be used in the lactation curve models
Plot the actual and predicted daily milk production obtained by the ensemble model
Description
Plot the actual and predicted daily milk production obtained by the ensemble model
Usage
PlotWeightLac(
data,
ID,
trait,
metric,
dim,
col = c("red", "blue"),
point_size = 2,
line_size = 1,
axis_text_size = 15,
axis_title_size = 15
)
Arguments
data |
The object generated by the LacCurveFit function |
ID |
The ID of the individual whose daily milking records will be plotted |
trait |
The name of the column containing the daily milking records |
metric |
The name of the strategy used to obtain the predicted values through the ensemble model |
dim |
The name of the column containing the days in milk (DIM) records |
col |
A vector defining the colors for the actual and predicted values |
point_size |
Numeric value indicating the size of the observed data points in the plot |
line_size |
Numeric value indicating the thickness of the regression line |
axis_text_size |
Numeric value defining the font size of the axis tick labels |
axis_title_size |
Numeric value defining the font size of the axis titles |
Value
A plot showing the actual and predicted daily milk production across the days in milk
Estimate resilience indicators (log-variance, lag-1 autocorrelation, and skewness) from daily milk production records
Description
Estimate resilience indicators (log-variance, lag-1 autocorrelation, and skewness) from daily milk production records
Usage
ResInd(
production_df,
dim_filter_range = c(1, 7, 203, 210),
outlier_sd_threshold = 4,
weight = "weight_AIC",
trait,
DIM,
ID_col
)
Arguments
production_df |
A list containing data frames with the daily production records (actual or predicted) obtained from the LacCurveFit function |
dim_filter_range |
A numeric vector with the lower and upper limits used to filter out lactation records at the beginning and end of lactation. If no filtering is needed, set the first two values to the minimum days in milk and the last two to the maximum |
outlier_sd_threshold |
A numeric threshold defining the maximum number of standard deviations allowed for resilience indicator values before considering them outliers |
weight |
The name of the column containing the selected ensemble prediction. Default is "weight_AIC" |
trait |
The name of the column containing daily milking records |
DIM |
The name of the column containing days in milk records |
ID_col |
The name of the column containing the unique individual IDs |
Value
A list containing: (1) the daily milk production values after filtering, (2) a list of removed individuals, and (3) a data frame with the resilience indicators
Visualize the distribution of model ranks across individuals using ridge density plots
Description
The 'RidgeModels' function creates ridge density plots to visualize the distribution of model ranks across individuals.
Usage
RidgeModels(LacCurveFit, metric = "AIC_rank")
Arguments
LacCurveFit |
The object returned by the 'LacCurveFit' function |
metric |
The name of the metric used to plot the model ranks |
Value
A ridge density plot showing the distribution of ranks for the models included in the ensemble
Estimate normalized model weights based on the variance of the predictions
Description
This function estimates normalized model weights by evaluating the variance of each model's predictions.
Usage
VarWeight(converged_models, x)
Arguments
converged_models |
A list containing the fitted models for the individual |
x |
A data frame containing the daily milking records for the individual |
Value
A vector containing the normalized weights for each model
A data frame containing the models included in the EMOTIONS package that can have the parameters edited
Description
A data frame containing the models included in the EMOTIONS package that can have the parameters edited
Usage
data(model_pars)
Format
A data frame with 42 rows and 2 variables:
Model_acronym: The acronym of the models that can have the parameters edited
Parameters: The list of parameters included in each model
Examples
data(model_pars)
A data frame containing the daily milk yield for 100 individuals up to 210 days in milk
Description
A data frame containing the daily milk yield for 100 individuals up to 210 days in milk
Usage
data(models_EMOTIONS)
Format
A data frame with 47 rows and 5 variables:
Model: Model description
Model_acronym: Model acronym used in the EMOTIONS functions
Authors: List of authors of each model available in EMOTIONS
Year: Year of publication of each model available in EMOTIONS
Reference: Link to the original publication of each model available in EMOTIONS
Examples
data(models_EMOTIONS)