Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inbase calculations occur for insufficient data in percent.days.op.threshold #23

Open
heroldn opened this issue Oct 28, 2020 · 0 comments

Comments

@heroldn
Copy link

heroldn commented Oct 28, 2020

Hi guys, when there is insufficient base period data (as determined by min.base.data.fraction.present when creating the climdex object) no values should be returned for any month/year of a percentile index. However, I find in such cases that months/years inside the base period that do have data still get values reported back. Specifically by the function percent.days.op.threshold.
e.g. I'm calculating tx90p and base period is 1971-1990 but only 1971 has data and I set min.base.data.fraction.present=0.5, so I expect no calculations to be made for any year. But I'm finding I'll still get a non-NA value for 1971 (a zero). So the treatment of the mask inside the base period isn't quite right. Basically what I think is happening is that sum(c(NA,NA),na.rm=TRUE) equals zero when we want it to equal NA in the case where ALL values are NA.

The following replacement in percent.days.op.threshold seems to fix it.
dat[inset] <- rowSums(f.result, na.rm=TRUE) / (byrs - 1)

replaced by

dat[inset] <- apply(f.result,1,function(x) if (all(is.na(x))) x[NA_integer_] else sum(x, na.rm = TRUE) / (byrs - 1))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant