bluefoxr / COINr

COINr
https://bluefoxr.github.io/COINr/
Other
25 stars 8 forks source link

Error while treating outliers #45

Closed MoujibChahid closed 1 year ago

MoujibChahid commented 1 year ago

A repetitive error is displayed when processing outliers. This occurs with both the "Treat" and "qTreat" functions.

The error message is as follows: Error in while ((!passing | force_win) & below_winmax) { : missing value where TRUE/FALSE needed

I've tried to follow the documentation but the problem persists.

Please remedy the situation.

bluefoxr commented 1 year ago

Hi, please provide a reproducible example (the coin as Rdata or RDA file, plus exact command you are running) and I'll take a look.

MoujibChahid commented 1 year ago

CompleteIndex2015.xlsx Index2015.zip

Enclosed are the requested documents describing the problem encountered. I have tried the following functions:

library(readxl) iData <- read_excel("/Users/moujib0/Desktop/Index2015/CompleteIndex2015.xlsx", sheet = "iData")

iMeta <- read_excel("/Users/moujib0/Desktop/Index2015/CompleteIndex2015.xlsx", sheet = "iMeta")

library(COINr) coin <- new_coin(iData, iMeta, level_names = c("Indicator", "Pillar", "Index")) iData checked and OK. iMeta checked and OK. Written data set to .$Data$Raw global_specs = list(f1 = "winsorise",

  • f1_para = list(na.rm = TRUE,
  • winmax = 5,
  • skew_thresh = 2,
  • kurt_thresh = 3.5,
  • force_win = FALSE),
  • f2 = "log_CT",
  • f2_para = list(na.rm = TRUE),
  • f_pass = "check_SkewKurt",
  • f_pass_para = list(na.rm = TRUE,
  • skew_thresh = 2,
  • kurt_thresh = 3.5)) coin <- qTreat(coin, dset = "Raw", winmax = 5) Error in while ((!passing | force_win) & below_winmax) { : missing value where TRUE/FALSE needed coin <- Treat(coin, dset = "Raw") print(coin) A Workbook object.

Worksheets: Sheet 1: "Meta.Ind"

Sheet 2: "Meta.Lineage"

Sheet 3: "Meta.Weights.Original"

Sheet 4: "Meta.Unit"

Sheet 5: "Data.Raw"

Worksheet write order: 1, 2, 3, 4, 5 Active Sheet 1: "Meta.Ind" Position: 1

Warning messages: 1: In class(object) <- "environment" : Setting class(x) to "environment" sets attribute to NULL; result will no longer be an S4 object 2: In class(object) <- "environment" : Setting class(x) to "environment" sets attribute to NULL; result will no longer be an S4 object

check_SkewKurt(coin, na.rm = FALSE, skew_thresh = 2, kurt_thresh = 3.5) Error in skew(x, na.rm = na.rm) : is.numeric(x) is not TRUE global_specs = list(f1 = "winsorise",

  • f1_para = list(na.rm = TRUE,
  • winmax = 5,
  • skew_thresh = 2,
  • kurt_thresh = 3.5,
  • force_win = FALSE),
  • f2 = "log_CT",
  • f2_para = list(na.rm = TRUE),
  • f_pass = "check_SkewKurt",
  • f_pass_para = list(na.rm = TRUE,
  • skew_thresh = 2,
  • kurt_thresh = 3.5)) check_SkewKurt(coin, na.rm = FALSE, skew_thresh = 2, kurt_thresh = 3.5) Error in skew(x, na.rm = na.rm) : is.numeric(x) is not TRUE
bluefoxr commented 1 year ago

coin <- qTreat(coin, dset = "Raw", winmax = 5)

I ran this and everything works - not sure what the problem is? There is a warning:

Warning message: Indicator could not be treated at column 'SI.INSUL.05' - returning untreated indicator. May be due to lack of unique values.

But this is fine, it is just telling you you cannot treat one indicator.

Please try:

  1. Installing latest COINr version in case you don't have it:
devtools::install_github("bluefoxr/COINr")
  1. Clearing your environment - from the messages you are getting above it looks like you have somehow converted the coin to a workbook?
MoujibChahid commented 1 year ago

It's perfect. The update you've just made to COINr has solved the problem. Thank you for your exceptional responsiveness. I believe that these exchanges allow us to develop this powerful tool and remedy certain problems that may arise. If you could just publish a sample script tracing all the construction steps (with codes), that would be just great.

bluefoxr commented 1 year ago

The update that fixed that problem was made some months ago but not yet pushed to CRAN.

For a full example, just follow the commands in build_example_coin() (ignore the if statements etc). https://github.com/bluefoxr/COINr/blob/a70bc83889d7fcafd000f8c4020110db4105bae5/R/examples.R#L42