Closed gdickens closed 1 month ago
In case it helps: what I've been trying to do is use COINr to normalize a set of indicators based on their distance to a pre-defined frontier based on performance. The formula I previously used is similar to the min / max approach except that the bounds aren't set by the indicator being normalized, but are externally set based on global data and/or research -
This means that I'm expecting each indicator would be normalized by its own goalpost (like the example). The normalized value of an indicator would also not necessarily span from 0 to 100 (or from 1 to 9 in my particular case).
The formula used by n_goalposts looked to be the appropriate way of achieving this in COINr, but I have had trouble using it on a panel dataset stored as a purse.
I've spent quite a lot of time testing different approaches with the help of ChatGPT / COINr's documentation, but apologies if I'm missing something obvious here.
Hi, this might be because your COINr version is not new enough for this feature. The COINr version on CRAN is a bit out of date and I will submit the latest version to CRAN soon, but in the meantime try installing the dev version:
# Install development version from GitHub
devtools::install_github("bluefoxr/COINr")
Let me know if this works.
Hey bluefoxr,
I did try this, albeit after an embarrassing amount of time using the CRAN version, but it didn't fix the problem.
To double check this I just removed the COINr package and reinstalled it via the command above and I'm receiving the same error(s) when running the code above.
Hi @gdickens I had a closer look at this. The problem is that when you set global = TRUE
, the purse method first extracts the data from all coins in the purse and glues it together, then passes the data frame to the data frame method of Normalise()
. But the code that deals with iMeta parameters is contained within the coin method, which is bypassed in this case.
Ideally I would add the iMeta feature to the purse method as well but I'm not sure when I would be able to get around to that. So some workarounds that come to mind are:
global = FALSE
, although not sure if that will produce what you want. Although probably in your case it might, since you don't need to calculate global min or max from the data?Does that help a bit?
Hey @bluefoxr
I gave this a try today and setting global=FALSE
worked. Apologies for not trying this earlier, my reading of the documentation led me to believe this wasn't likely to be the cause.
I didn't try the custom operation option, but that looks really useful, so thanks for flagging it as I'm sure to need it in the future. But, I did have to write my own function so I could pass it to Aggregate() via the f_ag
argument:
a_gmean_custom<-function(x, w)
{
gm <- (10-exp(mean(log(((10-x)/10*9+1)), na.rm = TRUE)))/9*10
gm
}
Worked like a charm, so thanks for making the package so flexible!
Thanks again for all your work on developing and maintaining the package. It's been super useful for my work.
(The geometric mean formula is based on EUROPA's approach for calculating the geometric mean when indicators might have a value of 0 (from their INFORM Risk Index). )
Ok glad that works. I'll close the issue now.
I've been trying to normalize a purse using the 'n_goalposts' method, however, the function doesn't appear to allow the use of goalposts from the iMeta data i.e. specifying 'use_iMeta' in the f_n_para argument.
What I've been trying to do is to apply a set of goalposts defined in the iMeta information of a purse, but no matter how I specify the argument R returns an error, such as 'argument "gposts" is missing, with no default' or 'f_n_para must be a list'.
The 'f_n_para must be a list' seems to be an error on my side based on having incorrectly formatted the function argument, but the gposts error suggests that the "use_iMeta" argument isn't working for the goalposts function.
Please see below for a reproducible example: