EIglm: Perform a GLM on times of events

Description Usage Arguments Details Value Author(s) References Examples

Description

Perform a GLM with the intervals between events as the response and the times of the events as a predictor.

Usage

1
 EIglm(event_times,event_vars=list(),formula=NULL)

Arguments

event_times

A numeric vector of times of occurrence of events.

event_vars

Optional predictors to include in the GLM.

formula

A optional string that can be coerced to a valid formula.

Details

EIglm calculates the intervals between the times passed in event_times and calls glm with family="Gamma". If the times are not in increasing order, they will be sorted. If there are any zero length intervals, the events that occur in the same time increment are spread out over that time increment.

If more predictors are passed in event_vars these will be added to the formula passed to glm. When passing predictors based on the events, remember to discard the first value as the intervals are calculated between events. This means that the interval is unknown for the first event.

EIglm only tests the effects of the variables specified and does not test interactions. If a more complex model is to be tested, the user must directly call glm and compose a formula for the model (see the last example). Note that because there is no data argument in EIglm, each term in the model must be specified explicitly.

Value

An object of class glm.

Author(s)

Jim Lemon

References

Blake, E.S., Rappaport, E.N. & Landsea, C.W. (2007) The deadliest, costliest, and most intense United States tropical cyclones from 1851 to 2006 (and other frequently requested hurricane facts). NOAA Technical Memorandum NWS TPC-5, Miami: National Weather Service.

Florida Climate Center (2013) Florida statewide averaged temperature data (in degrees Fahrenheit). URL: http://climatecenter.fsu.edu/products-services/data/statewide-averages/temperature accessed 28/5/2013

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
 ## Not run: 
  # Florida hurricane analysis (20th century)
  data(florida_hurr20)
  oldloc<-Sys.setlocale("LC_TIME", "C")
  fh_dates<-
   as.Date(paste(florida_hurr20$day,florida_hurr20$month,
   florida_hurr20$year,sep="-"),"%d-%B-%Y")
  fh_days<-as.numeric(fh_dates)
  fh_ints<-diff(fh_days)
  fh_counts<-tabulate(florida_hurr20$year[-1]-1899,nbins=100)
  # run a Poisson analysis on the counts
  print(summary(glm(fh_counts~I(1900:1999),family="poisson")))
  EIglm(fh_days)
  data(florida_temp20)
  plot(florida_temp20$year,florida_temp20$Annual,type="b",
    main="Average temperature in Florida",xlab="Year",ylab="degrees F")
  lines(supsmu(florida_temp20$year,florida_temp20$Annual),lwd=2)
  # define a function to match values
  findval<-
   function(x,set) return(which(set %in% x))
  ftemp_years<-florida_temp20$Annual[unlist(sapply(florida_hurr20$year,
   FUN=findval,florida_temp20$year))]
  EIglm(fh_days,list(ft=ftemp_years[-1]))
  Sys.setlocale("LC_TIME", oldloc)
 
## End(Not run)
 # manually performing an event interval GLM
 # get the Florida hurricane data
 data(florida_hurr20)
 # create date values for the events
 florida_hurr20$date<-
  as.Date(paste(florida_hurr20$day,florida_hurr20$month,
  florida_hurr20$year,sep="-"),"%d-%B-%Y")
 # convert the dates to numeric values (offsets from 1/1/1970)
 florida_hurr20$days<-as.numeric(florida_hurr20$date)
 # calculate the intervals, adding NA for the first unknown value
 florida_hurr20$ints<-c(NA,diff(florida_hurr20$days))
 # first test the default model in EIglm, dropping the first event
 summary(glm(ints~days,florida_hurr20[-1,],family="Gamma"))
 # test a model predicting intervals with times of occurrence,
 # the intensities of the hurricanes and their interaction,
 # again dropping the first event
 summary(glm(ints~days*category,florida_hurr20[-1,],family="Gamma"))

Example output

Call:
glm(formula = fh_counts ~ I(1900:1999), family = "poisson")

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-1.2845  -1.1126  -1.0101   0.4797   2.2313  

Coefficients:
              Estimate Std. Error z value Pr(>|z|)
(Intercept)  10.010385   8.484027   1.180    0.238
I(1900:1999) -0.005370   0.004361  -1.231    0.218

(Dispersion parameter for poisson family taken to be 1)

    Null deviance: 115.72  on 99  degrees of freedom
Residual deviance: 114.19  on 98  degrees of freedom
AIC: 217.76

Number of Fisher Scoring iterations: 5


formula: event_ints~event_times
Call:
glm(formula = formula, family = "Gamma")

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-2.3674  -1.4350  -0.2800   0.5792   1.2497  

Coefficients:
              Estimate Std. Error t value Pr(>|t|)    
(Intercept)  1.544e-03  1.977e-04   7.810 8.46e-11 ***
event_times -4.504e-08  1.798e-08  -2.505   0.0149 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for Gamma family taken to be 0.7422684)

    Null deviance: 87.814  on 63  degrees of freedom
Residual deviance: 83.429  on 62  degrees of freedom
AIC: 937.51

Number of Fisher Scoring iterations: 6


formula: event_ints~event_times+event_vars$ft
Call:
glm(formula = formula, family = "Gamma")

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-2.3824  -1.4196  -0.2258   0.6235   1.2417  

Coefficients:
                Estimate Std. Error t value Pr(>|t|)  
(Intercept)   -8.331e-03  1.611e-02  -0.517   0.6069  
event_times   -4.744e-08  1.869e-08  -2.539   0.0137 *
event_vars$ft  1.394e-04  2.276e-04   0.612   0.5425  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for Gamma family taken to be 0.7523581)

    Null deviance: 87.814  on 63  degrees of freedom
Residual deviance: 83.147  on 61  degrees of freedom
AIC: 939.25

Number of Fisher Scoring iterations: 6

[1] "C"

Call:
glm(formula = ints ~ days, family = "Gamma", data = florida_hurr20[-1, 
    ])

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-2.3674  -1.4350  -0.2800   0.5792   1.2497  

Coefficients:
              Estimate Std. Error t value Pr(>|t|)    
(Intercept)  1.544e-03  1.977e-04   7.810 8.46e-11 ***
days        -4.504e-08  1.798e-08  -2.505   0.0149 *  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for Gamma family taken to be 0.7422684)

    Null deviance: 87.814  on 63  degrees of freedom
Residual deviance: 83.429  on 62  degrees of freedom
AIC: 937.51

Number of Fisher Scoring iterations: 6


Call:
glm(formula = ints ~ days * category, family = "Gamma", data = florida_hurr20[-1, 
    ])

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-2.3537  -1.4185  -0.2857   0.5588   1.3339  

Coefficients:
                Estimate Std. Error t value Pr(>|t|)    
(Intercept)    1.823e-03  4.326e-04   4.213 8.58e-05 ***
days          -9.674e-09  3.659e-08  -0.264    0.792    
category      -1.079e-04  1.478e-04  -0.730    0.468    
days:category -1.556e-08  1.407e-08  -1.106    0.273    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for Gamma family taken to be 0.7542537)

    Null deviance: 87.814  on 63  degrees of freedom
Residual deviance: 82.243  on 60  degrees of freedom
AIC: 940.42

Number of Fisher Scoring iterations: 6

eventInterval documentation built on May 1, 2019, 9:22 p.m.