Search code examples
rweightedaucmse

How can I calculated summary stats based on weighted data in R? (AUC, MSE, MAE, R2, etc.)


I'm creating a Shiny dashboard app. One of the features on this app is a stat table that shows the MSE, MAE and either AUC or R2 depending on which is relevant.

These stats are currently just based on the data, treating each row equally. However, the data contains a weighting column. Some have a weight of 1, but most have a weight of a messy number (i.e. 3.4241). I'm unsure how to approach allowing for this functionality.

I'm using the functions mse, mae and auc from the ModelMetrics package. They take a vector of actual values and a vector of predicted values. There doesn't appear to be any option for accounting for weighting.

Does anyone have any ideas? I'm guessing I will need to make my own version of the functions, but I'm unsure how to go about doing this.


Solution

  • After posting this, I eventually came across the package "MetricsWeighted" that has weighted functions for each of these stats. It seems to be working as expected.