gof.date: Goodness-of-fit for the distribution of dates

View source: R/gof.date.R

gof.dateR Documentation

Goodness-of-fit for the distribution of dates

Description

Goodness-of-fit diagnostics for the distribution of event dates in a (assumed) Poisson process

Usage

    gof.date(date,
             start = NULL,
             end = NULL,
             plot = TRUE,
             main = NULL,
             skip = NULL,
             plot.type = "skip")

Arguments

date

Object of class POSIXct (or that can be coerced to this class) giving the dates to be tested. Must be in strictly increasing order.

start

The beginning of the interval, a POSIXct object. If NULL, the first event in date is used.

end

Object of class POSIXct the end of the interval. If NULL, the last event in date is used.

plot

Should a plot be shown?

main

Character giving the main title of the plot. The default NULL stands for a default main describing the period.

skip

Optional data.frame with columns start and end indicating start and end of skipped periods. The two columns need to be coerced to POSIXct objects. They can be POSIXct or character with POSIX datetime format.

plot.type

Character indicating the type of plot to produce when a skip data.frame is given. With plot.type = "skip" the plot shows missing periods as greyed rectangles and the displays the results of a Kolmogorov-Smirnov (KS) test performed on the events. For the "omit" case the missing periods are collapsed into vertical lines on the plot and the displayed results are for an "effective" KS test of uniformity performed omitting the missing periods.

Details

In the homogeneous Poisson process, events occur on a time interval in a uniform fashion. More precisely, for a given time interval the distribution of the event dates conditional to their number n is the distribution of the order statistics of a sample of size n of the uniform distribution on this interval.

When the interval has limits taken at events the uniformity statement remains true, but for inner events. This behaviour is met when start and end are not given and taken as the first and last events in date.

Value

A list

effKS.statistic, KS.statistic

Kolmogorov-Smirnov global test statistic for uniformity (bilateral test) omitting slipped periods or not.

effKS.pvalue, KS.pavalue

Critical probability in the KS test omitting skipped periods or not.

effnevt, nevt

Number of events omitting skipped periods or not.

effduration, duration

Effective duration i.e. total duration of non-skipped periods. In years, omitting skipped periods or not.

effrate, rate

Occurrence rate in number of events by year, omitting skipped periods or not.

effduration, duation

Total duration in years, omitting missing periods or not.

noskip

Data.frame object giving indications on the periods that are NOT skipped over (hence usually non-missing periods). These are : start, end (POSIX), duration (in years) rate (in number of events by year) and Kolmogorov test statistic and p-value. This data.frame is only available when a suitable skip has been given.

When the number of events corresponding to the indications of args is 0, the function returns NULL with a warning. When the number of events is less than 6 a warning is shown.

Warning

When skipped periods exist the number of events, duration, rate the global KS test must be computed by omitting the skipped periods in the duration and retaining only valid interevents. The indication given in nevt rate and duration should be used only when no skipped period exist (skip = NULL on input) and replaced by effnevt, effrate and effduration otherwise.

Note

In practical contexts missing periods are often met in the datasets. The diagnostic should therefore be applied on every period with no missing data. Even if the event dates seem reasonably uniform, it is a good idea to check that the rates do not differ significantly over intervals.

When some events are missing and no suitable information is given via the skip argument, the global rate, KS.statistic and KS.pvalue are of little interest. Yet the graph might be instructive.

Author(s)

Yves Deville

See Also

interevt function for the determination of interevents ans subsequent diagnostics.

Examples

## Use "Brest" dataset
## simple plot. Kolmogorov-Smirnov is not useful
gof1 <- gof.date(date = Brest$OTdata$date)

## consider missing periods. Much better!
gof2 <- gof.date(date = Brest$OTdata$date,
         skip = Brest$OTmissing,
         start = Brest$OTinfo$start,
         end = Brest$OTinfo$end)

print(gof2$noskip)

## Second type of graph
gof3 <- gof.date(date = Brest$OTdata$date,
         skip = Brest$OTmissing,
         start = Brest$OTinfo$start,
         end = Brest$OTinfo$end,
         plot.type = "omit")

## non-skipped periods at Brest
ns <- skip2noskip(skip = Brest$OTmissing,
                 start = Brest$OTinfo$start,
                 end = Brest$OTinfo$end)

## say 9 plots/diagnostics
oldpar <- par(mar = c(3, 4, 3, 2), mfcol = c(3, 3))

for (i in 1:9) {
  GOF <- gof.date(date = Brest$OTdata$date,
           start = ns$start[i],
           end = ns$end[i])
}

par(oldpar)


Renext documentation built on Aug. 30, 2023, 1:06 a.m.