-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
130 lines (95 loc) · 3.59 KB
/
README.Rmd
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
---
title: "I-priors and interactions"
output:
github_document:
# math_method: mathjax
html_preview: true
keep_html: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, #fig.height = 3.5, fig.width = 6,
fig.path = "figure/")
source("00-common.R")
knitr::read_chunk("01-cow.R")
knitr::read_chunk("02-sims.R")
knitr::read_chunk("03-sims_analysis.R")
```
This contains the R code for our paper.
> Wicher Bergsma, Haziq Jamil (2023). *Additive interaction modelling using I-priors*.
The key documents are as follows.
1. [`02-sims.R`](02-sims.R) and [`03-sims_analysis.R`](03-sims_analysis.R) contain the code for the simulations study detailed in Section 5 of the manuscript.
2. [`01-cow.R`](`01-cow.R`) contains the code for the functional response model in the application section (Section 6) of the manuscript.
In this README, the main summary of findings are presented.
Full details of the simulation results are found in the pdf files [`simres_corr.pdf`](`simres_corr.pdf`) and [`simres_uncorr.pdf`](`simres_uncorr.pdf`).
Please install the developmental version of the [`{iprior}`](https://github.com/haziqj/iprior) package.
## Simulation study
Data pairs $(y_i,x_i)$, where $x_i\in\mathbb R^3$ for $i=1,\dots,n$, were simulated according to the following model
$$
y_i = \beta_1 x_{i1} + \beta_2 x_{i2} + \beta_3 x_{i3} + \beta_4 x_{i1}x_{i2} + \beta_5 x_{i1}x_{i3} + \beta_6 x_{i2}x_{i3} + \beta_7 x_{i1}x_{i2}x_{i3} + \epsilon_i
$$
where $\epsilon_i\sim N(0,\sigma^2)$ such that $\text{Corr}(x_{ij},x_{ik})=\rho$, for $j\neq k$.
The simulation settings were $n=100$, $\sigma=3$, and $\rho\in\\{0,0.5\\}$.
The coefficients were varied according to the table below
```{r}
<<read_model_code>>
kbl(beta_vals, format = "pipe", row.names = TRUE)
```
For each set of true values of the coefficients, the four methods proposed the likeliest model to have generated the data set, from a search of hierarchically nested interaction models. This was replicated a total of $B=10,000$ times for each true value set.
The results below show proportion of times that each method selected the true model (higher is better).
The geometric mean was used as a summary measure of the simulation runs.
### Uncorrelated errors
```{r sims_uncorr, message = FALSE}
<<simres_fn>>
<<simres2>>
res_tab2 %>%
kbl(format = "pipe", row.names = TRUE, digits = 2)
```
<!-- The geometric mean -->
<!-- ```{r} -->
<!-- res_tab2[, -1] %>% -->
<!-- apply(., 2, function(x) exp(sum(log(x[x > 0])) / length(x))) %>% -->
<!-- round(3) -->
<!-- ``` -->
### Correlated errors
```{r sims_corr, message = FALSE}
<<simres1>>
res_tab1 %>%
kbl(format = "pipe", row.names = TRUE, digits = 2)
```
<!-- The geometric mean -->
<!-- ```{r} -->
<!-- res_tab1[, -1] %>% -->
<!-- apply(., 2, function(x) exp(sum(log(x[x > 0])) / length(x))) %>% -->
<!-- round(3) -->
<!-- ``` -->
### Summary of results
```{r overall_plot, fig.height = 4}
<<overall_plot>>
```
## Functional response model
```{r cow_plot, fig.height = 4}
<<load_cow_data>>
<<plot_cow_data>>
```
The model fitted was an I-prior model with ANOVA kernel (Pearson & fBm).
The results are tabulated below.
### Fixed hurst = 0.5
```{r}
load("cowres.RData")
mutate(res1, formula = paste0("`", formula, "`")) %>%
kbl(., format = "pipe", digits = 2)
```
### Fixed hurst = 0.3
```{r}
mutate(res2, formula = paste0("`", formula, "`")) %>%
kbl(., format = "pipe", digits = 2)
```
### Estimated hurst value
```{r}
mutate(res3, formula = paste0("`", formula, "`")) %>%
kbl(., format = "pipe", digits = 2)
```
## Outro
```{r}
sessioninfo::session_info()
```