PrecipitationOccurrenceModel
model objectR/predict.PrecipitationOccurenceModel.R
, R/predict.zPrecipitationAmountModel.R
predict.Rd
It is a wrapper of predict.glm
method for the a PrecipitationOccurrenceModel
model object S3 class.
# S3 method for class 'PrecipitationOccurrenceModel'
predict(
object,
newdata = NULL,
type = "response",
previous = NULL,
endogenous = NULL,
...
)
# S3 method for class 'PrecipitationOccurrenceMultiSiteModel'
predict(object, ...)
# S3 method for class 'PrecipitationAmountModel'
predict(
object,
newdata = NULL,
origin_newdata = NA,
precipitation.value.random.generation = FALSE,
...
)
model returned by PrecipitationOccurrenceModel
predictor or exogenous variables
see predict.glm
. Default is "response"
. See predict.glm
.
logical vector containing previously occurred states.
String vector containing the name of the endogenous variables.
It is used if the endogenous variables are more than one, otherwise is set NULL
(Default).
further arguments
character string containing the date corresponding the first row of newdata
logical value.
If it is FALSE
(Default) the method predict.PrecipitationAmountModel
returns conditioned random values,
otherwise these values are converted to precipitation values through their observed non-parametric distributions.
A vector or a data frame reporting predicted time series for each station.
library(RGENERATEPREC)
data(trentino)
year_min <- 1961
year_max <- 1990
period <- PRECIPITATION$year>=year_min & PRECIPITATION$year<=year_max
period_temp <- TEMPERATURE_MAX$year>=year_min & TEMPERATURE_MAX$year<=year_max
prec_mes <- PRECIPITATION[period,]
Tx_mes <- TEMPERATURE_MAX[period_temp,]
Tn_mes <- TEMPERATURE_MIN[period_temp,]
accepted <- array(TRUE,length(names(prec_mes)))
names(accepted) <- names(prec_mes)
for (it in names(prec_mes)) {
acc <- TRUE
acc <- (length(which(!is.na(Tx_mes[,it])))==length(Tx_mes[,it]))
acc <- (length(which(!is.na(Tn_mes[,it])))==length(Tn_mes[,it])) & acc
accepted[it] <- (length(which(!is.na(prec_mes[,it])))==length(prec_mes[,it])) & acc
}
valmin <- 1.0
prec_mes <- prec_mes[,accepted]
Tx_mes <- Tx_mes[,accepted]
Tn_mes <- Tn_mes[,accepted]
origin <- paste(year_min,1,1,sep="-")
prec_occurrence_mes <- prec_mes>=valmin
station <- names(prec_mes)[!(names(prec_mes) %in% c("day","month","year"))]
it <- station[2]
vect <- Tx_mes[,it]-Tn_mes[,it]
months <- factor(prec_mes$month)
model <- PrecipitationOccurrenceModel(x=prec_mes[,it],exogen=vect,monthly.factor=months)
probs <- predict(model)
nday <- 3.0
vect_new <- array(1.0,nday)
months_new <- array(1,nday)
row_test <- 2000:2007
newdata <- model$predictor[row_test,]
probs2 <- predict(model,newdata=newdata)
probs[row_test]==probs2
#> 2000 2001 2002 2003 2004 2005 2006 2007
#> TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
###
prec_occurrence_mes <- prec_mes>=valmin
station <- names(prec_mes)[!(names(prec_mes) %in% c("day","month","year"))]
station <- station[1:4] ## reduced the dataset!!!
Tx_mes <- Tx_mes[,station]
Tn_mes <- Tn_mes[,station]
prec_mes <- prec_mes[,station]
exogen <- Tx_mes-Tn_mes
months <- factor(prec_mes$month)
# \donttest{
### Not Run
### Please uncomment the following lines to run them
model_multisite <- PrecipitationOccurrenceMultiSiteModel(x=prec_mes,
exogen=exogen,origin=origin,multisite_type="wilks")
#> lag
#> 0
#> Hmm... p0 - first argument - must be a matrix of probabilities!!!
#> lag
#> 0
#> Hmm... p0 - first argument - must be a matrix of probabilities!!!
#> lag
#> 0
#> Hmm... p0 - first argument - must be a matrix of probabilities!!!
#> lag
#> 0
#> Hmm... p0 - first argument - must be a matrix of probabilities!!!
#> lag
#> 0
#> Hmm... p0 - first argument - must be a matrix of probabilities!!!
#> lag
#> 0
#> Hmm... p0 - first argument - must be a matrix of probabilities!!!
#> lag
#> 0
#> Hmm... p0 - first argument - must be a matrix of probabilities!!!
#> lag
#> 0
#> Hmm... p0 - first argument - must be a matrix of probabilities!!!
#> lag
#> 0
#> Hmm... p0 - first argument - must be a matrix of probabilities!!!
#> lag
#> 0
#> Hmm... p0 - first argument - must be a matrix of probabilities!!!
#> lag
#> 0
#> Hmm... p0 - first argument - must be a matrix of probabilities!!!
#> lag
#> 0
#> Hmm... p0 - first argument - must be a matrix of probabilities!!!
model_multisite_logit <- PrecipitationOccurrenceMultiSiteModel(x=prec_mes,
exogen=exogen,origin=origin,multisite_type="logit")
probs_multimodel <- predict(model_multisite_logit)
# }