-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwreg.R
57 lines (48 loc) · 1.16 KB
/
wreg.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
WFluSurv = function(dframe, cold, first=firstflu, last=lastflu)
{
curr = merge(dframe, surv)
curr$Bp = ifelse(curr$fluyear>=first, curr$Bp, NA)
curr$Bp= ifelse(curr$fluyear<=last, curr$Bp, NA)
model = lm(deaths~H1p+H3p+Bp+cold, data=curr)
plot(model)
list(model=model, fluyear=curr$fluyear[!is.na(curr$Bp)],
den=curr$den[!is.na(curr$Bp)])
}
lineprint = function(mod, vnames)
{
sum = summary(mod$model)
fs = as.list(sum$fs)
PF = 1-pf(fs$value, fs$numdf, fs$dendf)
P = sum$coef[vnames,4]
pred = confpredict(mod)$pred
f = (data.frame(
mean = pred[c(vnames, "Total")],
P = c(sum$coef[vnames,4], PF)
))
rownames(f) = c(names(vnames), "Total")
f
}
wcausemod = function(name, death, cold, first=0)
{
sapply(death[[name]], WFluSurv, simplify=FALSE, cold=cold, first=first)
}
confprint = function(mod, vnames)
{
sum = summary(mod$model)
fs = as.list(sum$fs)
PF = 1-pf(fs$value, fs$numdf, fs$dendf)
P = sum$coef[vnames,4]
pred = confpredict(mod)
f = (data.frame(
mean = pred[c(vnames, "Total"), ],
P = c(sum$coef[vnames,4], PF)
))
rownames(f) = c(names(vnames), "Total")
f
}
vnames = c(
H3N2 = "H3p",
H1N1 = "H1p",
B = "Bp",
Cold = "cold"
)