-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1biting_getHrlyEsts_table2.r
104 lines (55 loc) · 2.57 KB
/
1biting_getHrlyEsts_table2.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
rm(list=ls())
require(haven)
require(lme4)
require(dplyr)
# set working directory
#setwd("..")
# estimate biting rates
biting <- read_dta("1biting_data.dta")
# Run biting rate estimates in glmm in R with crossed random effects for household and day
getEstPerHr <- function(dataX, nmosq) {
resultStore <- array(-9, dim=c(n_hours,n_cols))
for (i in 1:n_hours) {
print(i)
m1 <- glmer( nmosq ~ relevel(as.factor(formrow), ref=i) + (1 | houseid) + ( 1 | day), data=dataX, family="poisson", control = glmerControl(optimizer="bobyqa") )
out1 <- summary(m1)$coeff
logm <- out1[1,1]
logse <- out1[1,2]
meanb <- exp(logm)
lb <- exp( logm - 1.96*logse)
ub <- exp( logm + 1.96*logse)
resultStore[i,]<-c(logm, logse, meanb, lb, ub)
}
return(resultStore)
}
n_hours = 12
n_cols = 5
# datasets for indoors and outdoors
temp_in <- biting[biting$location_code==1,]
temp_out <- biting[biting$location_code==0,]
# get estimates
ang_out <- getEstPerHr(temp_out, temp_out$Angambiae)
ang_in <- getEstPerHr(temp_in, temp_in$Angambiae)
anf_out <- getEstPerHr(temp_out, temp_out$Anfunestus)
anf_in <- getEstPerHr(temp_in, temp_in$Anfunestus)
tot_out <- getEstPerHr(temp_out, temp_out$total)
tot_in <- getEstPerHr(temp_in, temp_in$total)
# combine results into a dataset
results_all <- cbind( ang_out, ang_in, anf_out, anf_in, tot_out, tot_in )
colnames(results_all) <- c("ang_out_logm", "ang_out_logse", "ang_out_mean", "ang_out_lb", "ang_out_ub",
"ang_in_logm", "ang_in_logse", "ang_in_mean", "ang_in_lb", "ang_in_ub",
"anf_out_logm", "anf_out_logse", "anf_out_mean", "anf_out_lb", "anf_out_ub",
"anf_in_logm", "anf_in_logse", "anf_in_mean", "anf_in_lb", "anf_in_ub",
"tot_out_logm", "tot_out_logse", "tot_out_mean", "tot_out_lb", "tot_out_ub",
"tot_in_logm", "tot_in_logse", "tot_in_mean", "tot_in_lb", "tot_in_ub")
results_all <- data.frame(results_all)
# print out results for table 2
# indoor An Arabiensis
results_all[,c("ang_in_mean", "ang_in_lb", "ang_in_ub")]
# indoor An funestus
results_all[,c("anf_in_mean", "anf_in_lb", "anf_in_ub")]
# outdoor An arabiensis
results_all[,c("ang_out_mean", "ang_out_lb", "ang_out_ub")]
# outdoor An funestus
results_all[,c("anf_out_mean", "anf_out_lb", "anf_out_ub")]
write.csv(results_all, "1biting_estd_hrly_rates.csv")