Skip to content

Commit

Permalink
fix spi negative value error
Browse files Browse the repository at this point in the history
  • Loading branch information
kongdd committed Jan 22, 2024
1 parent 4f4e24f commit cc30371
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions R/cal_spei.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ cal_spei <- function(x, distribution = "log-Logistic", fit = "ub-pwm", ...) {

x.mon <- x[!is.na(x)]
if (distribution != "log-Logistic") {
pze <- sum(x.mon == 0) / length(x.mon)
pze <- sum(x.mon <= 0) / length(x.mon)
x.mon <- x.mon[x.mon > 0]
}

Expand Down Expand Up @@ -91,8 +91,9 @@ cal_spei <- function(x, distribution = "log-Logistic", fit = "ub-pwm", ...) {
z <- qnorm(cdf_res)

# Adjust for `pze` if distribution is Gamma or PearsonIII
if (distribution == "Gamma" | distribution == "PearsonIII") {
z <- qnorm(pze + (1 - pze) * pnorm(z))
if (distribution == "Gamma" | distribution == "PearsonIII") {
z <- qnorm(pze + (1 - pze) * cdf_res)
z[x <= 0] <- -Inf
}

list(z = z, coef = f_params)
Expand Down

0 comments on commit cc30371

Please sign in to comment.