## 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"))
Run the code above in your browser using DataLab