Skip to content

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

@heroldn

Description

@heroldn

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))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions