-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocess.qmd
138 lines (111 loc) · 4.97 KB
/
preprocess.qmd
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
---
title: "Preprocessing"
description: "Load and format experimental data for analysis."
format:
html:
df-print: kable
code-fold: show
code-summary: "Hide code"
code-overflow: wrap
toc-title: Page Contents
toc: true
toc-depth: 2
toc-location: right
number-sections: false
html-math-method: katex
smooth-scroll: true
editor: source
editor_options:
chunk_output_type: console
---
```{=html}
<style type="text/css">
body, td {
font-size: 13pt;
}
code.r{
font-size: 9pt;
}
pre {
font-size: 11pt
}
</style>
```
## Libraries
```{r, warning=FALSE, message=FALSE}
library(tidyverse)
library(INLA)
library(here)
library(pals)
```
## Custom Functions
```{r}
source(here("R/utilities.R"))
source_dir(here("R"))
```
## Read Data
```{r warning=FALSE, message=FALSE}
antem_df <- read_csv(here("local/bov_antemortem_2024.csv"))
# minimum date
min_date <- min(antem_df$date)
min_date # date of donor inoculation
# add variables
antem_df <- antem_df %>%
mutate(hpdi = as.numeric(difftime(date, min_date, units = "hours")), # hours post donor inoculation
hpe = dpe*24, # convert dpe to hpe
exp_type = if_else(group == "donor", "inoc", "cont"), # exposed by inoculation or direct contact
fever = if_else(temp >= 104, "fever", "no_fever"), # temp >= 104 constitutes fever
censor_status = if_else(group == "Group 1" | animal == "BR23-24", 0, 1), # No obs symptoms (0) in these
)
dim(antem_df)
```
## Plots to Check Data
### Donors
```{r fig.width=8, fig.height=8, warning=FALSE, message=FALSE}
plot_donors(antem_df)
```
### Contact Groups
```{r fig.width=8, fig.height=8, warning=FALSE, message=FALSE}
plot_contact_groups(antem_df)
```
## ANOVA
To evaluate the differences in nasal, serum, and lesion score among groups and over time, repeated measures ANOVAs were applied using the *ezANOVA()* function from the **ez** R-package. The analyses included within-subjects (days post-exposure, dpe) and between-subjects (group) factors, with nasal, serum, and lesion scores as the dependent variables. Mauchly's test was conducted to test the assumption of sphericity. Where violations were found, Greenhouse-Geisser and Huynh-Feldt corrections were applied.
The repeated measures ANOVA results for nasal, serum, and lesion scores were significant. For nasal virus quantity, there were significant main effects of group (F(2, 9) = 9.22, p = 0.0066) and days post-exposure (dpe) (F(6, 54) = 33.99, p < 0.0001), as well as a significant interaction between group and dpe (F(12, 54) = 5.53, p < 0.0001), suggesting that nasal virus quantity varied significantly across groups and time, with different temporal patterns among groups. For serum virus quantity, no significant main effect of group was found (F(2, 9) = 2.79, p = 0.114), but there were significant effects of dpe (F(6, 54) = 25.18, p < 0.0001) and the group by dpe interaction (F(12, 54) = 7.95, p < 0.0001), indicating significant changes over time and different temporal patterns among groups. Lesion scores showed significant main effects of group (F(2, 9) = 5.86, p = 0.023) and dpe (F(6, 54) = 45.87, p < 0.0001), and a significant interaction between group and dpe (F(12, 54) = 3.04, p = 0.0025), indicating significant differences in lesion severity across groups and over time, with varying temporal patterns among the groups.
**Prepare Data**
```{r}
contact_groups <- antem_df %>%
filter(group %in% c("Group 2", "Group 3", "Group 4")) %>%
select(animal, group, nasal, serum, dpe, score) %>%
mutate(
score = replace_na(score, 0)) %>%
drop_na() %>%
mutate(
score = replace_na(score, 0),
nasal = replace(nasal, nasal == 45, 0),
serum = replace(serum, serum == 45, 0),
dpe = as.factor(dpe),
animal = as.factor(animal),
group = as.factor(group)
) %>%
as.data.frame()
```
::: panel-tabset
## Nasal
Results indicate that nasal virus quantity differed significantly between the groups and across the days post-exposure, with an interaction effect suggesting that the temporal pattern of virus quantity varied among the groups.
```{r}
nasal_anova <- ez::ezANOVA(data = contact_groups, dv = .(nasal), wid = .(animal), within = .(dpe), between = .(group))
nasal_anova
```
## Serum
Results suggest that while there were no significant differences between groups, there were significant changes over time, and the pattern of these changes differed significantly among the groups.
```{r}
serum_anova <- ez::ezANOVA(data = contact_groups, dv = .(serum), wid = .(animal), within = .(dpe), between = .(group))
serum_anova
```
## Score
Results indicate that lesion scores differed significantly between the groups and across the days post-exposure, with an interaction effect suggesting that the temporal pattern of lesion severity varied among the groups.
```{r}
score_anova <- ez::ezANOVA(data = contact_groups, dv = .(score), wid = .(animal), within = .(dpe), between = .(group))
score_anova
```
:::