Learn R Programming

RMRAINGEN (version 1.0)

fitdistrForPrecipitation: This function calculates the parameters of a parametric probability distribution by fitting daily precipitation data for each station and each month. It is a wrapper function for fitdistr

Description

This function calculates the parameters of a parametric probability distribution by fitting daily precipitation data for each station and each month. It is a wrapper function for fitdistr

Usage

fitdistrForPrecipitation(data, dname = "exp", start = NULL, sample = "all", origin = "1961-1-1", valmin = 0.5, ...)

Arguments

data
dataset
dname
name of the pobability distribution to be fitted, e.g. "exp".
start
initialization configuration of probability distribution parameters for fitdistr.
sample
character string indicated if the parameters must be estimated differently for subset of the year, e.g. monthly. Admitted values are NULL (Default), "all" or "monthly".
origin
character string containing the date releted to the first row of data. Default is "1961-1-1".
valmin
threshold precipitation value [mm] for wet/dry day indicator. If precipitation is lower than valmin, day is considered dry. Default is 0.5 mm. See continuity_ratio,CCGamma.
...
further arguments for fitdistr

Value

a list containig the fitting parameters: S3 fitdistrForEachStation-class or fitdistrForEachStationForEachMonth-class (sample=="monthly") object

See Also

fitdistr,adddate

Examples

Run this code
library(RMRAINGEN)


data(trentino)

year_min <- 1961
year_max <- 1990

period <- PRECIPITATION$year>=year_min & PRECIPITATION$year<=year_max
station <- names(PRECIPITATION)[!(names(PRECIPITATION) %in% c("day","month","year"))]
prec_mes <- PRECIPITATION[period,station]

## removing nonworking stations (e.g. time series with NA)
accepted <- array(TRUE,length(names(prec_mes)))
names(accepted) <- names(prec_mes)
for (it in names(prec_mes)) {
		 accepted[it]  <- (length(which(!is.na(prec_mes[,it])))==length(prec_mes[,it]))
}

prec_mes <- prec_mes[,accepted]
## the dateset is reduced!!!
prec_mes <- prec_mes[,1:3]

fit  <- fitdistrForPrecipitation(data=prec_mes,dname="exp",start=NULL,sample=NULL)

origin <- paste(year_min,1,1,sep="-")


fit_monthly  <- fitdistrForPrecipitation(data=prec_mes,dname="exp",
					start=NULL,sample="monthly",origin=origin)
fit_monthly_gamma  <- fitdistrForPrecipitation(data=prec_mes,dname="gamma",
						 start=NULL,sample="monthly",origin=origin)

Run the code above in your browser using DataLab