Skip to content

Commit ad90915

Browse files
authored
Merge pull request #22 from indecis-eu/master
1. Solve a problem with pze (probability of zero precipitation) when using user-provided parameters. 2. Allow time series with frequencies other than 12 (monthly).
2 parents f59bcb6 + 4b9ecd4 commit ad90915

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

R/spei.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ spei <- function(data, scale, kernel=list(type='rectangular',shift=0),
304304
dim_one = ifelse(distribution == "Gamma", 2, 3)
305305

306306
if (!is.null(params)) {
307-
if (dim(params)[1]!=dim_one | dim(params)[2]!=m | dim(params)[3]!=12) {
308-
stop(paste('parameters array should have dimensions (', dim_one, ', ', m, ', 12)',sep=' '))
307+
if (dim(params)[1]!=dim_one | dim(params)[2]!=m | dim(params)[3]!=fr) {
308+
stop(paste('parameters array should have dimensions (', dim_one, ', ', m, ', fr)',sep=' '))
309309
}
310310
}
311311

@@ -344,18 +344,18 @@ spei <- function(data, scale, kernel=list(type='rectangular',shift=0),
344344
next()
345345
}
346346

347+
if(distribution != "log-Logistic"){
348+
pze <- sum(month==0)/length(month)
349+
month = month[month > 0]
350+
}
351+
347352
if (is.null(params)) {
348353
month_sd = sd(month,na.rm=TRUE)
349354
if (is.na(month_sd) || (month_sd == 0)) {
350355
std[f] <- NA
351356
next
352357
}
353358

354-
if(distribution != "log-Logistic"){
355-
pze <- sum(month==0)/length(month)
356-
month = month[month > 0]
357-
}
358-
359359
# Stop early and assign NAs if month's data is length < 4
360360
if(length(month) < 4){
361361
std[ff,s] = NA

0 commit comments

Comments
 (0)