-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path01.prep.R
64 lines (54 loc) · 2.09 KB
/
01.prep.R
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
###############################################################################
# Updated version of the code for the analysis in:
#
# "Reducing and meta-analyzing estimates from distributed lag non-linear models"
# Gasparrini and Armstrong
# BMC Medical Research Methodology - 2013
# http://www.ag-myresearch.com/2013_gasparrini_bmcmrm.html
#
# Update: 05 December 2017
# * an updated version of this code, compatible with future versions of the
# software, is available at:
# http://www.ag-myresearch.com/2013_gasparrini_bmcmrm.html
###############################################################################
###############################################################################
# CREATE 3 OBJECTS:
#
# 1) A VECTOR WITH NAMES OF REGIONS OF ENGLAND AND WALES
#
# 2) A LIST WITH THE DATA FOR EACH REGION, INCLUDING:
# - DATE, YEAR, MONTH, DAY, TIME, DAY OF THE YEAR, DAY OF THE WEEK
# - REGION NUMBERS AND NAMES
# - MEAN, MINIMUM AND MAXIMUM TEMPERATURE
# - DEW-POINT TEMPERATURE AND RELATIVE HUMIDITY
# - MORTALITY (ALL-CAUSE)
#
# 3) A FUNCTION TO COMPUTE THE Q-AIC
#
###############################################################################
# LOAD PACKAGES (ASSUMED ALREADY INSTALLED)
library(dlnm) ; library(mvmeta) ; library(splines)
# CHECK VERSION OF THE PACKAGE
if(packageVersion("dlnm")<"2.2.0")
stop("update dlnm package to version >= 2.2.0")
# LOAD THE DATASET
regEngWales <- read.csv("regEngWales.csv",row.names=1)
dim(regEngWales)
head(regEngWales)
# REGIONS
regions <- as.character(unique(regEngWales$regnames))
# CREATE A LIST WITH THE REGIONAL SERIES
data <- lapply(regions,function(x) regEngWales[regEngWales$regnames==x,])
names(data) <- regions
m <- length(regions)
# TEMPERATURE RANGES
ranges <- t(sapply(data, function(x) range(x$tmean,na.rm=T)))
####################################################################
# FUNCTION TO COMPUTE THE Q-AIC IN QUASI-POISSON MODELS
fqaic <- function(model) {
loglik <- sum(dpois(model$y,model$fitted.values,log=TRUE))
phi <- summary(model)$dispersion
qaic <- -2*loglik + 2*summary(model)$df[3]*phi
return(qaic)
}
#